@@ -433,15 +433,7 @@ where
433433 onion_fields : _,
434434 counterparty_skimmed_fee_msat,
435435 } => {
436- let payment_id = match purpose {
437- PaymentPurpose :: Bolt11InvoicePayment { .. } => PaymentId ( payment_hash. 0 ) ,
438- PaymentPurpose :: Bolt12OfferPayment { ref payment_context, .. } => {
439- PaymentId ( payment_context. offer_id . 0 )
440- } ,
441- PaymentPurpose :: Bolt12RefundPayment { .. } => PaymentId ( payment_hash. 0 ) ,
442- PaymentPurpose :: SpontaneousPayment ( ..) => PaymentId ( payment_hash. 0 ) ,
443- } ;
444-
436+ let payment_id = PaymentId ( payment_hash. 0 ) ;
445437 if let Some ( info) = self . payment_store . get ( & payment_id) {
446438 if info. status == PaymentStatus :: Succeeded
447439 || matches ! ( info. kind, PaymentKind :: Spontaneous { .. } )
@@ -520,19 +512,91 @@ where
520512 . ok ( ) )
521513 } ,
522514 PaymentPurpose :: Bolt12OfferPayment {
523- payment_preimage, payment_secret, ..
524- } => payment_preimage. or ( self
525- . channel_manager
526- . get_payment_preimage ( payment_hash, payment_secret)
527- . ok ( ) ) ,
515+ payment_preimage,
516+ payment_secret,
517+ payment_context,
518+ ..
519+ } => {
520+ let offer_id = payment_context. offer_id ;
521+ let payment = PaymentDetails {
522+ id : payment_id,
523+ kind : PaymentKind :: Bolt12Offer {
524+ hash : Some ( payment_hash) ,
525+ preimage : payment_preimage,
526+ secret : Some ( payment_secret) ,
527+ offer_id,
528+ } ,
529+ amount_msat : Some ( amount_msat) ,
530+ direction : PaymentDirection :: Inbound ,
531+ status : PaymentStatus :: Pending ,
532+ } ;
533+
534+ match self . payment_store . insert ( payment) {
535+ Ok ( false ) => ( ) ,
536+ Ok ( true ) => {
537+ log_error ! (
538+ self . logger,
539+ "Bolt12OfferPayment with ID {} was previously known" ,
540+ payment_id,
541+ ) ;
542+ debug_assert ! ( false ) ;
543+ } ,
544+ Err ( e) => {
545+ log_error ! (
546+ self . logger,
547+ "Failed to insert payment with ID {}: {}" ,
548+ payment_id,
549+ e
550+ ) ;
551+ debug_assert ! ( false ) ;
552+ } ,
553+ }
554+ payment_preimage. or ( self
555+ . channel_manager
556+ . get_payment_preimage ( payment_hash, payment_secret)
557+ . ok ( ) )
558+ } ,
528559 PaymentPurpose :: Bolt12RefundPayment {
529560 payment_preimage,
530561 payment_secret,
531562 ..
532- } => payment_preimage. or ( self
533- . channel_manager
534- . get_payment_preimage ( payment_hash, payment_secret)
535- . ok ( ) ) ,
563+ } => {
564+ let payment = PaymentDetails {
565+ id : payment_id,
566+ kind : PaymentKind :: Bolt12Refund {
567+ hash : Some ( payment_hash) ,
568+ preimage : payment_preimage,
569+ secret : Some ( payment_secret) ,
570+ } ,
571+ amount_msat : Some ( amount_msat) ,
572+ direction : PaymentDirection :: Inbound ,
573+ status : PaymentStatus :: Pending ,
574+ } ;
575+ match self . payment_store . insert ( payment) {
576+ Ok ( false ) => ( ) ,
577+ Ok ( true ) => {
578+ log_error ! (
579+ self . logger,
580+ "Bolt12RefundPayment with ID {} was previously known" ,
581+ payment_id,
582+ ) ;
583+ debug_assert ! ( false ) ;
584+ } ,
585+ Err ( e) => {
586+ log_error ! (
587+ self . logger,
588+ "Failed to insert payment with ID {}: {}" ,
589+ payment_id,
590+ e
591+ ) ;
592+ debug_assert ! ( false ) ;
593+ } ,
594+ }
595+ payment_preimage. or ( self
596+ . channel_manager
597+ . get_payment_preimage ( payment_hash, payment_secret)
598+ . ok ( ) )
599+ } ,
536600 PaymentPurpose :: SpontaneousPayment ( preimage) => {
537601 // Since it's spontaneous, we insert it now into our store.
538602 let payment = PaymentDetails {
@@ -600,15 +664,7 @@ where
600664 htlcs : _,
601665 sender_intended_total_msat : _,
602666 } => {
603- let payment_id = match purpose {
604- PaymentPurpose :: Bolt11InvoicePayment { .. } => PaymentId ( payment_hash. 0 ) ,
605- PaymentPurpose :: Bolt12OfferPayment { ref payment_context, .. } => {
606- PaymentId ( payment_context. offer_id . 0 )
607- } ,
608- PaymentPurpose :: Bolt12RefundPayment { .. } => PaymentId ( payment_hash. 0 ) ,
609- PaymentPurpose :: SpontaneousPayment ( ..) => PaymentId ( payment_hash. 0 ) ,
610- } ;
611-
667+ let payment_id = PaymentId ( payment_hash. 0 ) ;
612668 log_info ! (
613669 self . logger,
614670 "Claimed payment with ID {} from payment hash {} of {}msat." ,
@@ -623,7 +679,6 @@ where
623679 payment_secret,
624680 ..
625681 } => PaymentDetailsUpdate {
626- hash : Some ( Some ( payment_hash) ) ,
627682 preimage : Some ( payment_preimage) ,
628683 secret : Some ( Some ( payment_secret) ) ,
629684 amount_msat : Some ( Some ( amount_msat) ) ,
@@ -633,7 +688,6 @@ where
633688 PaymentPurpose :: Bolt12OfferPayment {
634689 payment_preimage, payment_secret, ..
635690 } => PaymentDetailsUpdate {
636- hash : Some ( Some ( payment_hash) ) ,
637691 preimage : Some ( payment_preimage) ,
638692 secret : Some ( Some ( payment_secret) ) ,
639693 amount_msat : Some ( Some ( amount_msat) ) ,
@@ -645,15 +699,13 @@ where
645699 payment_secret,
646700 ..
647701 } => PaymentDetailsUpdate {
648- hash : Some ( Some ( payment_hash) ) ,
649702 preimage : Some ( payment_preimage) ,
650703 secret : Some ( Some ( payment_secret) ) ,
651704 amount_msat : Some ( Some ( amount_msat) ) ,
652705 status : Some ( PaymentStatus :: Succeeded ) ,
653706 ..PaymentDetailsUpdate :: new ( payment_id)
654707 } ,
655708 PaymentPurpose :: SpontaneousPayment ( preimage) => PaymentDetailsUpdate {
656- hash : Some ( Some ( payment_hash) ) ,
657709 preimage : Some ( Some ( preimage) ) ,
658710 amount_msat : Some ( Some ( amount_msat) ) ,
659711 status : Some ( PaymentStatus :: Succeeded ) ,
0 commit comments