Skip to content

Commit 09ce1b5

Browse files
committed
Include Refund context in blinded payment paths
When requesting a payment for a refund, include a context in the Bolt12Invoice's blinded payment paths indicated it is for such. When the eventual payment is received, the user can use the payment hash to correlate it with the corresponding Refund.
1 parent 48d9245 commit 09ce1b5

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

lightning/src/blinded_path/payment.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ pub enum PaymentContext {
114114
///
115115
/// [`Offer`]: crate::offers::offer::Offer
116116
Bolt12Offer(Bolt12OfferContext),
117+
118+
/// The payment was made for an invoice sent for a BOLT 12 [`Refund`].
119+
///
120+
/// [`Refund`]: crate::offers::refund::Refund
121+
Bolt12Refund(Bolt12RefundContext),
117122
}
118123

119124
/// An unknown payment context.
@@ -131,6 +136,12 @@ pub struct Bolt12OfferContext {
131136
pub offer_id: OfferId,
132137
}
133138

139+
/// The context of a payment made for an invoice sent for a BOLT 12 [`Refund`].
140+
///
141+
/// [`Refund`]: crate::offers::refund::Refund
142+
#[derive(Clone, Debug, Eq, PartialEq)]
143+
pub struct Bolt12RefundContext {}
144+
134145
impl PaymentContext {
135146
pub(crate) fn unknown() -> Self {
136147
PaymentContext::Unknown(UnknownPaymentContext(()))
@@ -358,6 +369,7 @@ impl_writeable_tlv_based_enum!(PaymentContext,
358369
;
359370
(0, Unknown),
360371
(1, Bolt12Offer),
372+
(2, Bolt12Refund),
361373
);
362374

363375
impl Writeable for UnknownPaymentContext {
@@ -376,6 +388,8 @@ impl_writeable_tlv_based!(Bolt12OfferContext, {
376388
(0, offer_id, required),
377389
});
378390

391+
impl_writeable_tlv_based!(Bolt12RefundContext, {});
392+
379393
#[cfg(test)]
380394
mod tests {
381395
use bitcoin::secp256k1::PublicKey;

lightning/src/ln/channelmanager.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use bitcoin::secp256k1::Secp256k1;
3232
use bitcoin::{secp256k1, Sequence};
3333

3434
use crate::blinded_path::{BlindedPath, NodeIdLookUp};
35-
use crate::blinded_path::payment::{Bolt12OfferContext, PaymentConstraints, PaymentContext, ReceiveTlvs};
35+
use crate::blinded_path::payment::{Bolt12OfferContext, Bolt12RefundContext, PaymentConstraints, PaymentContext, ReceiveTlvs};
3636
use crate::chain;
3737
use crate::chain::{Confirm, ChannelMonitorUpdateStatus, Watch, BestBlock};
3838
use crate::chain::chaininterface::{BroadcasterInterface, ConfirmationTarget, FeeEstimator, LowerBoundedFeeEstimator};
@@ -8826,7 +8826,7 @@ where
88268826

88278827
match self.create_inbound_payment(Some(amount_msats), relative_expiry, None) {
88288828
Ok((payment_hash, payment_secret)) => {
8829-
let payment_context = PaymentContext::unknown();
8829+
let payment_context = PaymentContext::Bolt12Refund(Bolt12RefundContext {});
88308830
let payment_paths = self.create_blinded_payment_paths(
88318831
amount_msats, payment_secret, payment_context
88328832
)

0 commit comments

Comments
 (0)