Skip to content

Commit 8f4b944

Browse files
Add payer_offer() accessor method for invoice requests
Implements a public accessor method to retrieve the payer_offer field from invoice requests. This completes the interface for accessing the invreq_payer_offer experimental TLV field that was added in commit 61799bf. Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
1 parent 5693660 commit 8f4b944

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

lightning/src/ln/offers_tests.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ use crate::types::features::Bolt12InvoiceFeatures;
5555
use crate::ln::functional_test_utils::*;
5656
use crate::ln::msgs::{BaseMessageHandler, ChannelMessageHandler, Init, NodeAnnouncement, OnionMessage, OnionMessageHandler, RoutingMessageHandler, SocketAddress, UnsignedGossipMessage, UnsignedNodeAnnouncement};
5757
use crate::ln::outbound_payment::IDEMPOTENCY_TIMEOUT_TICKS;
58-
use crate::offers::invoice::Bolt12Invoice;
58+
use crate::offers::invoice::{self, Bolt12Invoice};
5959
use crate::offers::invoice_error::InvoiceError;
6060
use crate::offers::invoice_request::{InvoiceRequest, InvoiceRequestFields, InvoiceRequestVerifiedFromOffer};
6161
use crate::offers::nonce::Nonce;
@@ -2574,6 +2574,7 @@ fn pay_offer_and_add_contacts_info_blip42() {
25742574
// Now we check that there are the contact secret and the
25752575
// contact secret is the same that we inject by bob.
25762576
assert!(invoice_request.contact_secret().is_some());
2577+
assert!(invoice_request.payer_offer().is_some());
25772578
// TODO: we should check also if the contact secret is the same that we inject by bob.
25782579

25792580
let onion_message = alice.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();

lightning/src/offers/invoice_request.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ macro_rules! invoice_request_builder_methods { (
187187
InvoiceRequestContentsWithoutPayerSigningPubkey {
188188
payer: PayerContents(metadata), offer, chain: None, amount_msats: None,
189189
features: InvoiceRequestFeatures::empty(), quantity: None, payer_note: None,
190-
offer_from_hrn: None, invreq_contact_secret: None,
190+
offer_from_hrn: None, invreq_contact_secret: None, invreq_payer_offer: None,
191191
#[cfg(test)]
192192
experimental_bar: None,
193193
}
@@ -704,6 +704,7 @@ pub(super) struct InvoiceRequestContentsWithoutPayerSigningPubkey {
704704
payer_note: Option<String>,
705705
offer_from_hrn: Option<HumanReadableName>,
706706
invreq_contact_secret: Option<Vec<u8>>,
707+
invreq_payer_offer: Option<Vec<u8>>,
707708
#[cfg(test)]
708709
experimental_bar: Option<u64>,
709710
}
@@ -770,6 +771,11 @@ macro_rules! invoice_request_accessors { ($self: ident, $contents: expr) => {
770771
pub fn contact_secret(&$self) -> Option<&[u8]> {
771772
$contents.contact_secret()
772773
}
774+
775+
/// Returns the payer offer if present in the invoice request.
776+
pub fn payer_offer(&$self) -> Option<&[u8]> {
777+
$contents.payer_offer()
778+
}
773779
} }
774780

775781
impl UnsignedInvoiceRequest {
@@ -1206,6 +1212,10 @@ impl InvoiceRequestContents {
12061212
self.inner.invreq_contact_secret.as_ref().map(|secret| secret.as_slice())
12071213
}
12081214

1215+
pub(super) fn payer_offer(&self) -> Option<&[u8]> {
1216+
self.inner.invreq_payer_offer.as_ref().map(|offer| offer.as_slice())
1217+
}
1218+
12091219
pub(super) fn as_tlv_stream(&self) -> PartialInvoiceRequestTlvStreamRef<'_> {
12101220
let (payer, offer, mut invoice_request, experimental_offer, experimental_invoice_request) =
12111221
self.inner.as_tlv_stream();
@@ -1253,7 +1263,7 @@ impl InvoiceRequestContentsWithoutPayerSigningPubkey {
12531263

12541264
let experimental_invoice_request = ExperimentalInvoiceRequestTlvStreamRef {
12551265
invreq_contact_secret: self.invreq_contact_secret.as_ref(),
1256-
invreq_payer_offer: None,
1266+
invreq_payer_offer: self.invreq_payer_offer.as_ref(),
12571267
invreq_payer_bip_353_name: None,
12581268
#[cfg(test)]
12591269
experimental_bar: self.experimental_bar,
@@ -1494,7 +1504,7 @@ impl TryFrom<PartialInvoiceRequestTlvStream> for InvoiceRequestContents {
14941504
experimental_offer_tlv_stream,
14951505
ExperimentalInvoiceRequestTlvStream {
14961506
invreq_contact_secret,
1497-
invreq_payer_offer: _,
1507+
invreq_payer_offer,
14981508
invreq_payer_bip_353_name: _,
14991509
#[cfg(test)]
15001510
experimental_bar,
@@ -1540,6 +1550,7 @@ impl TryFrom<PartialInvoiceRequestTlvStream> for InvoiceRequestContents {
15401550
payer_note,
15411551
offer_from_hrn,
15421552
invreq_contact_secret,
1553+
invreq_payer_offer,
15431554
#[cfg(test)]
15441555
experimental_bar,
15451556
},

0 commit comments

Comments
 (0)