@@ -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
@@ -391,11 +392,6 @@ impl UnsignedBolt12Invoice {
391
392
Self { bytes, contents, tagged_hash }
392
393
}
393
394
394
- /// The public key corresponding to the key needed to sign the invoice.
395
- pub fn signing_pubkey ( & self ) -> PublicKey {
396
- self . contents . fields ( ) . signing_pubkey
397
- }
398
-
399
395
/// Signs the invoice using the given function.
400
396
///
401
397
/// This is not exported to bindings users as functions aren't currently mapped.
@@ -479,11 +475,11 @@ struct InvoiceFields {
479
475
signing_pubkey : PublicKey ,
480
476
}
481
477
482
- impl Bolt12Invoice {
478
+ macro_rules! invoice_accessors { ( $self : ident , $contents : expr ) => {
483
479
/// A complete description of the purpose of the originating offer or refund. Intended to be
484
480
/// displayed to the user but with the caveat that it has not been verified in any way.
485
- pub fn description ( & self ) -> PrintableString {
486
- self . contents . description ( )
481
+ pub fn description( & $ self) -> PrintableString {
482
+ $ contents. description( )
487
483
}
488
484
489
485
/// Paths to the recipient originating from publicly reachable nodes, including information
@@ -494,52 +490,60 @@ impl Bolt12Invoice {
494
490
///
495
491
/// This is not exported to bindings users as slices with non-reference types cannot be ABI
496
492
/// matched in another language.
497
- pub fn payment_paths ( & self ) -> & [ ( BlindedPayInfo , BlindedPath ) ] {
498
- self . contents . payment_paths ( )
493
+ pub fn payment_paths( & $ self) -> & [ ( BlindedPayInfo , BlindedPath ) ] {
494
+ $ contents. payment_paths( )
499
495
}
500
496
501
497
/// Duration since the Unix epoch when the invoice was created.
502
- pub fn created_at ( & self ) -> Duration {
503
- self . contents . created_at ( )
498
+ pub fn created_at( & $ self) -> Duration {
499
+ $ contents. created_at( )
504
500
}
505
501
506
502
/// Duration since [`Bolt12Invoice::created_at`] when the invoice has expired and therefore
507
503
/// should no longer be paid.
508
- pub fn relative_expiry ( & self ) -> Duration {
509
- self . contents . relative_expiry ( )
504
+ pub fn relative_expiry( & $ self) -> Duration {
505
+ $ contents. relative_expiry( )
510
506
}
511
507
512
508
/// Whether the invoice has expired.
513
509
#[ cfg( feature = "std" ) ]
514
- pub fn is_expired ( & self ) -> bool {
515
- self . contents . is_expired ( )
510
+ pub fn is_expired( & $ self) -> bool {
511
+ $ contents. is_expired( )
516
512
}
517
513
518
514
/// SHA256 hash of the payment preimage that will be given in return for paying the invoice.
519
- pub fn payment_hash ( & self ) -> PaymentHash {
520
- self . contents . payment_hash ( )
515
+ pub fn payment_hash( & $ self) -> PaymentHash {
516
+ $ contents. payment_hash( )
521
517
}
522
518
523
519
/// The minimum amount required for a successful payment of the invoice.
524
- pub fn amount_msats ( & self ) -> u64 {
525
- self . contents . amount_msats ( )
520
+ pub fn amount_msats( & $ self) -> u64 {
521
+ $ contents. amount_msats( )
526
522
}
527
523
528
524
/// Fallback addresses for paying the invoice on-chain, in order of most-preferred to
529
525
/// least-preferred.
530
- pub fn fallbacks ( & self ) -> Vec < Address > {
531
- self . contents . fallbacks ( )
526
+ pub fn fallbacks( & $ self) -> Vec <Address > {
527
+ $ contents. fallbacks( )
532
528
}
533
529
534
530
/// Features pertaining to paying an invoice.
535
- pub fn features ( & self ) -> & Bolt12InvoiceFeatures {
536
- self . contents . features ( )
531
+ pub fn invoice_features ( & $ self) -> & Bolt12InvoiceFeatures {
532
+ $ contents. features( )
537
533
}
538
534
539
535
/// The public key corresponding to the key used to sign the invoice.
540
- pub fn signing_pubkey ( & self ) -> PublicKey {
541
- self . contents . signing_pubkey ( )
536
+ pub fn signing_pubkey( & $ self) -> PublicKey {
537
+ $ contents. signing_pubkey( )
542
538
}
539
+ } }
540
+
541
+ impl UnsignedBolt12Invoice {
542
+ invoice_accessors ! ( self , self . contents) ;
543
+ }
544
+
545
+ impl Bolt12Invoice {
546
+ invoice_accessors ! ( self , self . contents) ;
543
547
544
548
/// Signature of the invoice verified using [`Bolt12Invoice::signing_pubkey`].
545
549
pub fn signature ( & self ) -> Signature {
@@ -1086,6 +1090,19 @@ mod tests {
1086
1090
let mut buffer = Vec :: new ( ) ;
1087
1091
unsigned_invoice. write ( & mut buffer) . unwrap ( ) ;
1088
1092
1093
+ assert_eq ! ( unsigned_invoice. bytes, buffer. as_slice( ) ) ;
1094
+ assert_eq ! ( unsigned_invoice. description( ) , PrintableString ( "foo" ) ) ;
1095
+ assert_eq ! ( unsigned_invoice. payment_paths( ) , payment_paths. as_slice( ) ) ;
1096
+ assert_eq ! ( unsigned_invoice. created_at( ) , now) ;
1097
+ assert_eq ! ( unsigned_invoice. relative_expiry( ) , DEFAULT_RELATIVE_EXPIRY ) ;
1098
+ #[ cfg( feature = "std" ) ]
1099
+ assert ! ( !unsigned_invoice. is_expired( ) ) ;
1100
+ assert_eq ! ( unsigned_invoice. payment_hash( ) , payment_hash) ;
1101
+ assert_eq ! ( unsigned_invoice. amount_msats( ) , 1000 ) ;
1102
+ assert_eq ! ( unsigned_invoice. fallbacks( ) , vec![ ] ) ;
1103
+ assert_eq ! ( unsigned_invoice. invoice_features( ) , & Bolt12InvoiceFeatures :: empty( ) ) ;
1104
+ assert_eq ! ( unsigned_invoice. signing_pubkey( ) , recipient_pubkey( ) ) ;
1105
+
1089
1106
match UnsignedBolt12Invoice :: try_from ( buffer) {
1090
1107
Err ( e) => panic ! ( "error parsing unsigned invoice: {:?}" , e) ,
1091
1108
Ok ( parsed) => {
@@ -1109,7 +1126,7 @@ mod tests {
1109
1126
assert_eq ! ( invoice. payment_hash( ) , payment_hash) ;
1110
1127
assert_eq ! ( invoice. amount_msats( ) , 1000 ) ;
1111
1128
assert_eq ! ( invoice. fallbacks( ) , vec![ ] ) ;
1112
- assert_eq ! ( invoice. features ( ) , & Bolt12InvoiceFeatures :: empty( ) ) ;
1129
+ assert_eq ! ( invoice. invoice_features ( ) , & Bolt12InvoiceFeatures :: empty( ) ) ;
1113
1130
assert_eq ! ( invoice. signing_pubkey( ) , recipient_pubkey( ) ) ;
1114
1131
assert ! (
1115
1132
merkle:: verify_signature(
@@ -1192,7 +1209,7 @@ mod tests {
1192
1209
assert_eq ! ( invoice. payment_hash( ) , payment_hash) ;
1193
1210
assert_eq ! ( invoice. amount_msats( ) , 1000 ) ;
1194
1211
assert_eq ! ( invoice. fallbacks( ) , vec![ ] ) ;
1195
- assert_eq ! ( invoice. features ( ) , & Bolt12InvoiceFeatures :: empty( ) ) ;
1212
+ assert_eq ! ( invoice. invoice_features ( ) , & Bolt12InvoiceFeatures :: empty( ) ) ;
1196
1213
assert_eq ! ( invoice. signing_pubkey( ) , recipient_pubkey( ) ) ;
1197
1214
assert ! (
1198
1215
merkle:: verify_signature(
@@ -1540,7 +1557,7 @@ mod tests {
1540
1557
. build ( ) . unwrap ( )
1541
1558
. sign ( recipient_sign) . unwrap ( ) ;
1542
1559
let ( _, _, _, tlv_stream, _) = invoice. as_tlv_stream ( ) ;
1543
- assert_eq ! ( invoice. features ( ) , & features) ;
1560
+ assert_eq ! ( invoice. invoice_features ( ) , & features) ;
1544
1561
assert_eq ! ( tlv_stream. features, Some ( & features) ) ;
1545
1562
}
1546
1563
@@ -1760,7 +1777,7 @@ mod tests {
1760
1777
Ok ( invoice) => {
1761
1778
let mut features = Bolt12InvoiceFeatures :: empty ( ) ;
1762
1779
features. set_basic_mpp_optional ( ) ;
1763
- assert_eq ! ( invoice. features ( ) , & features) ;
1780
+ assert_eq ! ( invoice. invoice_features ( ) , & features) ;
1764
1781
} ,
1765
1782
Err ( e) => panic ! ( "error parsing invoice: {:?}" , e) ,
1766
1783
}
0 commit comments