@@ -358,77 +358,86 @@ pub(super) struct OfferContents {
358
358
signing_pubkey : PublicKey ,
359
359
}
360
360
361
- impl Offer {
361
+ macro_rules! offer_accessors { ( $self : ident , $contents : expr ) => {
362
362
// TODO: Return a slice once ChainHash has constants.
363
363
// - https://github.com/rust-bitcoin/rust-bitcoin/pull/1283
364
364
// - https://github.com/rust-bitcoin/rust-bitcoin/pull/1286
365
365
/// The chains that may be used when paying a requested invoice (e.g., bitcoin mainnet).
366
366
/// Payments must be denominated in units of the minimal lightning-payable unit (e.g., msats)
367
367
/// for the selected chain.
368
- pub fn chains ( & self ) -> Vec < ChainHash > {
369
- self . contents . chains ( )
370
- }
371
-
372
- pub ( super ) fn implied_chain ( & self ) -> ChainHash {
373
- self . contents . implied_chain ( )
374
- }
375
-
376
- /// Returns whether the given chain is supported by the offer.
377
- pub fn supports_chain ( & self , chain : ChainHash ) -> bool {
378
- self . contents . supports_chain ( chain)
368
+ pub fn chains( & $self) -> Vec <$crate:: bitcoin:: blockdata:: constants:: ChainHash > {
369
+ $contents. chains( )
379
370
}
380
371
381
372
// TODO: Link to corresponding method in `InvoiceRequest`.
382
373
/// Opaque bytes set by the originator. Useful for authentication and validating fields since it
383
374
/// is reflected in `invoice_request` messages along with all the other fields from the `offer`.
384
- pub fn metadata ( & self ) -> Option < & Vec < u8 > > {
385
- self . contents . metadata ( )
375
+ pub fn metadata( & $ self) -> Option <& Vec <u8 >> {
376
+ $ contents. metadata( )
386
377
}
387
378
388
379
/// The minimum amount required for a successful payment of a single item.
389
- pub fn amount ( & self ) -> Option < & Amount > {
390
- self . contents . amount ( )
380
+ pub fn amount( & $ self) -> Option <& $crate :: offers :: offer :: Amount > {
381
+ $ contents. amount( )
391
382
}
392
383
393
384
/// A complete description of the purpose of the payment. Intended to be displayed to the user
394
385
/// but with the caveat that it has not been verified in any way.
395
- pub fn description ( & self ) -> PrintableString {
396
- self . contents . description ( )
386
+ pub fn description( & $ self) -> $crate :: util :: string :: PrintableString {
387
+ $ contents. description( )
397
388
}
398
389
399
390
/// Features pertaining to the offer.
400
- pub fn features ( & self ) -> & OfferFeatures {
401
- & self . contents . features ( )
391
+ pub fn offer_features ( & $ self) -> & $crate :: ln :: features :: OfferFeatures {
392
+ & $ contents. features( )
402
393
}
403
394
404
395
/// Duration since the Unix epoch when an invoice should no longer be requested.
405
396
///
406
397
/// If `None`, the offer does not expire.
407
- pub fn absolute_expiry ( & self ) -> Option < Duration > {
408
- self . contents . absolute_expiry ( )
409
- }
410
-
411
- /// Whether the offer has expired.
412
- #[ cfg( feature = "std" ) ]
413
- pub fn is_expired ( & self ) -> bool {
414
- self . contents . is_expired ( )
398
+ pub fn absolute_expiry( & $self) -> Option <core:: time:: Duration > {
399
+ $contents. absolute_expiry( )
415
400
}
416
401
417
402
/// The issuer of the offer, possibly beginning with `user@domain` or `domain`. Intended to be
418
403
/// displayed to the user but with the caveat that it has not been verified in any way.
419
- pub fn issuer ( & self ) -> Option < PrintableString > {
420
- self . contents . issuer ( )
404
+ pub fn issuer( & $ self) -> Option <$crate :: util :: string :: PrintableString > {
405
+ $ contents. issuer( )
421
406
}
422
407
423
408
/// Paths to the recipient originating from publicly reachable nodes. Blinded paths provide
424
409
/// recipient privacy by obfuscating its node id.
425
- pub fn paths ( & self ) -> & [ BlindedPath ] {
426
- self . contents . paths ( )
410
+ pub fn paths( & $ self) -> & [ $crate :: blinded_path :: BlindedPath ] {
411
+ $ contents. paths( )
427
412
}
428
413
429
414
/// The quantity of items supported.
430
- pub fn supported_quantity ( & self ) -> Quantity {
431
- self . contents . supported_quantity ( )
415
+ pub fn supported_quantity( & $self) -> $crate:: offers:: offer:: Quantity {
416
+ $contents. supported_quantity( )
417
+ }
418
+
419
+ /// The public key used by the recipient to sign invoices.
420
+ pub fn signing_pubkey( & $self) -> $crate:: bitcoin:: secp256k1:: PublicKey {
421
+ $contents. signing_pubkey( )
422
+ }
423
+ } }
424
+
425
+ impl Offer {
426
+ offer_accessors ! ( self , self . contents) ;
427
+
428
+ pub ( super ) fn implied_chain ( & self ) -> ChainHash {
429
+ self . contents . implied_chain ( )
430
+ }
431
+
432
+ /// Returns whether the given chain is supported by the offer.
433
+ pub fn supports_chain ( & self , chain : ChainHash ) -> bool {
434
+ self . contents . supports_chain ( chain)
435
+ }
436
+
437
+ /// Whether the offer has expired.
438
+ #[ cfg( feature = "std" ) ]
439
+ pub fn is_expired ( & self ) -> bool {
440
+ self . contents . is_expired ( )
432
441
}
433
442
434
443
/// Returns whether the given quantity is valid for the offer.
@@ -443,11 +452,6 @@ impl Offer {
443
452
self . contents . expects_quantity ( )
444
453
}
445
454
446
- /// The public key used by the recipient to sign invoices.
447
- pub fn signing_pubkey ( & self ) -> PublicKey {
448
- self . contents . signing_pubkey ( )
449
- }
450
-
451
455
/// Similar to [`Offer::request_invoice`] except it:
452
456
/// - derives the [`InvoiceRequest::payer_id`] such that a different key can be used for each
453
457
/// request, and
@@ -469,7 +473,7 @@ impl Offer {
469
473
where
470
474
ES :: Target : EntropySource ,
471
475
{
472
- if self . features ( ) . requires_unknown_bits ( ) {
476
+ if self . offer_features ( ) . requires_unknown_bits ( ) {
473
477
return Err ( Bolt12SemanticError :: UnknownRequiredFeatures ) ;
474
478
}
475
479
@@ -490,7 +494,7 @@ impl Offer {
490
494
where
491
495
ES :: Target : EntropySource ,
492
496
{
493
- if self . features ( ) . requires_unknown_bits ( ) {
497
+ if self . offer_features ( ) . requires_unknown_bits ( ) {
494
498
return Err ( Bolt12SemanticError :: UnknownRequiredFeatures ) ;
495
499
}
496
500
@@ -515,7 +519,7 @@ impl Offer {
515
519
pub fn request_invoice (
516
520
& self , metadata : Vec < u8 > , payer_id : PublicKey
517
521
) -> Result < InvoiceRequestBuilder < ExplicitPayerId , secp256k1:: SignOnly > , Bolt12SemanticError > {
518
- if self . features ( ) . requires_unknown_bits ( ) {
522
+ if self . offer_features ( ) . requires_unknown_bits ( ) {
519
523
return Err ( Bolt12SemanticError :: UnknownRequiredFeatures ) ;
520
524
}
521
525
@@ -890,7 +894,7 @@ mod tests {
890
894
assert_eq ! ( offer. metadata( ) , None ) ;
891
895
assert_eq ! ( offer. amount( ) , None ) ;
892
896
assert_eq ! ( offer. description( ) , PrintableString ( "foo" ) ) ;
893
- assert_eq ! ( offer. features ( ) , & OfferFeatures :: empty( ) ) ;
897
+ assert_eq ! ( offer. offer_features ( ) , & OfferFeatures :: empty( ) ) ;
894
898
assert_eq ! ( offer. absolute_expiry( ) , None ) ;
895
899
#[ cfg( feature = "std" ) ]
896
900
assert ! ( !offer. is_expired( ) ) ;
@@ -1131,15 +1135,15 @@ mod tests {
1131
1135
. features_unchecked ( OfferFeatures :: unknown ( ) )
1132
1136
. build ( )
1133
1137
. unwrap ( ) ;
1134
- assert_eq ! ( offer. features ( ) , & OfferFeatures :: unknown( ) ) ;
1138
+ assert_eq ! ( offer. offer_features ( ) , & OfferFeatures :: unknown( ) ) ;
1135
1139
assert_eq ! ( offer. as_tlv_stream( ) . features, Some ( & OfferFeatures :: unknown( ) ) ) ;
1136
1140
1137
1141
let offer = OfferBuilder :: new ( "foo" . into ( ) , pubkey ( 42 ) )
1138
1142
. features_unchecked ( OfferFeatures :: unknown ( ) )
1139
1143
. features_unchecked ( OfferFeatures :: empty ( ) )
1140
1144
. build ( )
1141
1145
. unwrap ( ) ;
1142
- assert_eq ! ( offer. features ( ) , & OfferFeatures :: empty( ) ) ;
1146
+ assert_eq ! ( offer. offer_features ( ) , & OfferFeatures :: empty( ) ) ;
1143
1147
assert_eq ! ( offer. as_tlv_stream( ) . features, None ) ;
1144
1148
}
1145
1149
0 commit comments