@@ -586,6 +586,81 @@ impl StorableObjectUpdate<PaymentDetails> for PaymentDetailsUpdate {
586586 }
587587}
588588
589+ /// Represents a pending payment
590+ #[ derive( Clone , Debug , PartialEq , Eq ) ]
591+ pub ( crate ) struct PendingPaymentDetails {
592+ /// The full payment details
593+ pub details : PaymentDetails ,
594+ /// Transaction IDs that have replaced or conflict with this payment.
595+ pub conflicting_txids : Vec < Txid > ,
596+ }
597+
598+ impl PendingPaymentDetails {
599+ pub ( crate ) fn new ( details : PaymentDetails , conflicting_txids : Vec < Txid > ) -> Self {
600+ Self { details, conflicting_txids }
601+ }
602+ }
603+
604+ impl_writeable_tlv_based ! ( PendingPaymentDetails , {
605+ ( 0 , details, required) ,
606+ ( 2 , conflicting_txids, optional_vec) ,
607+ } ) ;
608+
609+ #[ derive( Clone , Debug , PartialEq , Eq ) ]
610+ pub ( crate ) struct PendingPaymentDetailsUpdate {
611+ pub id : PaymentId ,
612+ pub payment_update : Option < PaymentDetailsUpdate > ,
613+ pub conflicting_txids : Option < Vec < Txid > > ,
614+ }
615+
616+ impl StorableObject for PendingPaymentDetails {
617+ type Id = PaymentId ;
618+ type Update = PendingPaymentDetailsUpdate ;
619+
620+ fn id ( & self ) -> Self :: Id {
621+ self . details . id
622+ }
623+
624+ fn update ( & mut self , update : Self :: Update ) -> bool {
625+ let mut updated = false ;
626+
627+ // Update the underlying payment details if present
628+ if let Some ( payment_update) = update. payment_update {
629+ updated |= self . details . update ( payment_update) ;
630+ }
631+
632+ if let Some ( new_conflicting_txids) = update. conflicting_txids {
633+ if self . conflicting_txids != new_conflicting_txids {
634+ self . conflicting_txids = new_conflicting_txids;
635+ updated = true ;
636+ }
637+ }
638+
639+ updated
640+ }
641+
642+ fn to_update ( & self ) -> Self :: Update {
643+ self . into ( )
644+ }
645+ }
646+
647+ impl StorableObjectUpdate < PendingPaymentDetails > for PendingPaymentDetailsUpdate {
648+ fn id ( & self ) -> <PendingPaymentDetails as StorableObject >:: Id {
649+ self . id
650+ }
651+ }
652+
653+ impl From < & PendingPaymentDetails > for PendingPaymentDetailsUpdate {
654+ fn from ( value : & PendingPaymentDetails ) -> Self {
655+ let conflicting_txids = if value. conflicting_txids . is_empty ( ) {
656+ None
657+ } else {
658+ Some ( value. conflicting_txids . clone ( ) )
659+ } ;
660+ Self { id : value. id ( ) , payment_update : Some ( value. details . to_update ( ) ) , conflicting_txids }
661+ }
662+ }
663+
589664#[ cfg( test) ]
590665mod tests {
591666 use lightning:: util:: ser:: { Readable , Writeable } ;
0 commit comments