@@ -665,6 +665,15 @@ macro_rules! invoice_request_accessors { ($self: ident, $contents: expr) => {
665
665
$contents. amount_msats( )
666
666
}
667
667
668
+ /// Returns whether an amount was set in the request; otherwise, if [`amount_msats`] is `Some`
669
+ /// then it was inferred from the [`Offer::amount`] and [`quantity`].
670
+ ///
671
+ /// [`amount_msats`]: Self::amount_msats
672
+ /// [`quantity`]: Self::quantity
673
+ pub fn has_amount_msats( & $self) -> bool {
674
+ $contents. has_amount_msats( )
675
+ }
676
+
668
677
/// Features pertaining to requesting an invoice.
669
678
pub fn invoice_request_features( & $self) -> & InvoiceRequestFeatures {
670
679
& $contents. features( )
@@ -985,6 +994,10 @@ impl InvoiceRequestContents {
985
994
} )
986
995
}
987
996
997
+ pub ( super ) fn has_amount_msats ( & self ) -> bool {
998
+ self . inner . amount_msats ( ) . is_some ( )
999
+ }
1000
+
988
1001
pub ( super ) fn features ( & self ) -> & InvoiceRequestFeatures {
989
1002
& self . inner . features
990
1003
}
@@ -1669,6 +1682,7 @@ mod tests {
1669
1682
. amount_msats ( 1000 ) . unwrap ( )
1670
1683
. build_and_sign ( ) . unwrap ( ) ;
1671
1684
let ( _, _, tlv_stream, _, _, _) = invoice_request. as_tlv_stream ( ) ;
1685
+ assert ! ( invoice_request. has_amount_msats( ) ) ;
1672
1686
assert_eq ! ( invoice_request. amount_msats( ) , Some ( 1000 ) ) ;
1673
1687
assert_eq ! ( tlv_stream. amount, Some ( 1000 ) ) ;
1674
1688
@@ -1680,6 +1694,7 @@ mod tests {
1680
1694
. amount_msats ( 1000 ) . unwrap ( )
1681
1695
. build_and_sign ( ) . unwrap ( ) ;
1682
1696
let ( _, _, tlv_stream, _, _, _) = invoice_request. as_tlv_stream ( ) ;
1697
+ assert ! ( invoice_request. has_amount_msats( ) ) ;
1683
1698
assert_eq ! ( invoice_request. amount_msats( ) , Some ( 1000 ) ) ;
1684
1699
assert_eq ! ( tlv_stream. amount, Some ( 1000 ) ) ;
1685
1700
@@ -1690,6 +1705,7 @@ mod tests {
1690
1705
. amount_msats ( 1001 ) . unwrap ( )
1691
1706
. build_and_sign ( ) . unwrap ( ) ;
1692
1707
let ( _, _, tlv_stream, _, _, _) = invoice_request. as_tlv_stream ( ) ;
1708
+ assert ! ( invoice_request. has_amount_msats( ) ) ;
1693
1709
assert_eq ! ( invoice_request. amount_msats( ) , Some ( 1001 ) ) ;
1694
1710
assert_eq ! ( tlv_stream. amount, Some ( 1001 ) ) ;
1695
1711
@@ -1774,6 +1790,7 @@ mod tests {
1774
1790
. request_invoice ( & expanded_key, nonce, & secp_ctx, payment_id) . unwrap ( )
1775
1791
. build_and_sign ( ) . unwrap ( ) ;
1776
1792
let ( _, _, tlv_stream, _, _, _) = invoice_request. as_tlv_stream ( ) ;
1793
+ assert ! ( !invoice_request. has_amount_msats( ) ) ;
1777
1794
assert_eq ! ( invoice_request. amount_msats( ) , Some ( 1000 ) ) ;
1778
1795
assert_eq ! ( tlv_stream. amount, None ) ;
1779
1796
@@ -1785,6 +1802,7 @@ mod tests {
1785
1802
. quantity ( 2 ) . unwrap ( )
1786
1803
. build_and_sign ( ) . unwrap ( ) ;
1787
1804
let ( _, _, tlv_stream, _, _, _) = invoice_request. as_tlv_stream ( ) ;
1805
+ assert ! ( !invoice_request. has_amount_msats( ) ) ;
1788
1806
assert_eq ! ( invoice_request. amount_msats( ) , Some ( 2000 ) ) ;
1789
1807
assert_eq ! ( tlv_stream. amount, None ) ;
1790
1808
@@ -1794,6 +1812,7 @@ mod tests {
1794
1812
. request_invoice ( & expanded_key, nonce, & secp_ctx, payment_id) . unwrap ( )
1795
1813
. build_unchecked_and_sign ( ) ;
1796
1814
let ( _, _, tlv_stream, _, _, _) = invoice_request. as_tlv_stream ( ) ;
1815
+ assert ! ( !invoice_request. has_amount_msats( ) ) ;
1797
1816
assert_eq ! ( invoice_request. amount_msats( ) , None ) ;
1798
1817
assert_eq ! ( tlv_stream. amount, None ) ;
1799
1818
}
0 commit comments