@@ -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,30 @@ 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 in response to an offer.
179
+ ///
180
+ /// [BOLT 12]: https://github.com/lightning/bolts/blob/master/12-offer-encoding.md
181
+ Bolt12Offer {
182
+ /// The payment hash, i.e., the hash of the `preimage`.
183
+ hash : Option < PaymentHash > ,
184
+ /// The pre-image used by the payment.
185
+ preimage : Option < PaymentPreimage > ,
186
+ /// The secret used by the payment.
187
+ secret : Option < PaymentSecret > ,
188
+ /// The ID of the offer this payment is for.
189
+ offer_id : OfferId ,
190
+ } ,
191
+ /// A [BOLT 12] 'refund' payment, i.e., a payment without a prior offer.
192
+ ///
193
+ /// [BOLT 12]: https://github.com/lightning/bolts/blob/master/12-offer-encoding.md
194
+ Bolt12Refund {
195
+ /// The payment hash, i.e., the hash of the `preimage`.
196
+ hash : Option < PaymentHash > ,
197
+ /// The pre-image used by the payment.
198
+ preimage : Option < PaymentPreimage > ,
199
+ /// The secret used by the payment.
200
+ secret : Option < PaymentSecret > ,
201
+ } ,
179
202
/// A spontaneous ("keysend") payment.
180
203
Spontaneous {
181
204
/// The payment hash, i.e., the hash of the `preimage`.
@@ -198,9 +221,20 @@ impl_writeable_tlv_based_enum!(PaymentKind,
198
221
( 4 , secret, option) ,
199
222
( 6 , lsp_fee_limits, required) ,
200
223
} ,
224
+ ( 6 , Bolt12Offer ) => {
225
+ ( 0 , hash, option) ,
226
+ ( 2 , preimage, option) ,
227
+ ( 4 , secret, option) ,
228
+ ( 6 , offer_id, required) ,
229
+ } ,
201
230
( 8 , Spontaneous ) => {
202
231
( 0 , hash, required) ,
203
232
( 2 , preimage, option) ,
233
+ } ,
234
+ ( 10 , Bolt12Refund ) => {
235
+ ( 0 , hash, option) ,
236
+ ( 2 , preimage, option) ,
237
+ ( 4 , secret, option) ,
204
238
} ;
205
239
) ;
206
240
@@ -227,6 +261,7 @@ impl_writeable_tlv_based!(LSPFeeLimits, {
227
261
#[ derive( Clone , Debug , PartialEq , Eq ) ]
228
262
pub ( crate ) struct PaymentDetailsUpdate {
229
263
pub id : PaymentId ,
264
+ pub hash : Option < Option < PaymentHash > > ,
230
265
pub preimage : Option < Option < PaymentPreimage > > ,
231
266
pub secret : Option < Option < PaymentSecret > > ,
232
267
pub amount_msat : Option < Option < u64 > > ,
@@ -236,7 +271,15 @@ pub(crate) struct PaymentDetailsUpdate {
236
271
237
272
impl PaymentDetailsUpdate {
238
273
pub fn new ( id : PaymentId ) -> Self {
239
- Self { id, preimage : None , secret : None , amount_msat : None , direction : None , status : None }
274
+ Self {
275
+ id,
276
+ hash : None ,
277
+ preimage : None ,
278
+ secret : None ,
279
+ amount_msat : None ,
280
+ direction : None ,
281
+ status : None ,
282
+ }
240
283
}
241
284
}
242
285
@@ -299,10 +342,29 @@ where
299
342
let mut locked_payments = self . payments . lock ( ) . unwrap ( ) ;
300
343
301
344
if let Some ( payment) = locked_payments. get_mut ( & update. id ) {
345
+ if let Some ( hash_opt) = update. hash {
346
+ match payment. kind {
347
+ PaymentKind :: Bolt12Offer { ref mut hash, .. } => {
348
+ debug_assert_eq ! ( payment. direction, PaymentDirection :: Outbound ,
349
+ "We should only ever override payment hash for outbound BOLT 12 payments" ) ;
350
+ * hash = hash_opt
351
+ } ,
352
+ PaymentKind :: Bolt12Refund { ref mut hash, .. } => {
353
+ debug_assert_eq ! ( payment. direction, PaymentDirection :: Outbound ,
354
+ "We should only ever override payment hash for outbound BOLT 12 payments" ) ;
355
+ * hash = hash_opt
356
+ } ,
357
+ _ => {
358
+ // We can omit updating the hash for BOLT11 payments as the payment has will always be known from the beginning.
359
+ } ,
360
+ }
361
+ }
302
362
if let Some ( preimage_opt) = update. preimage {
303
363
match payment. kind {
304
364
PaymentKind :: Bolt11 { ref mut preimage, .. } => * preimage = preimage_opt,
305
365
PaymentKind :: Bolt11Jit { ref mut preimage, .. } => * preimage = preimage_opt,
366
+ PaymentKind :: Bolt12Offer { ref mut preimage, .. } => * preimage = preimage_opt,
367
+ PaymentKind :: Bolt12Refund { ref mut preimage, .. } => * preimage = preimage_opt,
306
368
PaymentKind :: Spontaneous { ref mut preimage, .. } => * preimage = preimage_opt,
307
369
_ => { } ,
308
370
}
@@ -312,6 +374,8 @@ where
312
374
match payment. kind {
313
375
PaymentKind :: Bolt11 { ref mut secret, .. } => * secret = secret_opt,
314
376
PaymentKind :: Bolt11Jit { ref mut secret, .. } => * secret = secret_opt,
377
+ PaymentKind :: Bolt12Offer { ref mut secret, .. } => * secret = secret_opt,
378
+ PaymentKind :: Bolt12Refund { ref mut secret, .. } => * secret = secret_opt,
315
379
_ => { } ,
316
380
}
317
381
}
@@ -327,7 +391,6 @@ where
327
391
self . persist_info ( & update. id , payment) ?;
328
392
updated = true ;
329
393
}
330
-
331
394
Ok ( updated)
332
395
}
333
396
0 commit comments