Skip to content

Commit b10aaa3

Browse files
Move common BOLT 12 accessor methods to new macro.
Will be useful when we support static BOLT 12 invoices.
1 parent d0f87d7 commit b10aaa3

File tree

2 files changed

+53
-47
lines changed

2 files changed

+53
-47
lines changed

lightning/src/offers/invoice.rs

Lines changed: 3 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ use crate::ln::channelmanager::PaymentId;
116116
use crate::ln::features::{BlindedHopFeatures, Bolt12InvoiceFeatures, InvoiceRequestFeatures, OfferFeatures};
117117
use crate::ln::inbound_payment::ExpandedKey;
118118
use crate::ln::msgs::DecodeError;
119-
use crate::offers::invoice_macros::invoice_builder_methods_common;
119+
use crate::offers::invoice_macros::{invoice_accessors_common, invoice_builder_methods_common};
120120
use crate::offers::invoice_request::{INVOICE_REQUEST_PAYER_ID_TYPE, INVOICE_REQUEST_TYPES, IV_BYTES as INVOICE_REQUEST_IV_BYTES, InvoiceRequest, InvoiceRequestContents, InvoiceRequestTlvStream, InvoiceRequestTlvStreamRef};
121121
use crate::offers::merkle::{SignError, SignFn, SignatureTlvStream, SignatureTlvStreamRef, TaggedHash, TlvStream, WithoutSignatures, self};
122122
use crate::offers::offer::{Amount, OFFER_TYPES, OfferTlvStream, OfferTlvStreamRef, Quantity};
@@ -740,35 +740,6 @@ macro_rules! invoice_accessors { ($self: ident, $contents: expr) => {
740740
$contents.payer_note()
741741
}
742742

743-
/// Paths to the recipient originating from publicly reachable nodes, including information
744-
/// needed for routing payments across them.
745-
///
746-
/// Blinded paths provide recipient privacy by obfuscating its node id. Note, however, that this
747-
/// privacy is lost if a public node id is used for [`Bolt12Invoice::signing_pubkey`].
748-
///
749-
/// This is not exported to bindings users as slices with non-reference types cannot be ABI
750-
/// matched in another language.
751-
pub fn payment_paths(&$self) -> &[(BlindedPayInfo, BlindedPath)] {
752-
$contents.payment_paths()
753-
}
754-
755-
/// Duration since the Unix epoch when the invoice was created.
756-
pub fn created_at(&$self) -> Duration {
757-
$contents.created_at()
758-
}
759-
760-
/// Duration since [`Bolt12Invoice::created_at`] when the invoice has expired and therefore
761-
/// should no longer be paid.
762-
pub fn relative_expiry(&$self) -> Duration {
763-
$contents.relative_expiry()
764-
}
765-
766-
/// Whether the invoice has expired.
767-
#[cfg(feature = "std")]
768-
pub fn is_expired(&$self) -> bool {
769-
$contents.is_expired()
770-
}
771-
772743
/// SHA256 hash of the payment preimage that will be given in return for paying the invoice.
773744
pub fn payment_hash(&$self) -> PaymentHash {
774745
$contents.payment_hash()
@@ -778,29 +749,15 @@ macro_rules! invoice_accessors { ($self: ident, $contents: expr) => {
778749
pub fn amount_msats(&$self) -> u64 {
779750
$contents.amount_msats()
780751
}
781-
782-
/// Fallback addresses for paying the invoice on-chain, in order of most-preferred to
783-
/// least-preferred.
784-
pub fn fallbacks(&$self) -> Vec<Address> {
785-
$contents.fallbacks()
786-
}
787-
788-
/// Features pertaining to paying an invoice.
789-
pub fn invoice_features(&$self) -> &Bolt12InvoiceFeatures {
790-
$contents.features()
791-
}
792-
793-
/// The public key corresponding to the key used to sign the invoice.
794-
pub fn signing_pubkey(&$self) -> PublicKey {
795-
$contents.signing_pubkey()
796-
}
797752
} }
798753

799754
impl UnsignedBolt12Invoice {
755+
invoice_accessors_common!(self, self.contents);
800756
invoice_accessors!(self, self.contents);
801757
}
802758

803759
impl Bolt12Invoice {
760+
invoice_accessors_common!(self, self.contents);
804761
invoice_accessors!(self, self.contents);
805762

806763
/// Signature of the invoice verified using [`Bolt12Invoice::signing_pubkey`].

lightning/src/offers/invoice_macros.rs

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
//! Shared code between BOLT 12 static and single-use invoices.
1111
1212
macro_rules! invoice_builder_methods_common { (
13-
$self: ident, $self_type: ty, $invoice_fields: expr, $return_type: ty, $return_value: expr, $type_param: ty $(, $self_mut: tt)?
13+
$self: ident, $self_type: ty, $invoice_fields: expr, $return_type: ty, $return_value: expr,
14+
$type_param: ty $(, $self_mut: tt)?
1415
) => {
1516
/// Sets the [`Bolt12Invoice::relative_expiry`] as seconds since [`Bolt12Invoice::created_at`].
1617
/// Any expiry that has already passed is valid and can be checked for using
@@ -80,4 +81,52 @@ macro_rules! invoice_builder_methods_common { (
8081
}
8182
} }
8283

84+
macro_rules! invoice_accessors_common { ($self: ident, $contents: expr) => {
85+
/// Paths to the recipient originating from publicly reachable nodes, including information
86+
/// needed for routing payments across them.
87+
///
88+
/// Blinded paths provide recipient privacy by obfuscating its node id. Note, however, that this
89+
/// privacy is lost if a public node id is used for [`Bolt12Invoice::signing_pubkey`].
90+
///
91+
/// This is not exported to bindings users as slices with non-reference types cannot be ABI
92+
/// matched in another language.
93+
pub fn payment_paths(&$self) -> &[(BlindedPayInfo, BlindedPath)] {
94+
$contents.payment_paths()
95+
}
96+
97+
/// Duration since the Unix epoch when the invoice was created.
98+
pub fn created_at(&$self) -> Duration {
99+
$contents.created_at()
100+
}
101+
102+
/// Duration since [`Bolt12Invoice::created_at`] when the invoice has expired and therefore
103+
/// should no longer be paid.
104+
pub fn relative_expiry(&$self) -> Duration {
105+
$contents.relative_expiry()
106+
}
107+
108+
/// Whether the invoice has expired.
109+
#[cfg(feature = "std")]
110+
pub fn is_expired(&$self) -> bool {
111+
$contents.is_expired()
112+
}
113+
114+
/// Fallback addresses for paying the invoice on-chain, in order of most-preferred to
115+
/// least-preferred.
116+
pub fn fallbacks(&$self) -> Vec<Address> {
117+
$contents.fallbacks()
118+
}
119+
120+
/// Features pertaining to paying an invoice.
121+
pub fn invoice_features(&$self) -> &Bolt12InvoiceFeatures {
122+
$contents.features()
123+
}
124+
125+
/// The public key corresponding to the key used to sign the invoice.
126+
pub fn signing_pubkey(&$self) -> PublicKey {
127+
$contents.signing_pubkey()
128+
}
129+
} }
130+
131+
pub(super) use invoice_accessors_common;
83132
pub(super) use invoice_builder_methods_common;

0 commit comments

Comments
 (0)