@@ -433,15 +433,7 @@ where
433
433
onion_fields : _,
434
434
counterparty_skimmed_fee_msat,
435
435
} => {
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 ) ;
445
437
if let Some ( info) = self . payment_store . get ( & payment_id) {
446
438
if info. status == PaymentStatus :: Succeeded
447
439
|| matches ! ( info. kind, PaymentKind :: Spontaneous { .. } )
@@ -520,19 +512,91 @@ where
520
512
. ok ( ) )
521
513
} ,
522
514
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
+ } ,
528
559
PaymentPurpose :: Bolt12RefundPayment {
529
560
payment_preimage,
530
561
payment_secret,
531
562
..
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
+ } ,
536
600
PaymentPurpose :: SpontaneousPayment ( preimage) => {
537
601
// Since it's spontaneous, we insert it now into our store.
538
602
let payment = PaymentDetails {
@@ -600,15 +664,7 @@ where
600
664
htlcs : _,
601
665
sender_intended_total_msat : _,
602
666
} => {
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 ) ;
612
668
log_info ! (
613
669
self . logger,
614
670
"Claimed payment with ID {} from payment hash {} of {}msat." ,
@@ -623,7 +679,6 @@ where
623
679
payment_secret,
624
680
..
625
681
} => PaymentDetailsUpdate {
626
- hash : Some ( Some ( payment_hash) ) ,
627
682
preimage : Some ( payment_preimage) ,
628
683
secret : Some ( Some ( payment_secret) ) ,
629
684
amount_msat : Some ( Some ( amount_msat) ) ,
@@ -633,7 +688,6 @@ where
633
688
PaymentPurpose :: Bolt12OfferPayment {
634
689
payment_preimage, payment_secret, ..
635
690
} => PaymentDetailsUpdate {
636
- hash : Some ( Some ( payment_hash) ) ,
637
691
preimage : Some ( payment_preimage) ,
638
692
secret : Some ( Some ( payment_secret) ) ,
639
693
amount_msat : Some ( Some ( amount_msat) ) ,
@@ -645,15 +699,13 @@ where
645
699
payment_secret,
646
700
..
647
701
} => PaymentDetailsUpdate {
648
- hash : Some ( Some ( payment_hash) ) ,
649
702
preimage : Some ( payment_preimage) ,
650
703
secret : Some ( Some ( payment_secret) ) ,
651
704
amount_msat : Some ( Some ( amount_msat) ) ,
652
705
status : Some ( PaymentStatus :: Succeeded ) ,
653
706
..PaymentDetailsUpdate :: new ( payment_id)
654
707
} ,
655
708
PaymentPurpose :: SpontaneousPayment ( preimage) => PaymentDetailsUpdate {
656
- hash : Some ( Some ( payment_hash) ) ,
657
709
preimage : Some ( Some ( preimage) ) ,
658
710
amount_msat : Some ( Some ( amount_msat) ) ,
659
711
status : Some ( PaymentStatus :: Succeeded ) ,
0 commit comments