Skip to content

Commit

Permalink
f - separate signing_pubkey macros
Browse files Browse the repository at this point in the history
  • Loading branch information
jkczyz committed Aug 8, 2024
1 parent 1200066 commit 19f49af
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 17 deletions.
24 changes: 24 additions & 0 deletions lightning/src/offers/invoice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -762,13 +762,37 @@ macro_rules! invoice_accessors { ($self: ident, $contents: expr) => {
}
} }


macro_rules! invoice_accessors_signing_pubkey {
($self: ident, $contents: expr, $invoice_type: ty) =>
{
/// The public key corresponding to the key used to sign the invoice.
///
/// If the invoices was created in response to an [`Offer`], then will be:
/// - [`Offer::issuer_id`] if `Some`, otherwise
/// - the final blinded node id from a [`BlindedPath`] in [`Offer::paths`] if `None`.
///
/// If the invoice was created in response to a [`Refund`], then may be a transient id chosen by
/// the recipient.
///
/// [`Offer`]: crate::offers::offer::Offer
/// [`Offer::issuer_id`]: crate::offers::offer::Offer::issuer_id
/// [`Offer::paths`]: crate::offers::offer::Offer::paths
/// [`Refund`]: crate::offers::refund::Refund
pub fn signing_pubkey(&$self) -> PublicKey {
$contents.signing_pubkey()
}
} }

impl UnsignedBolt12Invoice {
invoice_accessors_common!(self, self.contents, Bolt12Invoice);
invoice_accessors_signing_pubkey!(self, self.contents, Bolt12Invoice);
invoice_accessors!(self, self.contents);
}

impl Bolt12Invoice {
invoice_accessors_common!(self, self.contents, Bolt12Invoice);
invoice_accessors_signing_pubkey!(self, self.contents, Bolt12Invoice);
invoice_accessors!(self, self.contents);

/// Signature of the invoice verified using [`Bolt12Invoice::signing_pubkey`].
Expand Down
17 changes: 0 additions & 17 deletions lightning/src/offers/invoice_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,23 +124,6 @@ macro_rules! invoice_accessors_common { ($self: ident, $contents: expr, $invoice
pub fn invoice_features(&$self) -> &Bolt12InvoiceFeatures {
$contents.features()
}

/// The public key corresponding to the key used to sign the invoice.
///
/// If the invoices was created in response to an [`Offer`], then will be:
/// - [`Offer::issuer_id`] if `Some`, otherwise
/// - the final blinded node id from a [`BlindedPath`] in [`Offer::paths`] if `None`.
///
/// If the invoice was created in response to a [`Refund`], then may be transient id chosen by
/// the recipient.
///
/// [`Offer`]: crate::offers::offer::Offer
/// [`Offer::issuer_id`]: crate::offers::offer::Offer::issuer_id
/// [`Offer::paths`]: crate::offers::offer::Offer::paths
/// [`Refund`]: crate::offers::refund::Refund
pub fn signing_pubkey(&$self) -> PublicKey {
$contents.signing_pubkey()
}
} }

pub(super) use invoice_accessors_common;
Expand Down
18 changes: 18 additions & 0 deletions lightning/src/offers/static_invoice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,22 @@ macro_rules! invoice_accessors { ($self: ident, $contents: expr) => {
}
} }

macro_rules! invoice_accessors_signing_pubkey {
($self: ident, $contents: expr, $invoice_type: ty) =>
{
/// The public key corresponding to the key used to sign the invoice.
///
/// This will be:
/// - [`Offer::issuer_id`] if `Some`, otherwise
/// - the final blinded node id from a [`BlindedPath`] in [`Offer::paths`] if `None`.
///
/// [`Offer::issuer_id`]: crate::offers::offer::Offer::issuer_id
/// [`Offer::paths`]: crate::offers::offer::Offer::paths
pub fn signing_pubkey(&$self) -> PublicKey {
$contents.signing_pubkey()
}
} }

impl UnsignedStaticInvoice {
fn new(offer_bytes: &Vec<u8>, contents: InvoiceContents) -> Self {
let (_, invoice_tlv_stream) = contents.as_tlv_stream();
Expand Down Expand Up @@ -276,6 +292,7 @@ impl UnsignedStaticInvoice {
}

invoice_accessors_common!(self, self.contents, StaticInvoice);
invoice_accessors_signing_pubkey!(self, self.contents, StaticInvoice);
invoice_accessors!(self, self.contents);
}

Expand Down Expand Up @@ -311,6 +328,7 @@ where

impl StaticInvoice {
invoice_accessors_common!(self, self.contents, StaticInvoice);
invoice_accessors_signing_pubkey!(self, self.contents, StaticInvoice);
invoice_accessors!(self, self.contents);

/// Signature of the invoice verified using [`StaticInvoice::signing_pubkey`].
Expand Down

0 comments on commit 19f49af

Please sign in to comment.