payer_note: Option<String>,
}
-impl InvoiceRequest {
+macro_rules! invoice_request_accessors { ($self: ident, $contents: expr) => {
/// An unpredictable series of bytes, typically containing information about the derivation of
/// [`payer_id`].
///
/// [`payer_id`]: Self::payer_id
- pub fn metadata(&self) -> &[u8] {
- self.contents.metadata()
+ pub fn payer_metadata(&$self) -> &[u8] {
+ $contents.metadata()
}
/// A chain from [`Offer::chains`] that the offer is valid for.
- pub fn chain(&self) -> ChainHash {
- self.contents.chain()
+ pub fn chain(&$self) -> ChainHash {
+ $contents.chain()
}
/// The amount to pay in msats (i.e., the minimum lightning-payable unit for [`chain`]), which
/// must be greater than or equal to [`Offer::amount`], converted if necessary.
///
/// [`chain`]: Self::chain
- pub fn amount_msats(&self) -> Option<u64> {
- self.contents.amount_msats()
+ pub fn amount_msats(&$self) -> Option<u64> {
+ $contents.amount_msats()
}
/// Features pertaining to requesting an invoice.
- pub fn features(&self) -> &InvoiceRequestFeatures {
- &self.contents.features()
+ pub fn invoice_request_features(&$self) -> &InvoiceRequestFeatures {
+ &$contents.features()
}
/// The quantity of the offer's item conforming to [`Offer::is_valid_quantity`].
- pub fn quantity(&self) -> Option<u64> {
- self.contents.quantity()
+ pub fn quantity(&$self) -> Option<u64> {
+ $contents.quantity()
}
/// A possibly transient pubkey used to sign the invoice request.
- pub fn payer_id(&self) -> PublicKey {
- self.contents.payer_id()
+ pub fn payer_id(&$self) -> PublicKey {
+ $contents.payer_id()
}
/// A payer-provided note which will be seen by the recipient and reflected back in the invoice
/// response.
- pub fn payer_note(&self) -> Option<PrintableString> {
- self.contents.payer_note()
+ pub fn payer_note(&$self) -> Option<PrintableString> {
+ $contents.payer_note()
}
+} }
+
+impl InvoiceRequest {
+ invoice_request_accessors!(self, self.contents);
/// Signature of the invoice request using [`payer_id`].
///
&self, payment_paths: Vec<(BlindedPayInfo, BlindedPath)>, payment_hash: PaymentHash,
created_at: core::time::Duration
) -> Result<InvoiceBuilder<ExplicitSigningPubkey>, Bolt12SemanticError> {
- if self.features().requires_unknown_bits() {
+ if self.invoice_request_features().requires_unknown_bits() {
return Err(Bolt12SemanticError::UnknownRequiredFeatures);
}
&self, payment_paths: Vec<(BlindedPayInfo, BlindedPath)>, payment_hash: PaymentHash,
created_at: core::time::Duration, expanded_key: &ExpandedKey, secp_ctx: &Secp256k1<T>
) -> Result<InvoiceBuilder<DerivedSigningPubkey>, Bolt12SemanticError> {
- if self.features().requires_unknown_bits() {
+ if self.invoice_request_features().requires_unknown_bits() {
return Err(Bolt12SemanticError::UnknownRequiredFeatures);
}
invoice_request.write(&mut buffer).unwrap();
assert_eq!(invoice_request.bytes, buffer.as_slice());
- assert_eq!(invoice_request.metadata(), &[1; 32]);
+ assert_eq!(invoice_request.payer_metadata(), &[1; 32]);
assert_eq!(invoice_request.chain(), ChainHash::using_genesis_block(Network::Bitcoin));
assert_eq!(invoice_request.amount_msats(), None);
- assert_eq!(invoice_request.features(), &InvoiceRequestFeatures::empty());
+ assert_eq!(invoice_request.invoice_request_features(), &InvoiceRequestFeatures::empty());
assert_eq!(invoice_request.quantity(), None);
assert_eq!(invoice_request.payer_id(), payer_pubkey());
assert_eq!(invoice_request.payer_note(), None);
.build().unwrap()
.sign(payer_sign).unwrap();
let (_, _, tlv_stream, _) = invoice_request.as_tlv_stream();
- assert_eq!(invoice_request.features(), &InvoiceRequestFeatures::unknown());
+ assert_eq!(invoice_request.invoice_request_features(), &InvoiceRequestFeatures::unknown());
assert_eq!(tlv_stream.features, Some(&InvoiceRequestFeatures::unknown()));
let invoice_request = OfferBuilder::new("foo".into(), recipient_pubkey())
.build().unwrap()
.sign(payer_sign).unwrap();
let (_, _, tlv_stream, _) = invoice_request.as_tlv_stream();
- assert_eq!(invoice_request.features(), &InvoiceRequestFeatures::empty());
+ assert_eq!(invoice_request.invoice_request_features(), &InvoiceRequestFeatures::empty());
assert_eq!(tlv_stream.features, None);
}
/// Similar to [`Offer::request_invoice`] except it:
/// - derives the [`InvoiceRequest::payer_id`] such that a different key can be used for each
/// request, and
- /// - sets the [`InvoiceRequest::metadata`] when [`InvoiceRequestBuilder::build`] is called such
- /// that it can be used by [`Bolt12Invoice::verify`] to determine if the invoice was requested
- /// using a base [`ExpandedKey`] from which the payer id was derived.
+ /// - sets the [`InvoiceRequest::payer_metadata`] when [`InvoiceRequestBuilder::build`] is
+ /// called such that it can be used by [`Bolt12Invoice::verify`] to determine if the invoice
+ /// was requested using a base [`ExpandedKey`] from which the payer id was derived.
///
/// Useful to protect the sender's privacy.
///
/// This is not exported to bindings users as builder patterns don't map outside of move semantics.
///
/// [`InvoiceRequest::payer_id`]: crate::offers::invoice_request::InvoiceRequest::payer_id
- /// [`InvoiceRequest::metadata`]: crate::offers::invoice_request::InvoiceRequest::metadata
+ /// [`InvoiceRequest::payer_metadata`]: crate::offers::invoice_request::InvoiceRequest::payer_metadata
/// [`Bolt12Invoice::verify`]: crate::offers::invoice::Bolt12Invoice::verify
/// [`ExpandedKey`]: crate::ln::inbound_payment::ExpandedKey
pub fn request_invoice_deriving_payer_id<'a, 'b, ES: Deref, T: secp256k1::Signing>(