@@ -25,6 +25,8 @@ use lightning::{
2525
2626use lightning_types:: payment:: { PaymentHash , PaymentPreimage , PaymentSecret } ;
2727
28+ use bitcoin:: { BlockHash , Txid } ;
29+
2830use std:: collections:: hash_map;
2931use std:: collections:: HashMap ;
3032use std:: ops:: Deref ;
@@ -156,6 +158,15 @@ impl PaymentDetails {
156158 update_if_necessary ! ( self . status, status) ;
157159 }
158160
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+
159170 if updated {
160171 self . latest_update_timestamp = SystemTime :: now ( )
161172 . duration_since ( UNIX_EPOCH )
@@ -281,7 +292,12 @@ impl_writeable_tlv_based_enum!(PaymentStatus,
281292#[ derive( Clone , Debug , PartialEq , Eq ) ]
282293pub enum PaymentKind {
283294 /// 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+ } ,
285301 /// A [BOLT 11] payment.
286302 ///
287303 /// [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
@@ -370,7 +386,10 @@ pub enum PaymentKind {
370386}
371387
372388impl_writeable_tlv_based_enum ! ( PaymentKind ,
373- ( 0 , Onchain ) => { } ,
389+ ( 0 , Onchain ) => {
390+ ( 0 , txid, required) ,
391+ ( 2 , status, required) ,
392+ } ,
374393 ( 2 , Bolt11 ) => {
375394 ( 0 , hash, required) ,
376395 ( 2 , preimage, option) ,
@@ -403,6 +422,31 @@ impl_writeable_tlv_based_enum!(PaymentKind,
403422 }
404423) ;
405424
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 time at which the block was confirmed.
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+
406450/// Limits applying to how much fee we allow an LSP to deduct from the payment amount.
407451///
408452/// See [`LdkChannelConfig::accept_underpaying_htlcs`] for more information.
@@ -432,6 +476,7 @@ pub(crate) struct PaymentDetailsUpdate {
432476 pub amount_msat : Option < Option < u64 > > ,
433477 pub direction : Option < PaymentDirection > ,
434478 pub status : Option < PaymentStatus > ,
479+ pub confirmation_status : Option < ConfirmationStatus > ,
435480}
436481
437482impl PaymentDetailsUpdate {
@@ -444,6 +489,7 @@ impl PaymentDetailsUpdate {
444489 amount_msat : None ,
445490 direction : None ,
446491 status : None ,
492+ confirmation_status : None ,
447493 }
448494 }
449495}
@@ -459,6 +505,11 @@ impl From<&PaymentDetails> for PaymentDetailsUpdate {
459505 _ => ( None , None , None ) ,
460506 } ;
461507
508+ let confirmation_status = match value. kind {
509+ PaymentKind :: Onchain { status, .. } => Some ( status) ,
510+ _ => None ,
511+ } ;
512+
462513 Self {
463514 id : value. id ,
464515 hash : Some ( hash) ,
@@ -467,6 +518,7 @@ impl From<&PaymentDetails> for PaymentDetailsUpdate {
467518 amount_msat : Some ( value. amount_msat ) ,
468519 direction : Some ( value. direction ) ,
469520 status : Some ( value. status ) ,
521+ confirmation_status,
470522 }
471523 }
472524}
0 commit comments