@@ -10,6 +10,8 @@ use std::time::{Duration, SystemTime, UNIX_EPOCH};
1010use bitcoin:: secp256k1:: PublicKey ;
1111use bitcoin:: { BlockHash , Txid } ;
1212use lightning:: chain:: chaininterface:: TransactionType as LdkTransactionType ;
13+ #[ cfg( not( feature = "uniffi" ) ) ]
14+ use lightning:: events:: PaidBolt12Invoice ;
1315use lightning:: ln:: channelmanager:: PaymentId ;
1416use lightning:: ln:: msgs:: DecodeError ;
1517use lightning:: ln:: types:: ChannelId ;
@@ -23,6 +25,8 @@ use lightning_types::payment::{PaymentHash, PaymentPreimage, PaymentSecret};
2325use lightning_types:: string:: UntrustedString ;
2426
2527use crate :: data_store:: { StorableObject , StorableObjectId , StorableObjectUpdate } ;
28+ #[ cfg( feature = "uniffi" ) ]
29+ use crate :: ffi:: PaidBolt12Invoice ;
2630use crate :: hex_utils;
2731
2832/// Represents a payment.
@@ -251,6 +255,18 @@ impl StorableObject for PaymentDetails {
251255 update_if_necessary ! ( self . fee_paid_msat, fee_paid_msat_opt) ;
252256 }
253257
258+ if let Some ( ref bolt12_invoice_opt) = update. bolt12_invoice {
259+ match self . kind {
260+ PaymentKind :: Bolt12Offer { ref mut bolt12_invoice, .. } => {
261+ update_if_necessary ! ( * bolt12_invoice, bolt12_invoice_opt. clone( ) ) ;
262+ } ,
263+ PaymentKind :: Bolt12Refund { ref mut bolt12_invoice, .. } => {
264+ update_if_necessary ! ( * bolt12_invoice, bolt12_invoice_opt. clone( ) ) ;
265+ } ,
266+ _ => { } ,
267+ }
268+ }
269+
254270 if let Some ( skimmed_fee_msat) = update. counterparty_skimmed_fee_msat {
255271 match self . kind {
256272 PaymentKind :: Bolt11 { ref mut counterparty_skimmed_fee_msat, .. } => {
@@ -559,6 +575,15 @@ pub enum PaymentKind {
559575 ///
560576 /// This will always be `None` for payments serialized with version `v0.3.0`.
561577 quantity : Option < u64 > ,
578+ /// The BOLT 12 invoice that was paid, set once the payment succeeded.
579+ ///
580+ /// Only set for successful outbound payments, allowing to build a payer proof for the
581+ /// payment via [`Bolt12Payment::create_payer_proof`].
582+ ///
583+ /// This will always be `None` for payments serialized with version `v0.7.0` or prior.
584+ ///
585+ /// [`Bolt12Payment::create_payer_proof`]: crate::payment::Bolt12Payment::create_payer_proof
586+ bolt12_invoice : Option < PaidBolt12Invoice > ,
562587 } ,
563588 /// A [BOLT 12] 'refund' payment, i.e., a payment for a [`Refund`].
564589 ///
@@ -586,6 +611,15 @@ pub enum PaymentKind {
586611 ///
587612 /// This will always be `None` for payments serialized with version `v0.3.0`.
588613 quantity : Option < u64 > ,
614+ /// The BOLT 12 invoice that was paid, set once the payment succeeded.
615+ ///
616+ /// Only set for successful outbound payments, allowing to build a payer proof for the
617+ /// payment via [`Bolt12Payment::create_payer_proof`].
618+ ///
619+ /// This will always be `None` for payments serialized with version `v0.7.0` or prior.
620+ ///
621+ /// [`Bolt12Payment::create_payer_proof`]: crate::payment::Bolt12Payment::create_payer_proof
622+ bolt12_invoice : Option < PaidBolt12Invoice > ,
589623 } ,
590624 /// A spontaneous ("keysend") payment.
591625 Spontaneous {
@@ -625,6 +659,7 @@ impl_writeable_tlv_based_enum!(PaymentKind,
625659 ( 3 , quantity, option) ,
626660 ( 4 , secret, option) ,
627661 ( 6 , offer_id, required) ,
662+ ( 8 , bolt12_invoice, option) ,
628663 } ,
629664 ( 8 , Spontaneous ) => {
630665 ( 0 , hash, required) ,
@@ -636,6 +671,7 @@ impl_writeable_tlv_based_enum!(PaymentKind,
636671 ( 2 , preimage, option) ,
637672 ( 3 , quantity, option) ,
638673 ( 4 , secret, option) ,
674+ ( 6 , bolt12_invoice, option) ,
639675 }
640676) ;
641677
@@ -698,6 +734,7 @@ pub(crate) struct PaymentDetailsUpdate {
698734 pub direction : Option < PaymentDirection > ,
699735 pub status : Option < PaymentStatus > ,
700736 pub confirmation_status : Option < ConfirmationStatus > ,
737+ pub bolt12_invoice : Option < Option < PaidBolt12Invoice > > ,
701738 pub txid : Option < Txid > ,
702739 pub tx_type : Option < Option < TransactionType > > ,
703740}
@@ -715,6 +752,7 @@ impl PaymentDetailsUpdate {
715752 direction : None ,
716753 status : None ,
717754 confirmation_status : None ,
755+ bolt12_invoice : None ,
718756 txid : None ,
719757 tx_type : None ,
720758 }
@@ -723,12 +761,18 @@ impl PaymentDetailsUpdate {
723761
724762impl From < & PaymentDetails > for PaymentDetailsUpdate {
725763 fn from ( value : & PaymentDetails ) -> Self {
726- let ( hash, preimage, secret) = match value. kind {
727- PaymentKind :: Bolt11 { hash, preimage, secret, .. } => ( Some ( hash) , preimage, secret) ,
728- PaymentKind :: Bolt12Offer { hash, preimage, secret, .. } => ( hash, preimage, secret) ,
729- PaymentKind :: Bolt12Refund { hash, preimage, secret, .. } => ( hash, preimage, secret) ,
730- PaymentKind :: Spontaneous { hash, preimage, .. } => ( Some ( hash) , preimage, None ) ,
731- _ => ( None , None , None ) ,
764+ let ( hash, preimage, secret, bolt12_invoice) = match & value. kind {
765+ PaymentKind :: Bolt11 { hash, preimage, secret, .. } => {
766+ ( Some ( * hash) , * preimage, * secret, None )
767+ } ,
768+ PaymentKind :: Bolt12Offer { hash, preimage, secret, bolt12_invoice, .. } => {
769+ ( * hash, * preimage, * secret, Some ( bolt12_invoice. clone ( ) ) )
770+ } ,
771+ PaymentKind :: Bolt12Refund { hash, preimage, secret, bolt12_invoice, .. } => {
772+ ( * hash, * preimage, * secret, Some ( bolt12_invoice. clone ( ) ) )
773+ } ,
774+ PaymentKind :: Spontaneous { hash, preimage, .. } => ( Some ( * hash) , * preimage, None , None ) ,
775+ _ => ( None , None , None , None ) ,
732776 } ;
733777
734778 let ( confirmation_status, txid, tx_type) = match & value. kind {
@@ -738,9 +782,9 @@ impl From<&PaymentDetails> for PaymentDetailsUpdate {
738782 _ => ( None , None , None ) ,
739783 } ;
740784
741- let counterparty_skimmed_fee_msat = match value. kind {
785+ let counterparty_skimmed_fee_msat = match & value. kind {
742786 PaymentKind :: Bolt11 { counterparty_skimmed_fee_msat, .. } => {
743- Some ( counterparty_skimmed_fee_msat)
787+ Some ( * counterparty_skimmed_fee_msat)
744788 } ,
745789 _ => None ,
746790 } ;
@@ -756,6 +800,7 @@ impl From<&PaymentDetails> for PaymentDetailsUpdate {
756800 direction : Some ( value. direction ) ,
757801 status : Some ( value. status ) ,
758802 confirmation_status,
803+ bolt12_invoice,
759804 txid,
760805 tx_type,
761806 }
0 commit comments