]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Move common BOLT 12 accessor methods to new macro.
authorValentine Wallace <vwallace@protonmail.com>
Thu, 9 May 2024 18:19:41 +0000 (14:19 -0400)
committerValentine Wallace <vwallace@protonmail.com>
Tue, 4 Jun 2024 20:29:34 +0000 (16:29 -0400)
Will be useful when we support static BOLT 12 invoices.

lightning/src/offers/invoice.rs
lightning/src/offers/invoice_macros.rs

index 4fcd38a1c8d347dd7c172c068195814453a18f0a..7fdbab3379c3e59f6bc0f671f168a4b2b1ec76b1 100644 (file)
@@ -116,7 +116,7 @@ use crate::ln::channelmanager::PaymentId;
 use crate::ln::features::{BlindedHopFeatures, Bolt12InvoiceFeatures, InvoiceRequestFeatures, OfferFeatures};
 use crate::ln::inbound_payment::ExpandedKey;
 use crate::ln::msgs::DecodeError;
-use crate::offers::invoice_macros::invoice_builder_methods_common;
+use crate::offers::invoice_macros::{invoice_accessors_common, invoice_builder_methods_common};
 use crate::offers::invoice_request::{INVOICE_REQUEST_PAYER_ID_TYPE, INVOICE_REQUEST_TYPES, IV_BYTES as INVOICE_REQUEST_IV_BYTES, InvoiceRequest, InvoiceRequestContents, InvoiceRequestTlvStream, InvoiceRequestTlvStreamRef};
 use crate::offers::merkle::{SignError, SignFn, SignatureTlvStream, SignatureTlvStreamRef, TaggedHash, TlvStream, WithoutSignatures, self};
 use crate::offers::offer::{Amount, OFFER_TYPES, OfferTlvStream, OfferTlvStreamRef, Quantity};
@@ -740,35 +740,6 @@ macro_rules! invoice_accessors { ($self: ident, $contents: expr) => {
                $contents.payer_note()
        }
 
-       /// Paths to the recipient originating from publicly reachable nodes, including information
-       /// needed for routing payments across them.
-       ///
-       /// Blinded paths provide recipient privacy by obfuscating its node id. Note, however, that this
-       /// privacy is lost if a public node id is used for [`Bolt12Invoice::signing_pubkey`].
-       ///
-       /// This is not exported to bindings users as slices with non-reference types cannot be ABI
-       /// matched in another language.
-       pub fn payment_paths(&$self) -> &[(BlindedPayInfo, BlindedPath)] {
-               $contents.payment_paths()
-       }
-
-       /// Duration since the Unix epoch when the invoice was created.
-       pub fn created_at(&$self) -> Duration {
-               $contents.created_at()
-       }
-
-       /// Duration since [`Bolt12Invoice::created_at`] when the invoice has expired and therefore
-       /// should no longer be paid.
-       pub fn relative_expiry(&$self) -> Duration {
-               $contents.relative_expiry()
-       }
-
-       /// Whether the invoice has expired.
-       #[cfg(feature = "std")]
-       pub fn is_expired(&$self) -> bool {
-               $contents.is_expired()
-       }
-
        /// SHA256 hash of the payment preimage that will be given in return for paying the invoice.
        pub fn payment_hash(&$self) -> PaymentHash {
                $contents.payment_hash()
@@ -778,29 +749,15 @@ macro_rules! invoice_accessors { ($self: ident, $contents: expr) => {
        pub fn amount_msats(&$self) -> u64 {
                $contents.amount_msats()
        }
-
-       /// Fallback addresses for paying the invoice on-chain, in order of most-preferred to
-       /// least-preferred.
-       pub fn fallbacks(&$self) -> Vec<Address> {
-               $contents.fallbacks()
-       }
-
-       /// Features pertaining to paying an invoice.
-       pub fn invoice_features(&$self) -> &Bolt12InvoiceFeatures {
-               $contents.features()
-       }
-
-       /// The public key corresponding to the key used to sign the invoice.
-       pub fn signing_pubkey(&$self) -> PublicKey {
-               $contents.signing_pubkey()
-       }
 } }
 
 impl UnsignedBolt12Invoice {
+       invoice_accessors_common!(self, self.contents);
        invoice_accessors!(self, self.contents);
 }
 
 impl Bolt12Invoice {
+       invoice_accessors_common!(self, self.contents);
        invoice_accessors!(self, self.contents);
 
        /// Signature of the invoice verified using [`Bolt12Invoice::signing_pubkey`].
index c1e860b46554d319a8f177f66ad824ff90b5a7c1..8b32edcecf86c2fe40f3f3f7c02b441d253b463e 100644 (file)
@@ -10,7 +10,8 @@
 //! Shared code between BOLT 12 static and single-use invoices.
 
 macro_rules! invoice_builder_methods_common { (
-       $self: ident, $self_type: ty, $invoice_fields: expr, $return_type: ty, $return_value: expr, $type_param: ty $(, $self_mut: tt)?
+       $self: ident, $self_type: ty, $invoice_fields: expr, $return_type: ty, $return_value: expr,
+       $type_param: ty $(, $self_mut: tt)?
 ) => {
        /// Sets the [`Bolt12Invoice::relative_expiry`] as seconds since [`Bolt12Invoice::created_at`].
        /// Any expiry that has already passed is valid and can be checked for using
@@ -80,4 +81,52 @@ macro_rules! invoice_builder_methods_common { (
        }
 } }
 
+macro_rules! invoice_accessors_common { ($self: ident, $contents: expr) => {
+       /// Paths to the recipient originating from publicly reachable nodes, including information
+       /// needed for routing payments across them.
+       ///
+       /// Blinded paths provide recipient privacy by obfuscating its node id. Note, however, that this
+       /// privacy is lost if a public node id is used for [`Bolt12Invoice::signing_pubkey`].
+       ///
+       /// This is not exported to bindings users as slices with non-reference types cannot be ABI
+       /// matched in another language.
+       pub fn payment_paths(&$self) -> &[(BlindedPayInfo, BlindedPath)] {
+               $contents.payment_paths()
+       }
+
+       /// Duration since the Unix epoch when the invoice was created.
+       pub fn created_at(&$self) -> Duration {
+               $contents.created_at()
+       }
+
+       /// Duration since [`Bolt12Invoice::created_at`] when the invoice has expired and therefore
+       /// should no longer be paid.
+       pub fn relative_expiry(&$self) -> Duration {
+               $contents.relative_expiry()
+       }
+
+       /// Whether the invoice has expired.
+       #[cfg(feature = "std")]
+       pub fn is_expired(&$self) -> bool {
+               $contents.is_expired()
+       }
+
+       /// Fallback addresses for paying the invoice on-chain, in order of most-preferred to
+       /// least-preferred.
+       pub fn fallbacks(&$self) -> Vec<Address> {
+               $contents.fallbacks()
+       }
+
+       /// Features pertaining to paying an invoice.
+       pub fn invoice_features(&$self) -> &Bolt12InvoiceFeatures {
+               $contents.features()
+       }
+
+       /// The public key corresponding to the key used to sign the invoice.
+       pub fn signing_pubkey(&$self) -> PublicKey {
+               $contents.signing_pubkey()
+       }
+} }
+
+pub(super) use invoice_accessors_common;
 pub(super) use invoice_builder_methods_common;