88use std:: time:: { Duration , SystemTime , UNIX_EPOCH } ;
99
1010use bitcoin:: { BlockHash , Txid } ;
11+ #[ cfg( not( feature = "uniffi" ) ) ]
12+ use lightning:: events:: PaidBolt12Invoice ;
1113use lightning:: ln:: channelmanager:: PaymentId ;
1214use lightning:: ln:: msgs:: DecodeError ;
1315use lightning:: offers:: offer:: OfferId ;
@@ -20,6 +22,8 @@ use lightning_types::payment::{PaymentHash, PaymentPreimage, PaymentSecret};
2022use lightning_types:: string:: UntrustedString ;
2123
2224use crate :: data_store:: { StorableObject , StorableObjectId , StorableObjectUpdate } ;
25+ #[ cfg( feature = "uniffi" ) ]
26+ use crate :: ffi:: PaidBolt12Invoice ;
2327use crate :: hex_utils;
2428
2529/// Represents a payment.
@@ -267,6 +271,18 @@ impl StorableObject for PaymentDetails {
267271 update_if_necessary ! ( self . fee_paid_msat, fee_paid_msat_opt) ;
268272 }
269273
274+ if let Some ( ref bolt12_invoice_opt) = update. bolt12_invoice {
275+ match self . kind {
276+ PaymentKind :: Bolt12Offer { ref mut bolt12_invoice, .. } => {
277+ update_if_necessary ! ( * bolt12_invoice, bolt12_invoice_opt. clone( ) ) ;
278+ } ,
279+ PaymentKind :: Bolt12Refund { ref mut bolt12_invoice, .. } => {
280+ update_if_necessary ! ( * bolt12_invoice, bolt12_invoice_opt. clone( ) ) ;
281+ } ,
282+ _ => { } ,
283+ }
284+ }
285+
270286 if let Some ( skimmed_fee_msat) = update. counterparty_skimmed_fee_msat {
271287 match self . kind {
272288 PaymentKind :: Bolt11Jit { ref mut counterparty_skimmed_fee_msat, .. } => {
@@ -428,6 +444,8 @@ pub enum PaymentKind {
428444 ///
429445 /// This will always be `None` for payments serialized with version `v0.3.0`.
430446 quantity : Option < u64 > ,
447+ /// The BOLT12 invoice associated with the payment, once available.
448+ bolt12_invoice : Option < PaidBolt12Invoice > ,
431449 } ,
432450 /// A [BOLT 12] 'refund' payment, i.e., a payment for a [`Refund`].
433451 ///
@@ -448,6 +466,8 @@ pub enum PaymentKind {
448466 ///
449467 /// This will always be `None` for payments serialized with version `v0.3.0`.
450468 quantity : Option < u64 > ,
469+ /// The BOLT12 invoice associated with the payment, once available.
470+ bolt12_invoice : Option < PaidBolt12Invoice > ,
451471 } ,
452472 /// A spontaneous ("keysend") payment.
453473 Spontaneous {
@@ -482,6 +502,7 @@ impl_writeable_tlv_based_enum!(PaymentKind,
482502 ( 3 , quantity, option) ,
483503 ( 4 , secret, option) ,
484504 ( 6 , offer_id, required) ,
505+ ( 8 , bolt12_invoice, option) ,
485506 } ,
486507 ( 8 , Spontaneous ) => {
487508 ( 0 , hash, required) ,
@@ -493,6 +514,7 @@ impl_writeable_tlv_based_enum!(PaymentKind,
493514 ( 2 , preimage, option) ,
494515 ( 3 , quantity, option) ,
495516 ( 4 , secret, option) ,
517+ ( 6 , bolt12_invoice, option) ,
496518 }
497519) ;
498520
@@ -555,6 +577,7 @@ pub(crate) struct PaymentDetailsUpdate {
555577 pub direction : Option < PaymentDirection > ,
556578 pub status : Option < PaymentStatus > ,
557579 pub confirmation_status : Option < ConfirmationStatus > ,
580+ pub bolt12_invoice : Option < Option < PaidBolt12Invoice > > ,
558581 pub txid : Option < Txid > ,
559582}
560583
@@ -571,30 +594,39 @@ impl PaymentDetailsUpdate {
571594 direction : None ,
572595 status : None ,
573596 confirmation_status : None ,
597+ bolt12_invoice : None ,
574598 txid : None ,
575599 }
576600 }
577601}
578602
579603impl From < & PaymentDetails > for PaymentDetailsUpdate {
580604 fn from ( value : & PaymentDetails ) -> Self {
581- let ( hash, preimage, secret) = match value. kind {
582- PaymentKind :: Bolt11 { hash, preimage, secret, .. } => ( Some ( hash) , preimage, secret) ,
583- PaymentKind :: Bolt11Jit { hash, preimage, secret, .. } => ( Some ( hash) , preimage, secret) ,
584- PaymentKind :: Bolt12Offer { hash, preimage, secret, .. } => ( hash, preimage, secret) ,
585- PaymentKind :: Bolt12Refund { hash, preimage, secret, .. } => ( hash, preimage, secret) ,
586- PaymentKind :: Spontaneous { hash, preimage, .. } => ( Some ( hash) , preimage, None ) ,
587- _ => ( None , None , None ) ,
605+ let ( hash, preimage, secret, bolt12_invoice) = match & value. kind {
606+ PaymentKind :: Bolt11 { hash, preimage, secret, .. } => {
607+ ( Some ( * hash) , * preimage, * secret, None )
608+ } ,
609+ PaymentKind :: Bolt11Jit { hash, preimage, secret, .. } => {
610+ ( Some ( * hash) , * preimage, * secret, None )
611+ } ,
612+ PaymentKind :: Bolt12Offer { hash, preimage, secret, bolt12_invoice, .. } => {
613+ ( * hash, * preimage, * secret, Some ( bolt12_invoice. clone ( ) ) )
614+ } ,
615+ PaymentKind :: Bolt12Refund { hash, preimage, secret, bolt12_invoice, .. } => {
616+ ( * hash, * preimage, * secret, Some ( bolt12_invoice. clone ( ) ) )
617+ } ,
618+ PaymentKind :: Spontaneous { hash, preimage, .. } => ( Some ( * hash) , * preimage, None , None ) ,
619+ _ => ( None , None , None , None ) ,
588620 } ;
589621
590622 let ( confirmation_status, txid) = match & value. kind {
591623 PaymentKind :: Onchain { status, txid, .. } => ( Some ( * status) , Some ( * txid) ) ,
592624 _ => ( None , None ) ,
593625 } ;
594626
595- let counterparty_skimmed_fee_msat = match value. kind {
627+ let counterparty_skimmed_fee_msat = match & value. kind {
596628 PaymentKind :: Bolt11Jit { counterparty_skimmed_fee_msat, .. } => {
597- Some ( counterparty_skimmed_fee_msat)
629+ Some ( * counterparty_skimmed_fee_msat)
598630 } ,
599631 _ => None ,
600632 } ;
@@ -610,6 +642,7 @@ impl From<&PaymentDetails> for PaymentDetailsUpdate {
610642 direction : Some ( value. direction ) ,
611643 status : Some ( value. status ) ,
612644 confirmation_status,
645+ bolt12_invoice,
613646 txid,
614647 }
615648 }
0 commit comments