@@ -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 ;
@@ -148,6 +150,15 @@ impl PaymentDetails {
148150 update_if_necessary ! ( self . status, status) ;
149151 }
150152
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+
151162 if updated {
152163 self . latest_update_timestamp = SystemTime :: now ( )
153164 . duration_since ( UNIX_EPOCH )
@@ -273,7 +284,12 @@ impl_writeable_tlv_based_enum!(PaymentStatus,
273284#[ derive( Clone , Debug , PartialEq , Eq ) ]
274285pub enum PaymentKind {
275286 /// 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+ } ,
277293 /// A [BOLT 11] payment.
278294 ///
279295 /// [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
@@ -362,7 +378,10 @@ pub enum PaymentKind {
362378}
363379
364380impl_writeable_tlv_based_enum ! ( PaymentKind ,
365- ( 0 , Onchain ) => { } ,
381+ ( 0 , Onchain ) => {
382+ ( 0 , txid, required) ,
383+ ( 2 , status, required) ,
384+ } ,
366385 ( 2 , Bolt11 ) => {
367386 ( 0 , hash, required) ,
368387 ( 2 , preimage, option) ,
@@ -395,6 +414,31 @@ impl_writeable_tlv_based_enum!(PaymentKind,
395414 }
396415) ;
397416
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+
398442/// Limits applying to how much fee we allow an LSP to deduct from the payment amount.
399443///
400444/// See [`LdkChannelConfig::accept_underpaying_htlcs`] for more information.
@@ -424,6 +468,7 @@ pub(crate) struct PaymentDetailsUpdate {
424468 pub amount_msat : Option < Option < u64 > > ,
425469 pub direction : Option < PaymentDirection > ,
426470 pub status : Option < PaymentStatus > ,
471+ pub confirmation_status : Option < ConfirmationStatus > ,
427472}
428473
429474impl PaymentDetailsUpdate {
@@ -436,6 +481,7 @@ impl PaymentDetailsUpdate {
436481 amount_msat : None ,
437482 direction : None ,
438483 status : None ,
484+ confirmation_status : None ,
439485 }
440486 }
441487}
@@ -451,6 +497,11 @@ impl From<&PaymentDetails> for PaymentDetailsUpdate {
451497 _ => ( None , None , None ) ,
452498 } ;
453499
500+ let confirmation_status = match value. kind {
501+ PaymentKind :: Onchain { status, .. } => Some ( status) ,
502+ _ => None ,
503+ } ;
504+
454505 Self {
455506 id : value. id ,
456507 hash : Some ( hash) ,
@@ -459,6 +510,7 @@ impl From<&PaymentDetails> for PaymentDetailsUpdate {
459510 amount_msat : Some ( value. amount_msat ) ,
460511 direction : Some ( value. direction ) ,
461512 status : Some ( value. status ) ,
513+ confirmation_status,
462514 }
463515 }
464516}
0 commit comments