Skip to content

Commit fb76154

Browse files
Add PaymentContext for async payments
This context will be stored in the blinded path in upcoming commits to authenticate the payment to the recipient.
1 parent 7db5727 commit fb76154

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

lightning/src/blinded_path/payment.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use crate::types::features::BlindedHopFeatures;
2222
use crate::ln::msgs::DecodeError;
2323
use crate::ln::onion_utils;
2424
use crate::offers::invoice_request::InvoiceRequestFields;
25+
use crate::offers::nonce::Nonce;
2526
use crate::offers::offer::OfferId;
2627
use crate::routing::gossip::{NodeId, ReadOnlyNetworkGraph};
2728
use crate::sign::{EntropySource, NodeSigner, Recipient};
@@ -318,6 +319,11 @@ pub enum PaymentContext {
318319
/// [`Offer`]: crate::offers::offer::Offer
319320
Bolt12Offer(Bolt12OfferContext),
320321

322+
/// The payment was made for a static invoice requested from a BOLT 12 [`Offer`].
323+
///
324+
/// [`Offer`]: crate::offers::offer::Offer
325+
AsyncBolt12Offer(AsyncBolt12OfferContext),
326+
321327
/// The payment was made for an invoice sent for a BOLT 12 [`Refund`].
322328
///
323329
/// [`Refund`]: crate::offers::refund::Refund
@@ -351,6 +357,22 @@ pub struct Bolt12OfferContext {
351357
pub invoice_request: InvoiceRequestFields,
352358
}
353359

360+
/// The context of a payment made for a static invoice requested from a BOLT 12 [`Offer`].
361+
///
362+
/// [`Offer`]: crate::offers::offer::Offer
363+
#[derive(Clone, Debug, Eq, PartialEq)]
364+
pub struct AsyncBolt12OfferContext {
365+
/// The identifier of the [`Offer`].
366+
///
367+
/// [`Offer`]: crate::offers::offer::Offer
368+
pub offer_id: OfferId,
369+
/// The [`Nonce`] used to verify that an inbound [`InvoiceRequest`] corresponds to this static
370+
/// invoice's offer.
371+
///
372+
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
373+
pub offer_nonce: Nonce,
374+
}
375+
354376
/// The context of a payment made for an invoice sent for a BOLT 12 [`Refund`].
355377
///
356378
/// [`Refund`]: crate::offers::refund::Refund
@@ -590,6 +612,7 @@ impl_writeable_tlv_based_enum_legacy!(PaymentContext,
590612
(0, Unknown),
591613
(1, Bolt12Offer),
592614
(2, Bolt12Refund),
615+
(3, AsyncBolt12Offer),
593616
);
594617

595618
impl<'a> Writeable for PaymentContextRef<'a> {
@@ -626,6 +649,11 @@ impl_writeable_tlv_based!(Bolt12OfferContext, {
626649
(2, invoice_request, required),
627650
});
628651

652+
impl_writeable_tlv_based!(AsyncBolt12OfferContext, {
653+
(0, offer_id, required),
654+
(2, offer_nonce, required),
655+
});
656+
629657
impl_writeable_tlv_based!(Bolt12RefundContext, {});
630658

631659
#[cfg(test)]

lightning/src/events/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,15 @@ impl PaymentPurpose {
203203
payment_context: context,
204204
}
205205
},
206+
Some(PaymentContext::AsyncBolt12Offer(_context)) => {
207+
debug_assert!(false, "Receiving async payments is not yet supported");
208+
// This code will change to return Self::Bolt12OfferPayment when we add support for async
209+
// receive.
210+
PaymentPurpose::Bolt11InvoicePayment {
211+
payment_preimage,
212+
payment_secret,
213+
}
214+
},
206215
}
207216
}
208217
}

0 commit comments

Comments
 (0)