@@ -441,48 +441,52 @@ pub(super) struct InvoiceRequestContentsWithoutPayerId {
441
441
payer_note : Option < String > ,
442
442
}
443
443
444
- impl InvoiceRequest {
444
+ macro_rules! invoice_request_accessors { ( $self : ident , $contents : expr ) => {
445
445
/// An unpredictable series of bytes, typically containing information about the derivation of
446
446
/// [`payer_id`].
447
447
///
448
448
/// [`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( )
451
451
}
452
452
453
453
/// 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( )
456
456
}
457
457
458
458
/// The amount to pay in msats (i.e., the minimum lightning-payable unit for [`chain`]), which
459
459
/// must be greater than or equal to [`Offer::amount`], converted if necessary.
460
460
///
461
461
/// [`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( )
464
464
}
465
465
466
466
/// 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( )
469
469
}
470
470
471
471
/// 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( )
474
474
}
475
475
476
476
/// 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( )
479
479
}
480
480
481
481
/// A payer-provided note which will be seen by the recipient and reflected back in the invoice
482
482
/// 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( )
485
485
}
486
+ } }
487
+
488
+ impl InvoiceRequest {
489
+ invoice_request_accessors ! ( self , self . contents) ;
486
490
487
491
/// Signature of the invoice request using [`payer_id`].
488
492
///
@@ -534,7 +538,7 @@ impl InvoiceRequest {
534
538
& self , payment_paths : Vec < ( BlindedPayInfo , BlindedPath ) > , payment_hash : PaymentHash ,
535
539
created_at : core:: time:: Duration
536
540
) -> Result < InvoiceBuilder < ExplicitSigningPubkey > , Bolt12SemanticError > {
537
- if self . features ( ) . requires_unknown_bits ( ) {
541
+ if self . invoice_request_features ( ) . requires_unknown_bits ( ) {
538
542
return Err ( Bolt12SemanticError :: UnknownRequiredFeatures ) ;
539
543
}
540
544
@@ -577,7 +581,7 @@ impl InvoiceRequest {
577
581
& self , payment_paths : Vec < ( BlindedPayInfo , BlindedPath ) > , payment_hash : PaymentHash ,
578
582
created_at : core:: time:: Duration , expanded_key : & ExpandedKey , secp_ctx : & Secp256k1 < T >
579
583
) -> Result < InvoiceBuilder < DerivedSigningPubkey > , Bolt12SemanticError > {
580
- if self . features ( ) . requires_unknown_bits ( ) {
584
+ if self . invoice_request_features ( ) . requires_unknown_bits ( ) {
581
585
return Err ( Bolt12SemanticError :: UnknownRequiredFeatures ) ;
582
586
}
583
587
@@ -887,10 +891,10 @@ mod tests {
887
891
invoice_request. write ( & mut buffer) . unwrap ( ) ;
888
892
889
893
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 ] ) ;
891
895
assert_eq ! ( invoice_request. chain( ) , ChainHash :: using_genesis_block( Network :: Bitcoin ) ) ;
892
896
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( ) ) ;
894
898
assert_eq ! ( invoice_request. quantity( ) , None ) ;
895
899
assert_eq ! ( invoice_request. payer_id( ) , payer_pubkey( ) ) ;
896
900
assert_eq ! ( invoice_request. payer_note( ) , None ) ;
@@ -1291,7 +1295,7 @@ mod tests {
1291
1295
. build ( ) . unwrap ( )
1292
1296
. sign ( payer_sign) . unwrap ( ) ;
1293
1297
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( ) ) ;
1295
1299
assert_eq ! ( tlv_stream. features, Some ( & InvoiceRequestFeatures :: unknown( ) ) ) ;
1296
1300
1297
1301
let invoice_request = OfferBuilder :: new ( "foo" . into ( ) , recipient_pubkey ( ) )
@@ -1303,7 +1307,7 @@ mod tests {
1303
1307
. build ( ) . unwrap ( )
1304
1308
. sign ( payer_sign) . unwrap ( ) ;
1305
1309
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( ) ) ;
1307
1311
assert_eq ! ( tlv_stream. features, None ) ;
1308
1312
}
1309
1313
0 commit comments