@@ -12,6 +12,7 @@ use crate::ln::channelmanager::CounterpartyForwardingInfo;
12
12
use crate :: ln:: features:: BlindedHopFeatures ;
13
13
use crate :: ln:: msgs:: DecodeError ;
14
14
use crate :: offers:: invoice:: BlindedPayInfo ;
15
+ use crate :: offers:: offer:: OfferId ;
15
16
use crate :: prelude:: * ;
16
17
use crate :: util:: ser:: { HighZeroBytesDroppedBigSize , Readable , Writeable , Writer } ;
17
18
@@ -53,6 +54,8 @@ pub struct ReceiveTlvs {
53
54
pub payment_secret : PaymentSecret ,
54
55
/// Constraints for the receiver of this payment.
55
56
pub payment_constraints : PaymentConstraints ,
57
+ /// Context for the receiver of this payment.
58
+ pub payment_context : Option < PaymentContext > ,
56
59
}
57
60
58
61
/// Data to construct a [`BlindedHop`] for sending a payment over.
@@ -97,6 +100,24 @@ pub struct PaymentConstraints {
97
100
pub htlc_minimum_msat : u64 ,
98
101
}
99
102
103
+ /// The context of an inbound payment, which is included in a [`BlindedPath`] via [`ReceiveTlvs`]
104
+ /// and surfaced in [`Event::PaymentClaimable`].
105
+ ///
106
+ /// [`BlindedPath`]: crate::blinded_path::BlindedPath
107
+ /// [`Event::PaymentClaimable`]: crate::events::Event::PaymentClaimable
108
+ #[ derive( Clone , Debug ) ]
109
+ pub enum PaymentContext {
110
+ /// The payment was made for an invoice requested from a BOLT 12 [`Offer`].
111
+ ///
112
+ /// [`Offer`]: crate::offers::offer::Offer
113
+ Bolt12Offer {
114
+ /// The identifier of the [`Offer`].
115
+ ///
116
+ /// [`Offer`]: crate::offers::offer::Offer
117
+ offer_id : OfferId ,
118
+ } ,
119
+ }
120
+
100
121
impl TryFrom < CounterpartyForwardingInfo > for PaymentRelay {
101
122
type Error = ( ) ;
102
123
@@ -137,7 +158,8 @@ impl Writeable for ReceiveTlvs {
137
158
fn write < W : Writer > ( & self , w : & mut W ) -> Result < ( ) , io:: Error > {
138
159
encode_tlv_stream ! ( w, {
139
160
( 12 , self . payment_constraints, required) ,
140
- ( 65536 , self . payment_secret, required)
161
+ ( 65536 , self . payment_secret, required) ,
162
+ ( 65537 , self . payment_context, option)
141
163
} ) ;
142
164
Ok ( ( ) )
143
165
}
@@ -163,11 +185,14 @@ impl Readable for BlindedPaymentTlvs {
163
185
( 12 , payment_constraints, required) ,
164
186
( 14 , features, option) ,
165
187
( 65536 , payment_secret, option) ,
188
+ ( 65537 , payment_context, upgradable_option) ,
166
189
} ) ;
167
190
let _padding: Option < utils:: Padding > = _padding;
168
191
169
192
if let Some ( short_channel_id) = scid {
170
- if payment_secret. is_some ( ) { return Err ( DecodeError :: InvalidValue ) }
193
+ if payment_secret. is_some ( ) || payment_context. is_some ( ) {
194
+ return Err ( DecodeError :: InvalidValue )
195
+ }
171
196
Ok ( BlindedPaymentTlvs :: Forward ( ForwardTlvs {
172
197
short_channel_id,
173
198
payment_relay : payment_relay. ok_or ( DecodeError :: InvalidValue ) ?,
@@ -179,6 +204,7 @@ impl Readable for BlindedPaymentTlvs {
179
204
Ok ( BlindedPaymentTlvs :: Receive ( ReceiveTlvs {
180
205
payment_secret : payment_secret. ok_or ( DecodeError :: InvalidValue ) ?,
181
206
payment_constraints : payment_constraints. 0 . unwrap ( ) ,
207
+ payment_context : payment_context,
182
208
} ) )
183
209
}
184
210
}
@@ -309,6 +335,12 @@ impl Readable for PaymentConstraints {
309
335
}
310
336
}
311
337
338
+ impl_writeable_tlv_based_enum_upgradable ! ( PaymentContext ,
339
+ ( 0 , Bolt12Offer ) => {
340
+ ( 0 , offer_id, required) ,
341
+ } ,
342
+ ) ;
343
+
312
344
#[ cfg( test) ]
313
345
mod tests {
314
346
use bitcoin:: secp256k1:: PublicKey ;
@@ -361,6 +393,7 @@ mod tests {
361
393
max_cltv_expiry : 0 ,
362
394
htlc_minimum_msat : 1 ,
363
395
} ,
396
+ payment_context : None ,
364
397
} ;
365
398
let htlc_maximum_msat = 100_000 ;
366
399
let blinded_payinfo = super :: compute_payinfo ( & intermediate_nodes[ ..] , & recv_tlvs, htlc_maximum_msat, 12 ) . unwrap ( ) ;
@@ -379,6 +412,7 @@ mod tests {
379
412
max_cltv_expiry : 0 ,
380
413
htlc_minimum_msat : 1 ,
381
414
} ,
415
+ payment_context : None ,
382
416
} ;
383
417
let blinded_payinfo = super :: compute_payinfo ( & [ ] , & recv_tlvs, 4242 , TEST_FINAL_CLTV as u16 ) . unwrap ( ) ;
384
418
assert_eq ! ( blinded_payinfo. fee_base_msat, 0 ) ;
@@ -432,6 +466,7 @@ mod tests {
432
466
max_cltv_expiry : 0 ,
433
467
htlc_minimum_msat : 3 ,
434
468
} ,
469
+ payment_context : None ,
435
470
} ;
436
471
let htlc_maximum_msat = 100_000 ;
437
472
let blinded_payinfo = super :: compute_payinfo ( & intermediate_nodes[ ..] , & recv_tlvs, htlc_maximum_msat, TEST_FINAL_CLTV as u16 ) . unwrap ( ) ;
@@ -482,6 +517,7 @@ mod tests {
482
517
max_cltv_expiry : 0 ,
483
518
htlc_minimum_msat : 1 ,
484
519
} ,
520
+ payment_context : None ,
485
521
} ;
486
522
let htlc_minimum_msat = 3798 ;
487
523
assert ! ( super :: compute_payinfo( & intermediate_nodes[ ..] , & recv_tlvs, htlc_minimum_msat - 1 , TEST_FINAL_CLTV as u16 ) . is_err( ) ) ;
@@ -536,6 +572,7 @@ mod tests {
536
572
max_cltv_expiry : 0 ,
537
573
htlc_minimum_msat : 1 ,
538
574
} ,
575
+ payment_context : None ,
539
576
} ;
540
577
541
578
let blinded_payinfo = super :: compute_payinfo ( & intermediate_nodes[ ..] , & recv_tlvs, 10_000 , TEST_FINAL_CLTV as u16 ) . unwrap ( ) ;
0 commit comments