@@ -25,6 +25,8 @@ use lightning::{
25
25
26
26
use lightning_types:: payment:: { PaymentHash , PaymentPreimage , PaymentSecret } ;
27
27
28
+ use bitcoin:: { BlockHash , Txid } ;
29
+
28
30
use std:: collections:: hash_map;
29
31
use std:: collections:: HashMap ;
30
32
use std:: ops:: Deref ;
@@ -148,6 +150,15 @@ impl PaymentDetails {
148
150
update_if_necessary ! ( self . status, status) ;
149
151
}
150
152
153
+ if let Some ( confirmation_status) = update. confirmation_status {
154
+ match self . kind {
155
+ PaymentKind :: Onchain { ref mut status, .. } => {
156
+ update_if_necessary ! ( * status, confirmation_status) ;
157
+ } ,
158
+ _ => { } ,
159
+ }
160
+ }
161
+
151
162
if updated {
152
163
self . latest_update_timestamp = SystemTime :: now ( )
153
164
. duration_since ( UNIX_EPOCH )
@@ -273,7 +284,12 @@ impl_writeable_tlv_based_enum!(PaymentStatus,
273
284
#[ derive( Clone , Debug , PartialEq , Eq ) ]
274
285
pub enum PaymentKind {
275
286
/// An on-chain payment.
276
- Onchain ,
287
+ Onchain {
288
+ /// The transaction identifier of this payment.
289
+ txid : Txid ,
290
+ /// The confirmation status of this payment.
291
+ status : ConfirmationStatus ,
292
+ } ,
277
293
/// A [BOLT 11] payment.
278
294
///
279
295
/// [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
@@ -362,7 +378,10 @@ pub enum PaymentKind {
362
378
}
363
379
364
380
impl_writeable_tlv_based_enum ! ( PaymentKind ,
365
- ( 0 , Onchain ) => { } ,
381
+ ( 0 , Onchain ) => {
382
+ ( 0 , txid, required) ,
383
+ ( 2 , status, required) ,
384
+ } ,
366
385
( 2 , Bolt11 ) => {
367
386
( 0 , hash, required) ,
368
387
( 2 , preimage, option) ,
@@ -395,6 +414,31 @@ impl_writeable_tlv_based_enum!(PaymentKind,
395
414
}
396
415
) ;
397
416
417
+ /// Represents the confirmation status of a transaction.
418
+ #[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
419
+ pub enum ConfirmationStatus {
420
+ /// The transaction is confirmed in the best chain.
421
+ Confirmed {
422
+ /// The hash of the block in which the transaction was confirmed.
423
+ block_hash : BlockHash ,
424
+ /// The height under which the block was confirmed.
425
+ height : u32 ,
426
+ /// The time at which the block was confirmed.
427
+ timestamp : u64 ,
428
+ } ,
429
+ /// The transaction is unconfirmed.
430
+ Unconfirmed ,
431
+ }
432
+
433
+ impl_writeable_tlv_based_enum ! ( ConfirmationStatus ,
434
+ ( 0 , Confirmed ) => {
435
+ ( 0 , block_hash, required) ,
436
+ ( 2 , height, required) ,
437
+ ( 4 , timestamp, required) ,
438
+ } ,
439
+ ( 2 , Unconfirmed ) => { } ,
440
+ ) ;
441
+
398
442
/// Limits applying to how much fee we allow an LSP to deduct from the payment amount.
399
443
///
400
444
/// See [`LdkChannelConfig::accept_underpaying_htlcs`] for more information.
@@ -424,6 +468,7 @@ pub(crate) struct PaymentDetailsUpdate {
424
468
pub amount_msat : Option < Option < u64 > > ,
425
469
pub direction : Option < PaymentDirection > ,
426
470
pub status : Option < PaymentStatus > ,
471
+ pub confirmation_status : Option < ConfirmationStatus > ,
427
472
}
428
473
429
474
impl PaymentDetailsUpdate {
@@ -436,6 +481,7 @@ impl PaymentDetailsUpdate {
436
481
amount_msat : None ,
437
482
direction : None ,
438
483
status : None ,
484
+ confirmation_status : None ,
439
485
}
440
486
}
441
487
}
@@ -451,6 +497,11 @@ impl From<&PaymentDetails> for PaymentDetailsUpdate {
451
497
_ => ( None , None , None ) ,
452
498
} ;
453
499
500
+ let confirmation_status = match value. kind {
501
+ PaymentKind :: Onchain { status, .. } => Some ( status) ,
502
+ _ => None ,
503
+ } ;
504
+
454
505
Self {
455
506
id : value. id ,
456
507
hash : Some ( hash) ,
@@ -459,6 +510,7 @@ impl From<&PaymentDetails> for PaymentDetailsUpdate {
459
510
amount_msat : Some ( value. amount_msat ) ,
460
511
direction : Some ( value. direction ) ,
461
512
status : Some ( value. status ) ,
513
+ confirmation_status,
462
514
}
463
515
}
464
516
}
0 commit comments