@@ -320,7 +320,8 @@ impl<'a, S: SigningPubkeyStrategy> InvoiceBuilder<'a, S> {
320
320
self
321
321
}
322
322
323
- /// Sets [`Bolt12Invoice::features`] to indicate MPP may be used. Otherwise, MPP is disallowed.
323
+ /// Sets [`Bolt12Invoice::invoice_features`] to indicate MPP may be used. Otherwise, MPP is
324
+ /// disallowed.
324
325
pub fn allow_mpp ( mut self ) -> Self {
325
326
self . invoice . fields_mut ( ) . features . set_basic_mpp_optional ( ) ;
326
327
self
@@ -396,11 +397,6 @@ impl UnsignedBolt12Invoice {
396
397
Self { bytes, contents, tagged_hash }
397
398
}
398
399
399
- /// The public key corresponding to the key needed to sign the invoice.
400
- pub fn signing_pubkey ( & self ) -> PublicKey {
401
- self . contents . fields ( ) . signing_pubkey
402
- }
403
-
404
400
/// Signs the [`TaggedHash`] of the invoice using the given function.
405
401
///
406
402
/// Note: The hash computation may have included unknown, odd TLV records.
@@ -485,11 +481,11 @@ struct InvoiceFields {
485
481
signing_pubkey : PublicKey ,
486
482
}
487
483
488
- impl Bolt12Invoice {
484
+ macro_rules! invoice_accessors { ( $self : ident , $contents : expr ) => {
489
485
/// A complete description of the purpose of the originating offer or refund. Intended to be
490
486
/// displayed to the user but with the caveat that it has not been verified in any way.
491
- pub fn description ( & self ) -> PrintableString {
492
- self . contents . description ( )
487
+ pub fn description( & $ self) -> PrintableString {
488
+ $ contents. description( )
493
489
}
494
490
495
491
/// Paths to the recipient originating from publicly reachable nodes, including information
@@ -500,52 +496,60 @@ impl Bolt12Invoice {
500
496
///
501
497
/// This is not exported to bindings users as slices with non-reference types cannot be ABI
502
498
/// matched in another language.
503
- pub fn payment_paths ( & self ) -> & [ ( BlindedPayInfo , BlindedPath ) ] {
504
- self . contents . payment_paths ( )
499
+ pub fn payment_paths( & $ self) -> & [ ( BlindedPayInfo , BlindedPath ) ] {
500
+ $ contents. payment_paths( )
505
501
}
506
502
507
503
/// Duration since the Unix epoch when the invoice was created.
508
- pub fn created_at ( & self ) -> Duration {
509
- self . contents . created_at ( )
504
+ pub fn created_at( & $ self) -> Duration {
505
+ $ contents. created_at( )
510
506
}
511
507
512
508
/// Duration since [`Bolt12Invoice::created_at`] when the invoice has expired and therefore
513
509
/// should no longer be paid.
514
- pub fn relative_expiry ( & self ) -> Duration {
515
- self . contents . relative_expiry ( )
510
+ pub fn relative_expiry( & $ self) -> Duration {
511
+ $ contents. relative_expiry( )
516
512
}
517
513
518
514
/// Whether the invoice has expired.
519
515
#[ cfg( feature = "std" ) ]
520
- pub fn is_expired ( & self ) -> bool {
521
- self . contents . is_expired ( )
516
+ pub fn is_expired( & $ self) -> bool {
517
+ $ contents. is_expired( )
522
518
}
523
519
524
520
/// SHA256 hash of the payment preimage that will be given in return for paying the invoice.
525
- pub fn payment_hash ( & self ) -> PaymentHash {
526
- self . contents . payment_hash ( )
521
+ pub fn payment_hash( & $ self) -> PaymentHash {
522
+ $ contents. payment_hash( )
527
523
}
528
524
529
525
/// The minimum amount required for a successful payment of the invoice.
530
- pub fn amount_msats ( & self ) -> u64 {
531
- self . contents . amount_msats ( )
526
+ pub fn amount_msats( & $ self) -> u64 {
527
+ $ contents. amount_msats( )
532
528
}
533
529
534
530
/// Fallback addresses for paying the invoice on-chain, in order of most-preferred to
535
531
/// least-preferred.
536
- pub fn fallbacks ( & self ) -> Vec < Address > {
537
- self . contents . fallbacks ( )
532
+ pub fn fallbacks( & $ self) -> Vec <Address > {
533
+ $ contents. fallbacks( )
538
534
}
539
535
540
536
/// Features pertaining to paying an invoice.
541
- pub fn features ( & self ) -> & Bolt12InvoiceFeatures {
542
- self . contents . features ( )
537
+ pub fn invoice_features ( & $ self) -> & Bolt12InvoiceFeatures {
538
+ $ contents. features( )
543
539
}
544
540
545
541
/// The public key corresponding to the key used to sign the invoice.
546
- pub fn signing_pubkey ( & self ) -> PublicKey {
547
- self . contents . signing_pubkey ( )
542
+ pub fn signing_pubkey( & $ self) -> PublicKey {
543
+ $ contents. signing_pubkey( )
548
544
}
545
+ } }
546
+
547
+ impl UnsignedBolt12Invoice {
548
+ invoice_accessors ! ( self , self . contents) ;
549
+ }
550
+
551
+ impl Bolt12Invoice {
552
+ invoice_accessors ! ( self , self . contents) ;
549
553
550
554
/// Signature of the invoice verified using [`Bolt12Invoice::signing_pubkey`].
551
555
pub fn signature ( & self ) -> Signature {
@@ -1092,6 +1096,19 @@ mod tests {
1092
1096
let mut buffer = Vec :: new ( ) ;
1093
1097
unsigned_invoice. write ( & mut buffer) . unwrap ( ) ;
1094
1098
1099
+ assert_eq ! ( unsigned_invoice. bytes, buffer. as_slice( ) ) ;
1100
+ assert_eq ! ( unsigned_invoice. description( ) , PrintableString ( "foo" ) ) ;
1101
+ assert_eq ! ( unsigned_invoice. payment_paths( ) , payment_paths. as_slice( ) ) ;
1102
+ assert_eq ! ( unsigned_invoice. created_at( ) , now) ;
1103
+ assert_eq ! ( unsigned_invoice. relative_expiry( ) , DEFAULT_RELATIVE_EXPIRY ) ;
1104
+ #[ cfg( feature = "std" ) ]
1105
+ assert ! ( !unsigned_invoice. is_expired( ) ) ;
1106
+ assert_eq ! ( unsigned_invoice. payment_hash( ) , payment_hash) ;
1107
+ assert_eq ! ( unsigned_invoice. amount_msats( ) , 1000 ) ;
1108
+ assert_eq ! ( unsigned_invoice. fallbacks( ) , vec![ ] ) ;
1109
+ assert_eq ! ( unsigned_invoice. invoice_features( ) , & Bolt12InvoiceFeatures :: empty( ) ) ;
1110
+ assert_eq ! ( unsigned_invoice. signing_pubkey( ) , recipient_pubkey( ) ) ;
1111
+
1095
1112
match UnsignedBolt12Invoice :: try_from ( buffer) {
1096
1113
Err ( e) => panic ! ( "error parsing unsigned invoice: {:?}" , e) ,
1097
1114
Ok ( parsed) => {
@@ -1115,7 +1132,7 @@ mod tests {
1115
1132
assert_eq ! ( invoice. payment_hash( ) , payment_hash) ;
1116
1133
assert_eq ! ( invoice. amount_msats( ) , 1000 ) ;
1117
1134
assert_eq ! ( invoice. fallbacks( ) , vec![ ] ) ;
1118
- assert_eq ! ( invoice. features ( ) , & Bolt12InvoiceFeatures :: empty( ) ) ;
1135
+ assert_eq ! ( invoice. invoice_features ( ) , & Bolt12InvoiceFeatures :: empty( ) ) ;
1119
1136
assert_eq ! ( invoice. signing_pubkey( ) , recipient_pubkey( ) ) ;
1120
1137
assert ! (
1121
1138
merkle:: verify_signature(
@@ -1198,7 +1215,7 @@ mod tests {
1198
1215
assert_eq ! ( invoice. payment_hash( ) , payment_hash) ;
1199
1216
assert_eq ! ( invoice. amount_msats( ) , 1000 ) ;
1200
1217
assert_eq ! ( invoice. fallbacks( ) , vec![ ] ) ;
1201
- assert_eq ! ( invoice. features ( ) , & Bolt12InvoiceFeatures :: empty( ) ) ;
1218
+ assert_eq ! ( invoice. invoice_features ( ) , & Bolt12InvoiceFeatures :: empty( ) ) ;
1202
1219
assert_eq ! ( invoice. signing_pubkey( ) , recipient_pubkey( ) ) ;
1203
1220
assert ! (
1204
1221
merkle:: verify_signature(
@@ -1546,7 +1563,7 @@ mod tests {
1546
1563
. build ( ) . unwrap ( )
1547
1564
. sign ( recipient_sign) . unwrap ( ) ;
1548
1565
let ( _, _, _, tlv_stream, _) = invoice. as_tlv_stream ( ) ;
1549
- assert_eq ! ( invoice. features ( ) , & features) ;
1566
+ assert_eq ! ( invoice. invoice_features ( ) , & features) ;
1550
1567
assert_eq ! ( tlv_stream. features, Some ( & features) ) ;
1551
1568
}
1552
1569
@@ -1766,7 +1783,7 @@ mod tests {
1766
1783
Ok ( invoice) => {
1767
1784
let mut features = Bolt12InvoiceFeatures :: empty ( ) ;
1768
1785
features. set_basic_mpp_optional ( ) ;
1769
- assert_eq ! ( invoice. features ( ) , & features) ;
1786
+ assert_eq ! ( invoice. invoice_features ( ) , & features) ;
1770
1787
} ,
1771
1788
Err ( e) => panic ! ( "error parsing invoice: {:?}" , e) ,
1772
1789
}
0 commit comments