macro_rules! invoice_builder_methods_common { (
$self: ident, $self_type: ty, $invoice_fields: expr, $return_type: ty, $return_value: expr,
$invoice_type: ty $(, $self_mut: tt)?
) => {
#[doc = concat!("Sets the [`", stringify!($invoice_type), "::relative_expiry`]")]
#[doc = concat!("as seconds since [`", stringify!($invoice_type), "::created_at`].")]
#[doc = "Any expiry that has already passed is valid and can be checked for using"]
#[cfg_attr(feature = "std", doc = concat!("[`", stringify!($invoice_type), "::is_expired`]."))]
pub fn relative_expiry($($self_mut)* $self: $self_type, relative_expiry_secs: u32) -> $return_type {
let relative_expiry = Duration::from_secs(relative_expiry_secs as u64);
$invoice_fields.relative_expiry = Some(relative_expiry);
$return_value
}
#[doc = concat!("Adds a P2WSH address to [`", stringify!($invoice_type), "::fallbacks`].")]
pub fn fallback_v0_p2wsh(
$($self_mut)* $self: $self_type, script_hash: &bitcoin::WScriptHash
) -> $return_type {
use bitcoin::hashes::Hash;
let address = FallbackAddress {
version: bitcoin::WitnessVersion::V0.to_num(),
program: Vec::from(script_hash.to_byte_array()),
};
$invoice_fields.fallbacks.get_or_insert_with(Vec::new).push(address);
$return_value
}
#[doc = concat!("Adds a P2WPKH address to [`", stringify!($invoice_type), "::fallbacks`].")]
pub fn fallback_v0_p2wpkh(
$($self_mut)* $self: $self_type, pubkey_hash: &bitcoin::WPubkeyHash
) -> $return_type {
use bitcoin::hashes::Hash;
let address = FallbackAddress {
version: bitcoin::WitnessVersion::V0.to_num(),
program: Vec::from(pubkey_hash.to_byte_array()),
};
$invoice_fields.fallbacks.get_or_insert_with(Vec::new).push(address);
$return_value
}
#[doc = concat!("Adds a P2TR address to [`", stringify!($invoice_type), "::fallbacks`].")]
pub fn fallback_v1_p2tr_tweaked(
$($self_mut)* $self: $self_type, output_key: &bitcoin::key::TweakedPublicKey
) -> $return_type {
let address = FallbackAddress {
version: bitcoin::WitnessVersion::V1.to_num(),
program: Vec::from(&output_key.serialize()[..]),
};
$invoice_fields.fallbacks.get_or_insert_with(Vec::new).push(address);
$return_value
}
#[doc = concat!("Sets [`", stringify!($invoice_type), "::invoice_features`]")]
#[doc = "to indicate MPP may be used. Otherwise, MPP is disallowed."]
pub fn allow_mpp($($self_mut)* $self: $self_type) -> $return_type {
$invoice_fields.features.set_basic_mpp_optional();
$return_value
}
} }
#[cfg(test)]
macro_rules! invoice_builder_methods_test_common { (
$self: ident, $self_type: ty, $invoice_fields: expr, $return_type: ty, $return_value: expr
$(, $self_mut: tt)?
) => {
#[allow(dead_code)] pub(crate) fn features_unchecked(
$($self_mut)* $self: $self_type, features: Bolt12InvoiceFeatures
) -> $return_type {
$invoice_fields.features = features;
$return_value
}
#[cfg_attr(c_bindings, allow(dead_code))]
pub(super) fn experimental_baz($($self_mut)* $self: $self_type, experimental_baz: u64) -> $return_type {
$invoice_fields.experimental_baz = Some(experimental_baz);
$return_value
}
} }
macro_rules! invoice_accessors_common { ($self: ident, $contents: expr, $invoice_type: ty) => {
#[doc = concat!("[`", stringify!($invoice_type), "::signing_pubkey`].")]
pub fn payment_paths(&$self) -> &[BlindedPaymentPath] {
$contents.payment_paths()
}
pub fn created_at(&$self) -> Duration {
$contents.created_at()
}
#[doc = concat!("[`", stringify!($invoice_type), "::created_at`]")]
pub fn relative_expiry(&$self) -> Duration {
$contents.relative_expiry()
}
#[cfg(feature = "std")]
pub fn is_expired(&$self) -> bool {
$contents.is_expired()
}
pub fn is_expired_no_std(&$self, duration_since_epoch: Duration) -> bool {
$contents.is_expired_no_std(duration_since_epoch)
}
pub fn fallbacks(&$self) -> Vec<Address> {
$contents.fallbacks()
}
pub fn invoice_features(&$self) -> &Bolt12InvoiceFeatures {
$contents.features()
}
} }
pub(super) use invoice_accessors_common;
pub(super) use invoice_builder_methods_common;
#[cfg(test)]
pub(super) use invoice_builder_methods_test_common;