@@ -666,6 +666,15 @@ macro_rules! invoice_request_accessors { ($self: ident, $contents: expr) => {
666666 $contents. amount_msats( )
667667 }
668668
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+
669678 /// Features pertaining to requesting an invoice.
670679 pub fn invoice_request_features( & $self) -> & InvoiceRequestFeatures {
671680 & $contents. features( )
@@ -986,6 +995,10 @@ impl InvoiceRequestContents {
986995 } )
987996 }
988997
998+ pub ( super ) fn has_amount_msats ( & self ) -> bool {
999+ self . inner . amount_msats ( ) . is_some ( )
1000+ }
1001+
9891002 pub ( super ) fn features ( & self ) -> & InvoiceRequestFeatures {
9901003 & self . inner . features
9911004 }
@@ -1671,6 +1684,7 @@ mod tests {
16711684 . amount_msats ( 1000 ) . unwrap ( )
16721685 . build_and_sign ( ) . unwrap ( ) ;
16731686 let ( _, _, tlv_stream, _, _, _) = invoice_request. as_tlv_stream ( ) ;
1687+ assert ! ( invoice_request. has_amount_msats( ) ) ;
16741688 assert_eq ! ( invoice_request. amount_msats( ) , Some ( 1000 ) ) ;
16751689 assert_eq ! ( tlv_stream. amount, Some ( 1000 ) ) ;
16761690
@@ -1682,6 +1696,7 @@ mod tests {
16821696 . amount_msats ( 1000 ) . unwrap ( )
16831697 . build_and_sign ( ) . unwrap ( ) ;
16841698 let ( _, _, tlv_stream, _, _, _) = invoice_request. as_tlv_stream ( ) ;
1699+ assert ! ( invoice_request. has_amount_msats( ) ) ;
16851700 assert_eq ! ( invoice_request. amount_msats( ) , Some ( 1000 ) ) ;
16861701 assert_eq ! ( tlv_stream. amount, Some ( 1000 ) ) ;
16871702
@@ -1692,6 +1707,7 @@ mod tests {
16921707 . amount_msats ( 1001 ) . unwrap ( )
16931708 . build_and_sign ( ) . unwrap ( ) ;
16941709 let ( _, _, tlv_stream, _, _, _) = invoice_request. as_tlv_stream ( ) ;
1710+ assert ! ( invoice_request. has_amount_msats( ) ) ;
16951711 assert_eq ! ( invoice_request. amount_msats( ) , Some ( 1001 ) ) ;
16961712 assert_eq ! ( tlv_stream. amount, Some ( 1001 ) ) ;
16971713
@@ -1776,6 +1792,7 @@ mod tests {
17761792 . request_invoice ( & expanded_key, nonce, & secp_ctx, payment_id) . unwrap ( )
17771793 . build_and_sign ( ) . unwrap ( ) ;
17781794 let ( _, _, tlv_stream, _, _, _) = invoice_request. as_tlv_stream ( ) ;
1795+ assert ! ( !invoice_request. has_amount_msats( ) ) ;
17791796 assert_eq ! ( invoice_request. amount_msats( ) , Some ( 1000 ) ) ;
17801797 assert_eq ! ( tlv_stream. amount, None ) ;
17811798
@@ -1787,6 +1804,7 @@ mod tests {
17871804 . quantity ( 2 ) . unwrap ( )
17881805 . build_and_sign ( ) . unwrap ( ) ;
17891806 let ( _, _, tlv_stream, _, _, _) = invoice_request. as_tlv_stream ( ) ;
1807+ assert ! ( !invoice_request. has_amount_msats( ) ) ;
17901808 assert_eq ! ( invoice_request. amount_msats( ) , Some ( 2000 ) ) ;
17911809 assert_eq ! ( tlv_stream. amount, None ) ;
17921810
@@ -1796,6 +1814,7 @@ mod tests {
17961814 . request_invoice ( & expanded_key, nonce, & secp_ctx, payment_id) . unwrap ( )
17971815 . build_unchecked_and_sign ( ) ;
17981816 let ( _, _, tlv_stream, _, _, _) = invoice_request. as_tlv_stream ( ) ;
1817+ assert ! ( !invoice_request. has_amount_msats( ) ) ;
17991818 assert_eq ! ( invoice_request. amount_msats( ) , None ) ;
18001819 assert_eq ! ( tlv_stream. amount, None ) ;
18011820 }
0 commit comments