Skip to content

Commit bbc15f5

Browse files
Genericize BOLT 12 invoice{_builder} common macro docs over invoice type
Will be useful so the docs generated work for static invoices.
1 parent 7417406 commit bbc15f5

File tree

2 files changed

+23
-20
lines changed

2 files changed

+23
-20
lines changed

lightning/src/offers/invoice.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -383,35 +383,35 @@ impl<'a> InvoiceBuilder<'a, DerivedSigningPubkey> {
383383

384384
impl<'a, S: SigningPubkeyStrategy> InvoiceBuilder<'a, S> {
385385
invoice_builder_methods!(self, Self, Self, self, S, mut);
386-
invoice_builder_methods_common!(self, Self, self.invoice.fields_mut(), Self, self, S, mut);
386+
invoice_builder_methods_common!(self, Self, self.invoice.fields_mut(), Self, self, S, Bolt12Invoice, mut);
387387
}
388388

389389
#[cfg(all(c_bindings, not(test)))]
390390
impl<'a> InvoiceWithExplicitSigningPubkeyBuilder<'a> {
391391
invoice_explicit_signing_pubkey_builder_methods!(self, &mut Self);
392392
invoice_builder_methods!(self, &mut Self, (), (), ExplicitSigningPubkey);
393-
invoice_builder_methods_common!(self, &mut Self, self.invoice.fields_mut(), (), (), ExplicitSigningPubkey);
393+
invoice_builder_methods_common!(self, &mut Self, self.invoice.fields_mut(), (), (), ExplicitSigningPubkey, Bolt12Invoice);
394394
}
395395

396396
#[cfg(all(c_bindings, test))]
397397
impl<'a> InvoiceWithExplicitSigningPubkeyBuilder<'a> {
398398
invoice_explicit_signing_pubkey_builder_methods!(self, &mut Self);
399399
invoice_builder_methods!(self, &mut Self, &mut Self, self, ExplicitSigningPubkey);
400-
invoice_builder_methods_common!(self, &mut Self, self.invoice.fields_mut(), &mut Self, self, ExplicitSigningPubkey);
400+
invoice_builder_methods_common!(self, &mut Self, self.invoice.fields_mut(), &mut Self, self, ExplicitSigningPubkey, Bolt12Invoice);
401401
}
402402

403403
#[cfg(all(c_bindings, not(test)))]
404404
impl<'a> InvoiceWithDerivedSigningPubkeyBuilder<'a> {
405405
invoice_derived_signing_pubkey_builder_methods!(self, &mut Self);
406406
invoice_builder_methods!(self, &mut Self, (), (), DerivedSigningPubkey);
407-
invoice_builder_methods_common!(self, &mut Self, self.invoice.fields_mut(), (), (), DerivedSigningPubkey);
407+
invoice_builder_methods_common!(self, &mut Self, self.invoice.fields_mut(), (), (), DerivedSigningPubkey, Bolt12Invoice);
408408
}
409409

410410
#[cfg(all(c_bindings, test))]
411411
impl<'a> InvoiceWithDerivedSigningPubkeyBuilder<'a> {
412412
invoice_derived_signing_pubkey_builder_methods!(self, &mut Self);
413413
invoice_builder_methods!(self, &mut Self, &mut Self, self, DerivedSigningPubkey);
414-
invoice_builder_methods_common!(self, &mut Self, self.invoice.fields_mut(), &mut Self, self, DerivedSigningPubkey);
414+
invoice_builder_methods_common!(self, &mut Self, self.invoice.fields_mut(), &mut Self, self, DerivedSigningPubkey, Bolt12Invoice);
415415
}
416416

417417
#[cfg(c_bindings)]
@@ -752,12 +752,12 @@ macro_rules! invoice_accessors { ($self: ident, $contents: expr) => {
752752
} }
753753

754754
impl UnsignedBolt12Invoice {
755-
invoice_accessors_common!(self, self.contents);
755+
invoice_accessors_common!(self, self.contents, Bolt12Invoice);
756756
invoice_accessors!(self, self.contents);
757757
}
758758

759759
impl Bolt12Invoice {
760-
invoice_accessors_common!(self, self.contents);
760+
invoice_accessors_common!(self, self.contents, Bolt12Invoice);
761761
invoice_accessors!(self, self.contents);
762762

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

lightning/src/offers/invoice_macros.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@
1111
1212
macro_rules! invoice_builder_methods_common { (
1313
$self: ident, $self_type: ty, $invoice_fields: expr, $return_type: ty, $return_value: expr,
14-
$type_param: ty $(, $self_mut: tt)?
14+
$type_param: ty, $invoice_type: ty $(, $self_mut: tt)?
1515
) => {
16-
/// Sets the [`Bolt12Invoice::relative_expiry`] as seconds since [`Bolt12Invoice::created_at`].
17-
/// Any expiry that has already passed is valid and can be checked for using
18-
/// [`Bolt12Invoice::is_expired`].
16+
#[doc = concat!("Sets the [`", stringify!($invoice_type), "::relative_expiry`]")]
17+
#[doc = concat!("as seconds since [`", stringify!($invoice_type), "::created_at`].")]
18+
#[doc = "Any expiry that has already passed is valid and can be checked for using"]
19+
#[doc = concat!("[`", stringify!($invoice_type), "::is_expired`].")]
1920
///
2021
/// Successive calls to this method will override the previous setting.
2122
pub fn relative_expiry($($self_mut)* $self: $self_type, relative_expiry_secs: u32) -> $return_type {
@@ -24,7 +25,7 @@ macro_rules! invoice_builder_methods_common { (
2425
$return_value
2526
}
2627

27-
/// Adds a P2WSH address to [`Bolt12Invoice::fallbacks`].
28+
#[doc = concat!("Adds a P2WSH address to [`", stringify!($invoice_type), "::fallbacks`].")]
2829
///
2930
/// Successive calls to this method will add another address. Caller is responsible for not
3031
/// adding duplicate addresses and only calling if capable of receiving to P2WSH addresses.
@@ -41,7 +42,7 @@ macro_rules! invoice_builder_methods_common { (
4142
$return_value
4243
}
4344

44-
/// Adds a P2WPKH address to [`Bolt12Invoice::fallbacks`].
45+
#[doc = concat!("Adds a P2WPKH address to [`", stringify!($invoice_type), "::fallbacks`].")]
4546
///
4647
/// Successive calls to this method will add another address. Caller is responsible for not
4748
/// adding duplicate addresses and only calling if capable of receiving to P2WPKH addresses.
@@ -58,7 +59,7 @@ macro_rules! invoice_builder_methods_common { (
5859
$return_value
5960
}
6061

61-
/// Adds a P2TR address to [`Bolt12Invoice::fallbacks`].
62+
#[doc = concat!("Adds a P2TR address to [`", stringify!($invoice_type), "::fallbacks`].")]
6263
///
6364
/// Successive calls to this method will add another address. Caller is responsible for not
6465
/// adding duplicate addresses and only calling if capable of receiving to P2TR addresses.
@@ -73,20 +74,21 @@ macro_rules! invoice_builder_methods_common { (
7374
$return_value
7475
}
7576

76-
/// Sets [`Bolt12Invoice::invoice_features`] to indicate MPP may be used. Otherwise, MPP is
77-
/// disallowed.
77+
#[doc = concat!("Sets [`", stringify!($invoice_type), "::invoice_features`]")]
78+
#[doc = "to indicate MPP may be used. Otherwise, MPP is disallowed."]
7879
pub fn allow_mpp($($self_mut)* $self: $self_type) -> $return_type {
7980
$invoice_fields.features.set_basic_mpp_optional();
8081
$return_value
8182
}
8283
} }
8384

84-
macro_rules! invoice_accessors_common { ($self: ident, $contents: expr) => {
85+
macro_rules! invoice_accessors_common { ($self: ident, $contents: expr, $invoice_type: ty) => {
8586
/// Paths to the recipient originating from publicly reachable nodes, including information
8687
/// needed for routing payments across them.
8788
///
8889
/// 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+
/// privacy is lost if a public node id is used for
91+
#[doc = concat!("[`", stringify!($invoice_type), "::signing_pubkey`].")]
9092
///
9193
/// This is not exported to bindings users as slices with non-reference types cannot be ABI
9294
/// matched in another language.
@@ -99,8 +101,9 @@ macro_rules! invoice_accessors_common { ($self: ident, $contents: expr) => {
99101
$contents.created_at()
100102
}
101103

102-
/// Duration since [`Bolt12Invoice::created_at`] when the invoice has expired and therefore
103-
/// should no longer be paid.
104+
/// Duration since
105+
#[doc = concat!("[`", stringify!($invoice_type), "::created_at`]")]
106+
/// when the invoice has expired and therefore should no longer be paid.
104107
pub fn relative_expiry(&$self) -> Duration {
105108
$contents.relative_expiry()
106109
}

0 commit comments

Comments
 (0)