55// http://opensource.org/licenses/MIT>, at your option. You may not use this file except in
66// accordance with one or both of these licenses.
77
8+ use lightning:: events:: PaidBolt12Invoice ;
89use lightning:: ln:: channelmanager:: PaymentId ;
910use lightning:: ln:: msgs:: DecodeError ;
1011use lightning:: offers:: offer:: OfferId ;
@@ -293,6 +294,18 @@ impl StorableObject for PaymentDetails {
293294 }
294295 }
295296
297+ if let Some ( ref bolt12_invoice_opt) = update. bolt12_invoice {
298+ match self . kind {
299+ PaymentKind :: Bolt12Offer { ref mut bolt12_invoice, .. } => {
300+ update_if_necessary ! ( * bolt12_invoice, bolt12_invoice_opt. clone( ) ) ;
301+ } ,
302+ PaymentKind :: Bolt12Refund { ref mut bolt12_invoice, .. } => {
303+ update_if_necessary ! ( * bolt12_invoice, bolt12_invoice_opt. clone( ) ) ;
304+ } ,
305+ _ => { } ,
306+ }
307+ }
308+
296309 if updated {
297310 self . latest_update_timestamp = SystemTime :: now ( )
298311 . duration_since ( UNIX_EPOCH )
@@ -417,6 +430,8 @@ pub enum PaymentKind {
417430 ///
418431 /// This will always be `None` for payments serialized with version `v0.3.0`.
419432 quantity : Option < u64 > ,
433+ /// TODO: need to be documented
434+ bolt12_invoice : Option < PaidBolt12Invoice > ,
420435 } ,
421436 /// A [BOLT 12] 'refund' payment, i.e., a payment for a [`Refund`].
422437 ///
@@ -437,6 +452,8 @@ pub enum PaymentKind {
437452 ///
438453 /// This will always be `None` for payments serialized with version `v0.3.0`.
439454 quantity : Option < u64 > ,
455+ /// TODO: need to be documented
456+ bolt12_invoice : Option < PaidBolt12Invoice > ,
440457 } ,
441458 /// A spontaneous ("keysend") payment.
442459 Spontaneous {
@@ -471,6 +488,7 @@ impl_writeable_tlv_based_enum!(PaymentKind,
471488 ( 3 , quantity, option) ,
472489 ( 4 , secret, option) ,
473490 ( 6 , offer_id, required) ,
491+ ( 8 , bolt12_invoice, option) ,
474492 } ,
475493 ( 8 , Spontaneous ) => {
476494 ( 0 , hash, required) ,
@@ -482,6 +500,7 @@ impl_writeable_tlv_based_enum!(PaymentKind,
482500 ( 2 , preimage, option) ,
483501 ( 3 , quantity, option) ,
484502 ( 4 , secret, option) ,
503+ ( 6 , bolt12_invoice, option) ,
485504 }
486505) ;
487506
@@ -542,6 +561,7 @@ pub(crate) struct PaymentDetailsUpdate {
542561 pub direction : Option < PaymentDirection > ,
543562 pub status : Option < PaymentStatus > ,
544563 pub confirmation_status : Option < ConfirmationStatus > ,
564+ pub bolt12_invoice : Option < Option < PaidBolt12Invoice > > ,
545565}
546566
547567impl PaymentDetailsUpdate {
@@ -557,19 +577,20 @@ impl PaymentDetailsUpdate {
557577 direction : None ,
558578 status : None ,
559579 confirmation_status : None ,
580+ bolt12_invoice : None ,
560581 }
561582 }
562583}
563584
564585impl From < & PaymentDetails > for PaymentDetailsUpdate {
565586 fn from ( value : & PaymentDetails ) -> Self {
566- let ( hash, preimage, secret) = match value. kind {
567- PaymentKind :: Bolt11 { hash, preimage, secret, .. } => ( Some ( hash) , preimage, secret) ,
568- PaymentKind :: Bolt11Jit { hash, preimage, secret, .. } => ( Some ( hash) , preimage, secret) ,
569- PaymentKind :: Bolt12Offer { hash, preimage, secret, .. } => ( hash, preimage, secret) ,
570- PaymentKind :: Bolt12Refund { hash, preimage, secret, .. } => ( hash, preimage, secret) ,
571- PaymentKind :: Spontaneous { hash, preimage, .. } => ( Some ( hash) , preimage, None ) ,
572- _ => ( None , None , None ) ,
587+ let ( hash, preimage, secret, bolt12_invoice ) = match value. kind {
588+ PaymentKind :: Bolt11 { hash, preimage, secret, .. } => ( Some ( hash) , preimage, secret, None ) ,
589+ PaymentKind :: Bolt11Jit { hash, preimage, secret, .. } => ( Some ( hash) , preimage, secret, None ) ,
590+ PaymentKind :: Bolt12Offer { hash, preimage, secret, ref bolt12_invoice , .. } => ( hash, preimage, secret, Some ( bolt12_invoice ) ) ,
591+ PaymentKind :: Bolt12Refund { hash, preimage, secret, ref bolt12_invoice , .. } => ( hash, preimage, secret, Some ( bolt12_invoice ) ) ,
592+ PaymentKind :: Spontaneous { hash, preimage, .. } => ( Some ( hash) , preimage, None , None ) ,
593+ _ => ( None , None , None , None ) ,
573594 } ;
574595
575596 let confirmation_status = match value. kind {
@@ -595,6 +616,7 @@ impl From<&PaymentDetails> for PaymentDetailsUpdate {
595616 direction : Some ( value. direction ) ,
596617 status : Some ( value. status ) ,
597618 confirmation_status,
619+ bolt12_invoice : bolt12_invoice. cloned ( ) ,
598620 }
599621 }
600622}
0 commit comments