@@ -665,6 +665,15 @@ macro_rules! invoice_request_accessors { ($self: ident, $contents: expr) => {
665665 $contents. amount_msats( )
666666 }
667667
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+
668677 /// Features pertaining to requesting an invoice.
669678 pub fn invoice_request_features( & $self) -> & InvoiceRequestFeatures {
670679 & $contents. features( )
@@ -985,6 +994,10 @@ impl InvoiceRequestContents {
985994 } )
986995 }
987996
997+ pub ( super ) fn has_amount_msats ( & self ) -> bool {
998+ self . inner . amount_msats ( ) . is_some ( )
999+ }
1000+
9881001 pub ( super ) fn features ( & self ) -> & InvoiceRequestFeatures {
9891002 & self . inner . features
9901003 }
@@ -1669,6 +1682,7 @@ mod tests {
16691682 . amount_msats ( 1000 ) . unwrap ( )
16701683 . build_and_sign ( ) . unwrap ( ) ;
16711684 let ( _, _, tlv_stream, _, _, _) = invoice_request. as_tlv_stream ( ) ;
1685+ assert ! ( invoice_request. has_amount_msats( ) ) ;
16721686 assert_eq ! ( invoice_request. amount_msats( ) , Some ( 1000 ) ) ;
16731687 assert_eq ! ( tlv_stream. amount, Some ( 1000 ) ) ;
16741688
@@ -1680,6 +1694,7 @@ mod tests {
16801694 . amount_msats ( 1000 ) . unwrap ( )
16811695 . build_and_sign ( ) . unwrap ( ) ;
16821696 let ( _, _, tlv_stream, _, _, _) = invoice_request. as_tlv_stream ( ) ;
1697+ assert ! ( invoice_request. has_amount_msats( ) ) ;
16831698 assert_eq ! ( invoice_request. amount_msats( ) , Some ( 1000 ) ) ;
16841699 assert_eq ! ( tlv_stream. amount, Some ( 1000 ) ) ;
16851700
@@ -1690,6 +1705,7 @@ mod tests {
16901705 . amount_msats ( 1001 ) . unwrap ( )
16911706 . build_and_sign ( ) . unwrap ( ) ;
16921707 let ( _, _, tlv_stream, _, _, _) = invoice_request. as_tlv_stream ( ) ;
1708+ assert ! ( invoice_request. has_amount_msats( ) ) ;
16931709 assert_eq ! ( invoice_request. amount_msats( ) , Some ( 1001 ) ) ;
16941710 assert_eq ! ( tlv_stream. amount, Some ( 1001 ) ) ;
16951711
@@ -1774,6 +1790,7 @@ mod tests {
17741790 . request_invoice ( & expanded_key, nonce, & secp_ctx, payment_id) . unwrap ( )
17751791 . build_and_sign ( ) . unwrap ( ) ;
17761792 let ( _, _, tlv_stream, _, _, _) = invoice_request. as_tlv_stream ( ) ;
1793+ assert ! ( !invoice_request. has_amount_msats( ) ) ;
17771794 assert_eq ! ( invoice_request. amount_msats( ) , Some ( 1000 ) ) ;
17781795 assert_eq ! ( tlv_stream. amount, None ) ;
17791796
@@ -1785,6 +1802,7 @@ mod tests {
17851802 . quantity ( 2 ) . unwrap ( )
17861803 . build_and_sign ( ) . unwrap ( ) ;
17871804 let ( _, _, tlv_stream, _, _, _) = invoice_request. as_tlv_stream ( ) ;
1805+ assert ! ( !invoice_request. has_amount_msats( ) ) ;
17881806 assert_eq ! ( invoice_request. amount_msats( ) , Some ( 2000 ) ) ;
17891807 assert_eq ! ( tlv_stream. amount, None ) ;
17901808
@@ -1794,6 +1812,7 @@ mod tests {
17941812 . request_invoice ( & expanded_key, nonce, & secp_ctx, payment_id) . unwrap ( )
17951813 . build_unchecked_and_sign ( ) ;
17961814 let ( _, _, tlv_stream, _, _, _) = invoice_request. as_tlv_stream ( ) ;
1815+ assert ! ( !invoice_request. has_amount_msats( ) ) ;
17971816 assert_eq ! ( invoice_request. amount_msats( ) , None ) ;
17981817 assert_eq ! ( tlv_stream. amount, None ) ;
17991818 }
0 commit comments