@@ -9,6 +9,7 @@ use crate::Error;
9
9
use lightning:: ln:: channelmanager:: PaymentId ;
10
10
use lightning:: ln:: msgs:: DecodeError ;
11
11
use lightning:: ln:: { PaymentHash , PaymentPreimage , PaymentSecret } ;
12
+ use lightning:: offers:: offer:: OfferId ;
12
13
use lightning:: util:: ser:: { Readable , Writeable } ;
13
14
use lightning:: {
14
15
_init_and_read_len_prefixed_tlv_fields, impl_writeable_tlv_based,
@@ -145,7 +146,6 @@ pub enum PaymentKind {
145
146
/// A [BOLT 11] payment.
146
147
///
147
148
/// [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
148
- // TODO: Bolt11 { invoice: Option<Bolt11Invoice> },
149
149
Bolt11 {
150
150
/// The payment hash, i.e., the hash of the `preimage`.
151
151
hash : PaymentHash ,
@@ -158,7 +158,6 @@ pub enum PaymentKind {
158
158
///
159
159
/// [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
160
160
/// [LSPS 2]: https://github.com/BitcoinAndLightningLayerSpecs/lsp/blob/main/LSPS2/README.md
161
- // TODO: Bolt11Jit { invoice: Option<Bolt11Invoice> },
162
161
Bolt11Jit {
163
162
/// The payment hash, i.e., the hash of the `preimage`.
164
163
hash : PaymentHash ,
@@ -176,6 +175,32 @@ pub enum PaymentKind {
176
175
/// [`LdkChannelConfig::accept_underpaying_htlcs`]: lightning::util::config::ChannelConfig::accept_underpaying_htlcs
177
176
lsp_fee_limits : LSPFeeLimits ,
178
177
} ,
178
+ /// A [BOLT 12] 'offer' payment, i.e., a payment for an [`Offer`].
179
+ ///
180
+ /// [BOLT 12]: https://github.com/lightning/bolts/blob/master/12-offer-encoding.md
181
+ /// [`Offer`]: crate::lightning::offers::offer::Offer
182
+ Bolt12Offer {
183
+ /// The payment hash, i.e., the hash of the `preimage`.
184
+ hash : Option < PaymentHash > ,
185
+ /// The pre-image used by the payment.
186
+ preimage : Option < PaymentPreimage > ,
187
+ /// The secret used by the payment.
188
+ secret : Option < PaymentSecret > ,
189
+ /// The ID of the offer this payment is for.
190
+ offer_id : OfferId ,
191
+ } ,
192
+ /// A [BOLT 12] 'refund' payment, i.e., a payment for a [`Refund`].
193
+ ///
194
+ /// [BOLT 12]: https://github.com/lightning/bolts/blob/master/12-offer-encoding.md
195
+ /// [`Refund`]: lightning::offers::refund::Refund
196
+ Bolt12Refund {
197
+ /// The payment hash, i.e., the hash of the `preimage`.
198
+ hash : Option < PaymentHash > ,
199
+ /// The pre-image used by the payment.
200
+ preimage : Option < PaymentPreimage > ,
201
+ /// The secret used by the payment.
202
+ secret : Option < PaymentSecret > ,
203
+ } ,
179
204
/// A spontaneous ("keysend") payment.
180
205
Spontaneous {
181
206
/// The payment hash, i.e., the hash of the `preimage`.
@@ -198,9 +223,20 @@ impl_writeable_tlv_based_enum!(PaymentKind,
198
223
( 4 , secret, option) ,
199
224
( 6 , lsp_fee_limits, required) ,
200
225
} ,
226
+ ( 6 , Bolt12Offer ) => {
227
+ ( 0 , hash, option) ,
228
+ ( 2 , preimage, option) ,
229
+ ( 4 , secret, option) ,
230
+ ( 6 , offer_id, required) ,
231
+ } ,
201
232
( 8 , Spontaneous ) => {
202
233
( 0 , hash, required) ,
203
234
( 2 , preimage, option) ,
235
+ } ,
236
+ ( 10 , Bolt12Refund ) => {
237
+ ( 0 , hash, option) ,
238
+ ( 2 , preimage, option) ,
239
+ ( 4 , secret, option) ,
204
240
} ;
205
241
) ;
206
242
@@ -227,6 +263,7 @@ impl_writeable_tlv_based!(LSPFeeLimits, {
227
263
#[ derive( Clone , Debug , PartialEq , Eq ) ]
228
264
pub ( crate ) struct PaymentDetailsUpdate {
229
265
pub id : PaymentId ,
266
+ pub hash : Option < Option < PaymentHash > > ,
230
267
pub preimage : Option < Option < PaymentPreimage > > ,
231
268
pub secret : Option < Option < PaymentSecret > > ,
232
269
pub amount_msat : Option < Option < u64 > > ,
@@ -236,7 +273,15 @@ pub(crate) struct PaymentDetailsUpdate {
236
273
237
274
impl PaymentDetailsUpdate {
238
275
pub fn new ( id : PaymentId ) -> Self {
239
- Self { id, preimage : None , secret : None , amount_msat : None , direction : None , status : None }
276
+ Self {
277
+ id,
278
+ hash : None ,
279
+ preimage : None ,
280
+ secret : None ,
281
+ amount_msat : None ,
282
+ direction : None ,
283
+ status : None ,
284
+ }
240
285
}
241
286
}
242
287
@@ -299,10 +344,29 @@ where
299
344
let mut locked_payments = self . payments . lock ( ) . unwrap ( ) ;
300
345
301
346
if let Some ( payment) = locked_payments. get_mut ( & update. id ) {
347
+ if let Some ( hash_opt) = update. hash {
348
+ match payment. kind {
349
+ PaymentKind :: Bolt12Offer { ref mut hash, .. } => {
350
+ debug_assert_eq ! ( payment. direction, PaymentDirection :: Outbound ,
351
+ "We should only ever override payment hash for outbound BOLT 12 payments" ) ;
352
+ * hash = hash_opt
353
+ } ,
354
+ PaymentKind :: Bolt12Refund { ref mut hash, .. } => {
355
+ debug_assert_eq ! ( payment. direction, PaymentDirection :: Outbound ,
356
+ "We should only ever override payment hash for outbound BOLT 12 payments" ) ;
357
+ * hash = hash_opt
358
+ } ,
359
+ _ => {
360
+ // We can omit updating the hash for BOLT11 payments as the payment has will always be known from the beginning.
361
+ } ,
362
+ }
363
+ }
302
364
if let Some ( preimage_opt) = update. preimage {
303
365
match payment. kind {
304
366
PaymentKind :: Bolt11 { ref mut preimage, .. } => * preimage = preimage_opt,
305
367
PaymentKind :: Bolt11Jit { ref mut preimage, .. } => * preimage = preimage_opt,
368
+ PaymentKind :: Bolt12Offer { ref mut preimage, .. } => * preimage = preimage_opt,
369
+ PaymentKind :: Bolt12Refund { ref mut preimage, .. } => * preimage = preimage_opt,
306
370
PaymentKind :: Spontaneous { ref mut preimage, .. } => * preimage = preimage_opt,
307
371
_ => { } ,
308
372
}
@@ -312,6 +376,8 @@ where
312
376
match payment. kind {
313
377
PaymentKind :: Bolt11 { ref mut secret, .. } => * secret = secret_opt,
314
378
PaymentKind :: Bolt11Jit { ref mut secret, .. } => * secret = secret_opt,
379
+ PaymentKind :: Bolt12Offer { ref mut secret, .. } => * secret = secret_opt,
380
+ PaymentKind :: Bolt12Refund { ref mut secret, .. } => * secret = secret_opt,
315
381
_ => { } ,
316
382
}
317
383
}
@@ -327,7 +393,6 @@ where
327
393
self . persist_info ( & update. id , payment) ?;
328
394
updated = true ;
329
395
}
330
-
331
396
Ok ( updated)
332
397
}
333
398
0 commit comments