Skip to content

Commit 4b79cd5

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 b10aaa3 commit 4b79cd5

File tree

2 files changed

+23
-22
lines changed

2 files changed

+23
-22
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 & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,19 @@
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`].
19-
///
20-
/// Successive calls to this method will override the previous setting.
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`].")]
2120
pub fn relative_expiry($($self_mut)* $self: $self_type, relative_expiry_secs: u32) -> $return_type {
2221
let relative_expiry = Duration::from_secs(relative_expiry_secs as u64);
2322
$invoice_fields.relative_expiry = Some(relative_expiry);
2423
$return_value
2524
}
2625

27-
/// Adds a P2WSH address to [`Bolt12Invoice::fallbacks`].
26+
#[doc = concat!("Adds a P2WSH address to [`", stringify!($invoice_type), "::fallbacks`].")]
2827
///
2928
/// Successive calls to this method will add another address. Caller is responsible for not
3029
/// adding duplicate addresses and only calling if capable of receiving to P2WSH addresses.
@@ -41,7 +40,7 @@ macro_rules! invoice_builder_methods_common { (
4140
$return_value
4241
}
4342

44-
/// Adds a P2WPKH address to [`Bolt12Invoice::fallbacks`].
43+
#[doc = concat!("Adds a P2WPKH address to [`", stringify!($invoice_type), "::fallbacks`].")]
4544
///
4645
/// Successive calls to this method will add another address. Caller is responsible for not
4746
/// adding duplicate addresses and only calling if capable of receiving to P2WPKH addresses.
@@ -58,7 +57,7 @@ macro_rules! invoice_builder_methods_common { (
5857
$return_value
5958
}
6059

61-
/// Adds a P2TR address to [`Bolt12Invoice::fallbacks`].
60+
#[doc = concat!("Adds a P2TR address to [`", stringify!($invoice_type), "::fallbacks`].")]
6261
///
6362
/// Successive calls to this method will add another address. Caller is responsible for not
6463
/// adding duplicate addresses and only calling if capable of receiving to P2TR addresses.
@@ -73,20 +72,21 @@ macro_rules! invoice_builder_methods_common { (
7372
$return_value
7473
}
7574

76-
/// Sets [`Bolt12Invoice::invoice_features`] to indicate MPP may be used. Otherwise, MPP is
77-
/// disallowed.
75+
#[doc = concat!("Sets [`", stringify!($invoice_type), "::invoice_features`]")]
76+
#[doc = "to indicate MPP may be used. Otherwise, MPP is disallowed."]
7877
pub fn allow_mpp($($self_mut)* $self: $self_type) -> $return_type {
7978
$invoice_fields.features.set_basic_mpp_optional();
8079
$return_value
8180
}
8281
} }
8382

84-
macro_rules! invoice_accessors_common { ($self: ident, $contents: expr) => {
83+
macro_rules! invoice_accessors_common { ($self: ident, $contents: expr, $invoice_type: ty) => {
8584
/// Paths to the recipient originating from publicly reachable nodes, including information
8685
/// needed for routing payments across them.
8786
///
8887
/// 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`].
88+
/// privacy is lost if a public node id is used for
89+
#[doc = concat!("[`", stringify!($invoice_type), "::signing_pubkey`].")]
9090
///
9191
/// This is not exported to bindings users as slices with non-reference types cannot be ABI
9292
/// matched in another language.
@@ -99,8 +99,9 @@ macro_rules! invoice_accessors_common { ($self: ident, $contents: expr) => {
9999
$contents.created_at()
100100
}
101101

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

0 commit comments

Comments
 (0)