@@ -53,6 +53,8 @@ pub struct ReceiveTlvs {
53
53
pub payment_secret : PaymentSecret ,
54
54
/// Constraints for the receiver of this payment.
55
55
pub payment_constraints : PaymentConstraints ,
56
+ /// Context for the receiver of this payment.
57
+ pub payment_context : PaymentContext ,
56
58
}
57
59
58
60
/// Data to construct a [`BlindedHop`] for sending a payment over.
@@ -97,6 +99,27 @@ pub struct PaymentConstraints {
97
99
pub htlc_minimum_msat : u64 ,
98
100
}
99
101
102
+ /// The context of an inbound payment, which is included in a [`BlindedPath`] via [`ReceiveTlvs`]
103
+ /// and surfaced in [`PaymentPurpose`].
104
+ ///
105
+ /// [`BlindedPath`]: crate::blinded_path::BlindedPath
106
+ /// [`PaymentPurpose`]: crate::events::PaymentPurpose
107
+ #[ derive( Clone , Debug ) ]
108
+ pub enum PaymentContext {
109
+ /// The payment context was unknown.
110
+ Unknown ( UnknownPaymentContext ) ,
111
+ }
112
+
113
+ /// An unknown payment context.
114
+ #[ derive( Clone , Debug ) ]
115
+ pub struct UnknownPaymentContext ( ( ) ) ;
116
+
117
+ impl PaymentContext {
118
+ pub ( crate ) fn unknown ( ) -> Self {
119
+ PaymentContext :: Unknown ( UnknownPaymentContext ( ( ) ) )
120
+ }
121
+ }
122
+
100
123
impl TryFrom < CounterpartyForwardingInfo > for PaymentRelay {
101
124
type Error = ( ) ;
102
125
@@ -137,7 +160,8 @@ impl Writeable for ReceiveTlvs {
137
160
fn write < W : Writer > ( & self , w : & mut W ) -> Result < ( ) , io:: Error > {
138
161
encode_tlv_stream ! ( w, {
139
162
( 12 , self . payment_constraints, required) ,
140
- ( 65536 , self . payment_secret, required)
163
+ ( 65536 , self . payment_secret, required) ,
164
+ ( 65537 , self . payment_context, required)
141
165
} ) ;
142
166
Ok ( ( ) )
143
167
}
@@ -163,11 +187,14 @@ impl Readable for BlindedPaymentTlvs {
163
187
( 12 , payment_constraints, required) ,
164
188
( 14 , features, option) ,
165
189
( 65536 , payment_secret, option) ,
190
+ ( 65537 , payment_context, ( default_value, PaymentContext :: unknown( ) ) ) ,
166
191
} ) ;
167
192
let _padding: Option < utils:: Padding > = _padding;
168
193
169
194
if let Some ( short_channel_id) = scid {
170
- if payment_secret. is_some ( ) { return Err ( DecodeError :: InvalidValue ) }
195
+ if payment_secret. is_some ( ) {
196
+ return Err ( DecodeError :: InvalidValue )
197
+ }
171
198
Ok ( BlindedPaymentTlvs :: Forward ( ForwardTlvs {
172
199
short_channel_id,
173
200
payment_relay : payment_relay. ok_or ( DecodeError :: InvalidValue ) ?,
@@ -179,6 +206,7 @@ impl Readable for BlindedPaymentTlvs {
179
206
Ok ( BlindedPaymentTlvs :: Receive ( ReceiveTlvs {
180
207
payment_secret : payment_secret. ok_or ( DecodeError :: InvalidValue ) ?,
181
208
payment_constraints : payment_constraints. 0 . unwrap ( ) ,
209
+ payment_context : payment_context. 0 . unwrap ( ) ,
182
210
} ) )
183
211
}
184
212
}
@@ -309,10 +337,27 @@ impl Readable for PaymentConstraints {
309
337
}
310
338
}
311
339
340
+ impl_writeable_tlv_based_enum ! ( PaymentContext ,
341
+ ;
342
+ ( 0 , Unknown ) ,
343
+ ) ;
344
+
345
+ impl Writeable for UnknownPaymentContext {
346
+ fn write < W : Writer > ( & self , _w : & mut W ) -> Result < ( ) , io:: Error > {
347
+ Ok ( ( ) )
348
+ }
349
+ }
350
+
351
+ impl Readable for UnknownPaymentContext {
352
+ fn read < R : io:: Read > ( _r : & mut R ) -> Result < Self , DecodeError > {
353
+ Ok ( UnknownPaymentContext ( ( ) ) )
354
+ }
355
+ }
356
+
312
357
#[ cfg( test) ]
313
358
mod tests {
314
359
use bitcoin:: secp256k1:: PublicKey ;
315
- use crate :: blinded_path:: payment:: { ForwardNode , ForwardTlvs , ReceiveTlvs , PaymentConstraints , PaymentRelay } ;
360
+ use crate :: blinded_path:: payment:: { ForwardNode , ForwardTlvs , ReceiveTlvs , PaymentConstraints , PaymentContext , PaymentRelay } ;
316
361
use crate :: ln:: PaymentSecret ;
317
362
use crate :: ln:: features:: BlindedHopFeatures ;
318
363
use crate :: ln:: functional_test_utils:: TEST_FINAL_CLTV ;
@@ -361,6 +406,7 @@ mod tests {
361
406
max_cltv_expiry : 0 ,
362
407
htlc_minimum_msat : 1 ,
363
408
} ,
409
+ payment_context : PaymentContext :: unknown ( ) ,
364
410
} ;
365
411
let htlc_maximum_msat = 100_000 ;
366
412
let blinded_payinfo = super :: compute_payinfo ( & intermediate_nodes[ ..] , & recv_tlvs, htlc_maximum_msat, 12 ) . unwrap ( ) ;
@@ -379,6 +425,7 @@ mod tests {
379
425
max_cltv_expiry : 0 ,
380
426
htlc_minimum_msat : 1 ,
381
427
} ,
428
+ payment_context : PaymentContext :: unknown ( ) ,
382
429
} ;
383
430
let blinded_payinfo = super :: compute_payinfo ( & [ ] , & recv_tlvs, 4242 , TEST_FINAL_CLTV as u16 ) . unwrap ( ) ;
384
431
assert_eq ! ( blinded_payinfo. fee_base_msat, 0 ) ;
@@ -432,6 +479,7 @@ mod tests {
432
479
max_cltv_expiry : 0 ,
433
480
htlc_minimum_msat : 3 ,
434
481
} ,
482
+ payment_context : PaymentContext :: unknown ( ) ,
435
483
} ;
436
484
let htlc_maximum_msat = 100_000 ;
437
485
let blinded_payinfo = super :: compute_payinfo ( & intermediate_nodes[ ..] , & recv_tlvs, htlc_maximum_msat, TEST_FINAL_CLTV as u16 ) . unwrap ( ) ;
@@ -482,6 +530,7 @@ mod tests {
482
530
max_cltv_expiry : 0 ,
483
531
htlc_minimum_msat : 1 ,
484
532
} ,
533
+ payment_context : PaymentContext :: unknown ( ) ,
485
534
} ;
486
535
let htlc_minimum_msat = 3798 ;
487
536
assert ! ( super :: compute_payinfo( & intermediate_nodes[ ..] , & recv_tlvs, htlc_minimum_msat - 1 , TEST_FINAL_CLTV as u16 ) . is_err( ) ) ;
@@ -536,6 +585,7 @@ mod tests {
536
585
max_cltv_expiry : 0 ,
537
586
htlc_minimum_msat : 1 ,
538
587
} ,
588
+ payment_context : PaymentContext :: unknown ( ) ,
539
589
} ;
540
590
541
591
let blinded_payinfo = super :: compute_payinfo ( & intermediate_nodes[ ..] , & recv_tlvs, 10_000 , TEST_FINAL_CLTV as u16 ) . unwrap ( ) ;
0 commit comments