@@ -441,48 +441,52 @@ pub(super) struct InvoiceRequestContentsWithoutPayerId {
441441 payer_note : Option < String > ,
442442}
443443
444- impl InvoiceRequest {
444+ macro_rules! invoice_request_accessors { ( $self : ident , $contents : expr ) => {
445445 /// An unpredictable series of bytes, typically containing information about the derivation of
446446 /// [`payer_id`].
447447 ///
448448 /// [`payer_id`]: Self::payer_id
449- pub fn metadata ( & self ) -> & [ u8 ] {
450- self . contents . metadata ( )
449+ pub fn payer_metadata ( & $ self) -> & [ u8 ] {
450+ $ contents. metadata( )
451451 }
452452
453453 /// A chain from [`Offer::chains`] that the offer is valid for.
454- pub fn chain ( & self ) -> ChainHash {
455- self . contents . chain ( )
454+ pub fn chain( & $ self) -> ChainHash {
455+ $ contents. chain( )
456456 }
457457
458458 /// The amount to pay in msats (i.e., the minimum lightning-payable unit for [`chain`]), which
459459 /// must be greater than or equal to [`Offer::amount`], converted if necessary.
460460 ///
461461 /// [`chain`]: Self::chain
462- pub fn amount_msats ( & self ) -> Option < u64 > {
463- self . contents . amount_msats ( )
462+ pub fn amount_msats( & $ self) -> Option <u64 > {
463+ $ contents. amount_msats( )
464464 }
465465
466466 /// Features pertaining to requesting an invoice.
467- pub fn features ( & self ) -> & InvoiceRequestFeatures {
468- & self . contents . features ( )
467+ pub fn invoice_request_features ( & $ self) -> & InvoiceRequestFeatures {
468+ & $ contents. features( )
469469 }
470470
471471 /// The quantity of the offer's item conforming to [`Offer::is_valid_quantity`].
472- pub fn quantity ( & self ) -> Option < u64 > {
473- self . contents . quantity ( )
472+ pub fn quantity( & $ self) -> Option <u64 > {
473+ $ contents. quantity( )
474474 }
475475
476476 /// A possibly transient pubkey used to sign the invoice request.
477- pub fn payer_id ( & self ) -> PublicKey {
478- self . contents . payer_id ( )
477+ pub fn payer_id( & $ self) -> PublicKey {
478+ $ contents. payer_id( )
479479 }
480480
481481 /// A payer-provided note which will be seen by the recipient and reflected back in the invoice
482482 /// response.
483- pub fn payer_note ( & self ) -> Option < PrintableString > {
484- self . contents . payer_note ( )
483+ pub fn payer_note( & $ self) -> Option <PrintableString > {
484+ $ contents. payer_note( )
485485 }
486+ } }
487+
488+ impl InvoiceRequest {
489+ invoice_request_accessors ! ( self , self . contents) ;
486490
487491 /// Signature of the invoice request using [`payer_id`].
488492 ///
@@ -534,7 +538,7 @@ impl InvoiceRequest {
534538 & self , payment_paths : Vec < ( BlindedPayInfo , BlindedPath ) > , payment_hash : PaymentHash ,
535539 created_at : core:: time:: Duration
536540 ) -> Result < InvoiceBuilder < ExplicitSigningPubkey > , Bolt12SemanticError > {
537- if self . features ( ) . requires_unknown_bits ( ) {
541+ if self . invoice_request_features ( ) . requires_unknown_bits ( ) {
538542 return Err ( Bolt12SemanticError :: UnknownRequiredFeatures ) ;
539543 }
540544
@@ -577,7 +581,7 @@ impl InvoiceRequest {
577581 & self , payment_paths : Vec < ( BlindedPayInfo , BlindedPath ) > , payment_hash : PaymentHash ,
578582 created_at : core:: time:: Duration , expanded_key : & ExpandedKey , secp_ctx : & Secp256k1 < T >
579583 ) -> Result < InvoiceBuilder < DerivedSigningPubkey > , Bolt12SemanticError > {
580- if self . features ( ) . requires_unknown_bits ( ) {
584+ if self . invoice_request_features ( ) . requires_unknown_bits ( ) {
581585 return Err ( Bolt12SemanticError :: UnknownRequiredFeatures ) ;
582586 }
583587
@@ -887,10 +891,10 @@ mod tests {
887891 invoice_request. write ( & mut buffer) . unwrap ( ) ;
888892
889893 assert_eq ! ( invoice_request. bytes, buffer. as_slice( ) ) ;
890- assert_eq ! ( invoice_request. metadata ( ) , & [ 1 ; 32 ] ) ;
894+ assert_eq ! ( invoice_request. payer_metadata ( ) , & [ 1 ; 32 ] ) ;
891895 assert_eq ! ( invoice_request. chain( ) , ChainHash :: using_genesis_block( Network :: Bitcoin ) ) ;
892896 assert_eq ! ( invoice_request. amount_msats( ) , None ) ;
893- assert_eq ! ( invoice_request. features ( ) , & InvoiceRequestFeatures :: empty( ) ) ;
897+ assert_eq ! ( invoice_request. invoice_request_features ( ) , & InvoiceRequestFeatures :: empty( ) ) ;
894898 assert_eq ! ( invoice_request. quantity( ) , None ) ;
895899 assert_eq ! ( invoice_request. payer_id( ) , payer_pubkey( ) ) ;
896900 assert_eq ! ( invoice_request. payer_note( ) , None ) ;
@@ -1291,7 +1295,7 @@ mod tests {
12911295 . build ( ) . unwrap ( )
12921296 . sign ( payer_sign) . unwrap ( ) ;
12931297 let ( _, _, tlv_stream, _) = invoice_request. as_tlv_stream ( ) ;
1294- assert_eq ! ( invoice_request. features ( ) , & InvoiceRequestFeatures :: unknown( ) ) ;
1298+ assert_eq ! ( invoice_request. invoice_request_features ( ) , & InvoiceRequestFeatures :: unknown( ) ) ;
12951299 assert_eq ! ( tlv_stream. features, Some ( & InvoiceRequestFeatures :: unknown( ) ) ) ;
12961300
12971301 let invoice_request = OfferBuilder :: new ( "foo" . into ( ) , recipient_pubkey ( ) )
@@ -1303,7 +1307,7 @@ mod tests {
13031307 . build ( ) . unwrap ( )
13041308 . sign ( payer_sign) . unwrap ( ) ;
13051309 let ( _, _, tlv_stream, _) = invoice_request. as_tlv_stream ( ) ;
1306- assert_eq ! ( invoice_request. features ( ) , & InvoiceRequestFeatures :: empty( ) ) ;
1310+ assert_eq ! ( invoice_request. invoice_request_features ( ) , & InvoiceRequestFeatures :: empty( ) ) ;
13071311 assert_eq ! ( tlv_stream. features, None ) ;
13081312 }
13091313
0 commit comments