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