@@ -19,6 +19,10 @@ use lightning::{
1919use lightning_types:: payment:: { PaymentHash , PaymentPreimage , PaymentSecret } ;
2020use lightning_types:: string:: UntrustedString ;
2121
22+ use bitcoin:: { BlockHash , Transaction , Txid } ;
23+
24+ use std:: time:: { Duration , SystemTime , UNIX_EPOCH } ;
25+
2226use crate :: data_store:: { StorableObject , StorableObjectId , StorableObjectUpdate } ;
2327use crate :: hex_utils;
2428
@@ -291,6 +295,33 @@ impl StorableObject for PaymentDetails {
291295 }
292296 }
293297
298+ if let Some ( tx) = & update. raw_tx {
299+ match self . kind {
300+ PaymentKind :: Onchain { ref mut raw_tx, .. } => {
301+ update_if_necessary ! ( * raw_tx, tx. clone( ) ) ;
302+ } ,
303+ _ => { } ,
304+ }
305+ }
306+
307+ if let Some ( attempts) = update. broadcast_attempts {
308+ match self . kind {
309+ PaymentKind :: Onchain { ref mut broadcast_attempts, .. } => {
310+ update_if_necessary ! ( * broadcast_attempts, attempts) ;
311+ } ,
312+ _ => { } ,
313+ }
314+ }
315+
316+ if let Some ( broadcast_time) = update. last_broadcast_time {
317+ match self . kind {
318+ PaymentKind :: Onchain { ref mut last_broadcast_time, .. } => {
319+ update_if_necessary ! ( * last_broadcast_time, broadcast_time) ;
320+ } ,
321+ _ => { } ,
322+ }
323+ }
324+
294325 if updated {
295326 self . latest_update_timestamp = SystemTime :: now ( )
296327 . duration_since ( UNIX_EPOCH )
@@ -351,6 +382,12 @@ pub enum PaymentKind {
351382 txid : Txid ,
352383 /// The confirmation status of this payment.
353384 status : ConfirmationStatus ,
385+ /// The raw transaction for rebroadcasting
386+ raw_tx : Option < Transaction > ,
387+ /// Last broadcast attempt timestamp (UNIX seconds)
388+ last_broadcast_time : Option < u64 > ,
389+ /// Number of broadcast attempts
390+ broadcast_attempts : Option < u32 > ,
354391 } ,
355392 /// A [BOLT 11] payment.
356393 ///
@@ -448,7 +485,10 @@ pub enum PaymentKind {
448485impl_writeable_tlv_based_enum ! ( PaymentKind ,
449486 ( 0 , Onchain ) => {
450487 ( 0 , txid, required) ,
488+ ( 1 , raw_tx, option) ,
451489 ( 2 , status, required) ,
490+ ( 3 , last_broadcast_time, option) ,
491+ ( 5 , broadcast_attempts, option) ,
452492 } ,
453493 ( 2 , Bolt11 ) => {
454494 ( 0 , hash, required) ,
@@ -540,6 +580,9 @@ pub(crate) struct PaymentDetailsUpdate {
540580 pub direction : Option < PaymentDirection > ,
541581 pub status : Option < PaymentStatus > ,
542582 pub confirmation_status : Option < ConfirmationStatus > ,
583+ pub raw_tx : Option < Option < Transaction > > ,
584+ pub last_broadcast_time : Option < Option < u64 > > ,
585+ pub broadcast_attempts : Option < Option < u32 > > ,
543586}
544587
545588impl PaymentDetailsUpdate {
@@ -555,6 +598,9 @@ impl PaymentDetailsUpdate {
555598 direction : None ,
556599 status : None ,
557600 confirmation_status : None ,
601+ raw_tx : None ,
602+ last_broadcast_time : None ,
603+ broadcast_attempts : None ,
558604 }
559605 }
560606}
@@ -570,10 +616,17 @@ impl From<&PaymentDetails> for PaymentDetailsUpdate {
570616 _ => ( None , None , None ) ,
571617 } ;
572618
573- let confirmation_status = match value. kind {
574- PaymentKind :: Onchain { status, .. } => Some ( status) ,
575- _ => None ,
576- } ;
619+ let ( confirmation_status, raw_tx, last_broadcast_time, broadcast_attempts) =
620+ match & value. kind {
621+ PaymentKind :: Onchain {
622+ status,
623+ raw_tx,
624+ last_broadcast_time,
625+ broadcast_attempts,
626+ ..
627+ } => ( Some ( * status) , raw_tx. clone ( ) , * last_broadcast_time, * broadcast_attempts) ,
628+ _ => ( None , None , None , None ) ,
629+ } ;
577630
578631 let counterparty_skimmed_fee_msat = match value. kind {
579632 PaymentKind :: Bolt11Jit { counterparty_skimmed_fee_msat, .. } => {
@@ -593,6 +646,9 @@ impl From<&PaymentDetails> for PaymentDetailsUpdate {
593646 direction : Some ( value. direction ) ,
594647 status : Some ( value. status ) ,
595648 confirmation_status,
649+ raw_tx : Some ( raw_tx) ,
650+ last_broadcast_time : Some ( last_broadcast_time) ,
651+ broadcast_attempts : Some ( broadcast_attempts) ,
596652 }
597653 }
598654}
0 commit comments