@@ -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 ;
@@ -156,6 +158,15 @@ impl PaymentDetails {
156
158
update_if_necessary ! ( self . status, status) ;
157
159
}
158
160
161
+ if let Some ( confirmation_status) = update. confirmation_status {
162
+ match self . kind {
163
+ PaymentKind :: Onchain { ref mut status, .. } => {
164
+ update_if_necessary ! ( * status, confirmation_status) ;
165
+ } ,
166
+ _ => { } ,
167
+ }
168
+ }
169
+
159
170
if updated {
160
171
self . latest_update_timestamp = SystemTime :: now ( )
161
172
. duration_since ( UNIX_EPOCH )
@@ -281,7 +292,12 @@ impl_writeable_tlv_based_enum!(PaymentStatus,
281
292
#[ derive( Clone , Debug , PartialEq , Eq ) ]
282
293
pub enum PaymentKind {
283
294
/// An on-chain payment.
284
- Onchain ,
295
+ Onchain {
296
+ /// The transaction identifier of this payment.
297
+ txid : Txid ,
298
+ /// The confirmation status of this payment.
299
+ status : ConfirmationStatus ,
300
+ } ,
285
301
/// A [BOLT 11] payment.
286
302
///
287
303
/// [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
@@ -370,7 +386,10 @@ pub enum PaymentKind {
370
386
}
371
387
372
388
impl_writeable_tlv_based_enum ! ( PaymentKind ,
373
- ( 0 , Onchain ) => { } ,
389
+ ( 0 , Onchain ) => {
390
+ ( 0 , txid, required) ,
391
+ ( 2 , status, required) ,
392
+ } ,
374
393
( 2 , Bolt11 ) => {
375
394
( 0 , hash, required) ,
376
395
( 2 , preimage, option) ,
@@ -403,6 +422,31 @@ impl_writeable_tlv_based_enum!(PaymentKind,
403
422
}
404
423
) ;
405
424
425
+ /// Represents the confirmation status of a transaction.
426
+ #[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
427
+ pub enum ConfirmationStatus {
428
+ /// The transaction is confirmed in the best chain.
429
+ Confirmed {
430
+ /// The hash of the block in which the transaction was confirmed.
431
+ block_hash : BlockHash ,
432
+ /// The height under which the block was confirmed.
433
+ height : u32 ,
434
+ /// The timestamp, in seconds since start of the UNIX epoch, when this entry was last updated.
435
+ timestamp : u64 ,
436
+ } ,
437
+ /// The transaction is unconfirmed.
438
+ Unconfirmed ,
439
+ }
440
+
441
+ impl_writeable_tlv_based_enum ! ( ConfirmationStatus ,
442
+ ( 0 , Confirmed ) => {
443
+ ( 0 , block_hash, required) ,
444
+ ( 2 , height, required) ,
445
+ ( 4 , timestamp, required) ,
446
+ } ,
447
+ ( 2 , Unconfirmed ) => { } ,
448
+ ) ;
449
+
406
450
/// Limits applying to how much fee we allow an LSP to deduct from the payment amount.
407
451
///
408
452
/// See [`LdkChannelConfig::accept_underpaying_htlcs`] for more information.
@@ -432,6 +476,7 @@ pub(crate) struct PaymentDetailsUpdate {
432
476
pub amount_msat : Option < Option < u64 > > ,
433
477
pub direction : Option < PaymentDirection > ,
434
478
pub status : Option < PaymentStatus > ,
479
+ pub confirmation_status : Option < ConfirmationStatus > ,
435
480
}
436
481
437
482
impl PaymentDetailsUpdate {
@@ -444,6 +489,7 @@ impl PaymentDetailsUpdate {
444
489
amount_msat : None ,
445
490
direction : None ,
446
491
status : None ,
492
+ confirmation_status : None ,
447
493
}
448
494
}
449
495
}
@@ -459,6 +505,11 @@ impl From<&PaymentDetails> for PaymentDetailsUpdate {
459
505
_ => ( None , None , None ) ,
460
506
} ;
461
507
508
+ let confirmation_status = match value. kind {
509
+ PaymentKind :: Onchain { status, .. } => Some ( status) ,
510
+ _ => None ,
511
+ } ;
512
+
462
513
Self {
463
514
id : value. id ,
464
515
hash : Some ( hash) ,
@@ -467,6 +518,7 @@ impl From<&PaymentDetails> for PaymentDetailsUpdate {
467
518
amount_msat : Some ( value. amount_msat ) ,
468
519
direction : Some ( value. direction ) ,
469
520
status : Some ( value. status ) ,
521
+ confirmation_status,
470
522
}
471
523
}
472
524
}
0 commit comments