43
43
use bitcoin:: network:: constants:: Network ;
44
44
use core:: time:: Duration ;
45
45
use crate :: blinded_path:: { BlindedPath , IntroductionNode } ;
46
- use crate :: events:: { Event , MessageSendEventsProvider } ;
46
+ use crate :: blinded_path:: payment:: { Bolt12OfferContext , Bolt12RefundContext , PaymentContext } ;
47
+ use crate :: events:: { Event , MessageSendEventsProvider , PaymentPurpose } ;
47
48
use crate :: ln:: channelmanager:: { PaymentId , RecentPaymentDetails , Retry , self } ;
48
49
use crate :: ln:: functional_test_utils:: * ;
49
50
use crate :: ln:: msgs:: { ChannelMessageHandler , Init , NodeAnnouncement , OnionMessage , OnionMessageHandler , RoutingMessageHandler , SocketAddress , UnsignedGossipMessage , UnsignedNodeAnnouncement } ;
@@ -151,15 +152,28 @@ fn route_bolt12_payment<'a, 'b, 'c>(
151
152
do_pass_along_path ( args) ;
152
153
}
153
154
154
- fn claim_bolt12_payment < ' a , ' b , ' c > ( node : & Node < ' a , ' b , ' c > , path : & [ & Node < ' a , ' b , ' c > ] ) {
155
+ fn claim_bolt12_payment < ' a , ' b , ' c > (
156
+ node : & Node < ' a , ' b , ' c > , path : & [ & Node < ' a , ' b , ' c > ] , expected_payment_context : PaymentContext
157
+ ) {
155
158
let recipient = & path[ path. len ( ) - 1 ] ;
156
- match get_event ! ( recipient, Event :: PaymentClaimable ) {
157
- Event :: PaymentClaimable { purpose, .. } => match purpose. preimage ( ) {
158
- Some ( payment_preimage) => claim_payment ( node, path, payment_preimage) ,
159
- None => panic ! ( "No preimage in Event::PaymentClaimable" ) ,
160
- } ,
159
+ let payment_purpose = match get_event ! ( recipient, Event :: PaymentClaimable ) {
160
+ Event :: PaymentClaimable { purpose, .. } => purpose,
161
161
_ => panic ! ( "No Event::PaymentClaimable" ) ,
162
162
} ;
163
+ let payment_preimage = match payment_purpose. preimage ( ) {
164
+ Some ( preimage) => preimage,
165
+ None => panic ! ( "No preimage in Event::PaymentClaimable" ) ,
166
+ } ;
167
+ match payment_purpose {
168
+ PaymentPurpose :: Bolt12OfferPayment { payment_context, .. } => {
169
+ assert_eq ! ( PaymentContext :: Bolt12Offer ( payment_context) , expected_payment_context) ;
170
+ } ,
171
+ PaymentPurpose :: Bolt12RefundPayment { payment_context, .. } => {
172
+ assert_eq ! ( PaymentContext :: Bolt12Refund ( payment_context) , expected_payment_context) ;
173
+ } ,
174
+ _ => panic ! ( "Unexpected payment purpose: {:?}" , payment_purpose) ,
175
+ }
176
+ claim_payment ( node, path, payment_preimage) ;
163
177
}
164
178
165
179
fn extract_invoice_request < ' a , ' b , ' c > (
@@ -367,9 +381,11 @@ fn creates_and_pays_for_offer_using_two_hop_blinded_path() {
367
381
disconnect_peers ( david, & [ bob, & nodes[ 4 ] , & nodes[ 5 ] ] ) ;
368
382
369
383
let offer = alice. node
370
- . create_offer_builder ( "coffee" . to_string ( ) ) . unwrap ( )
384
+ . create_offer_builder ( "coffee" . to_string ( ) )
385
+ . unwrap ( )
371
386
. amount_msats ( 10_000_000 )
372
387
. build ( ) . unwrap ( ) ;
388
+ let payment_context = PaymentContext :: Bolt12Offer ( Bolt12OfferContext { offer_id : offer. id ( ) } ) ;
373
389
assert_ne ! ( offer. signing_pubkey( ) , alice_id) ;
374
390
assert ! ( !offer. paths( ) . is_empty( ) ) ;
375
391
for path in offer. paths ( ) {
@@ -413,7 +429,7 @@ fn creates_and_pays_for_offer_using_two_hop_blinded_path() {
413
429
route_bolt12_payment ( david, & [ charlie, bob, alice] , & invoice) ;
414
430
expect_recent_payment ! ( david, RecentPaymentDetails :: Pending , payment_id) ;
415
431
416
- claim_bolt12_payment ( david, & [ charlie, bob, alice] ) ;
432
+ claim_bolt12_payment ( david, & [ charlie, bob, alice] , payment_context ) ;
417
433
expect_recent_payment ! ( david, RecentPaymentDetails :: Fulfilled , payment_id) ;
418
434
}
419
435
@@ -472,6 +488,7 @@ fn creates_and_pays_for_refund_using_two_hop_blinded_path() {
472
488
}
473
489
expect_recent_payment ! ( david, RecentPaymentDetails :: AwaitingInvoice , payment_id) ;
474
490
491
+ let payment_context = PaymentContext :: Bolt12Refund ( Bolt12RefundContext { } ) ;
475
492
let expected_invoice = alice. node . request_refund_payment ( & refund) . unwrap ( ) ;
476
493
477
494
connect_peers ( alice, charlie) ;
@@ -495,7 +512,7 @@ fn creates_and_pays_for_refund_using_two_hop_blinded_path() {
495
512
route_bolt12_payment ( david, & [ charlie, bob, alice] , & invoice) ;
496
513
expect_recent_payment ! ( david, RecentPaymentDetails :: Pending , payment_id) ;
497
514
498
- claim_bolt12_payment ( david, & [ charlie, bob, alice] ) ;
515
+ claim_bolt12_payment ( david, & [ charlie, bob, alice] , payment_context ) ;
499
516
expect_recent_payment ! ( david, RecentPaymentDetails :: Fulfilled , payment_id) ;
500
517
}
501
518
@@ -520,6 +537,7 @@ fn creates_and_pays_for_offer_using_one_hop_blinded_path() {
520
537
. create_offer_builder ( "coffee" . to_string ( ) ) . unwrap ( )
521
538
. amount_msats ( 10_000_000 )
522
539
. build ( ) . unwrap ( ) ;
540
+ let payment_context = PaymentContext :: Bolt12Offer ( Bolt12OfferContext { offer_id : offer. id ( ) } ) ;
523
541
assert_ne ! ( offer. signing_pubkey( ) , alice_id) ;
524
542
assert ! ( !offer. paths( ) . is_empty( ) ) ;
525
543
for path in offer. paths ( ) {
@@ -552,7 +570,7 @@ fn creates_and_pays_for_offer_using_one_hop_blinded_path() {
552
570
route_bolt12_payment ( bob, & [ alice] , & invoice) ;
553
571
expect_recent_payment ! ( bob, RecentPaymentDetails :: Pending , payment_id) ;
554
572
555
- claim_bolt12_payment ( bob, & [ alice] ) ;
573
+ claim_bolt12_payment ( bob, & [ alice] , payment_context ) ;
556
574
expect_recent_payment ! ( bob, RecentPaymentDetails :: Fulfilled , payment_id) ;
557
575
}
558
576
@@ -590,6 +608,7 @@ fn creates_and_pays_for_refund_using_one_hop_blinded_path() {
590
608
}
591
609
expect_recent_payment ! ( bob, RecentPaymentDetails :: AwaitingInvoice , payment_id) ;
592
610
611
+ let payment_context = PaymentContext :: Bolt12Refund ( Bolt12RefundContext { } ) ;
593
612
let expected_invoice = alice. node . request_refund_payment ( & refund) . unwrap ( ) ;
594
613
595
614
let onion_message = alice. onion_messenger . next_onion_message_for_peer ( bob_id) . unwrap ( ) ;
@@ -608,7 +627,7 @@ fn creates_and_pays_for_refund_using_one_hop_blinded_path() {
608
627
route_bolt12_payment ( bob, & [ alice] , & invoice) ;
609
628
expect_recent_payment ! ( bob, RecentPaymentDetails :: Pending , payment_id) ;
610
629
611
- claim_bolt12_payment ( bob, & [ alice] ) ;
630
+ claim_bolt12_payment ( bob, & [ alice] , payment_context ) ;
612
631
expect_recent_payment ! ( bob, RecentPaymentDetails :: Fulfilled , payment_id) ;
613
632
}
614
633
@@ -634,6 +653,7 @@ fn pays_for_offer_without_blinded_paths() {
634
653
. clear_paths ( )
635
654
. amount_msats ( 10_000_000 )
636
655
. build ( ) . unwrap ( ) ;
656
+ let payment_context = PaymentContext :: Bolt12Offer ( Bolt12OfferContext { offer_id : offer. id ( ) } ) ;
637
657
assert_eq ! ( offer. signing_pubkey( ) , alice_id) ;
638
658
assert ! ( offer. paths( ) . is_empty( ) ) ;
639
659
@@ -651,7 +671,7 @@ fn pays_for_offer_without_blinded_paths() {
651
671
route_bolt12_payment ( bob, & [ alice] , & invoice) ;
652
672
expect_recent_payment ! ( bob, RecentPaymentDetails :: Pending , payment_id) ;
653
673
654
- claim_bolt12_payment ( bob, & [ alice] ) ;
674
+ claim_bolt12_payment ( bob, & [ alice] , payment_context ) ;
655
675
expect_recent_payment ! ( bob, RecentPaymentDetails :: Fulfilled , payment_id) ;
656
676
}
657
677
@@ -684,6 +704,7 @@ fn pays_for_refund_without_blinded_paths() {
684
704
assert ! ( refund. paths( ) . is_empty( ) ) ;
685
705
expect_recent_payment ! ( bob, RecentPaymentDetails :: AwaitingInvoice , payment_id) ;
686
706
707
+ let payment_context = PaymentContext :: Bolt12Refund ( Bolt12RefundContext { } ) ;
687
708
let expected_invoice = alice. node . request_refund_payment ( & refund) . unwrap ( ) ;
688
709
689
710
let onion_message = alice. onion_messenger . next_onion_message_for_peer ( bob_id) . unwrap ( ) ;
@@ -695,7 +716,7 @@ fn pays_for_refund_without_blinded_paths() {
695
716
route_bolt12_payment ( bob, & [ alice] , & invoice) ;
696
717
expect_recent_payment ! ( bob, RecentPaymentDetails :: Pending , payment_id) ;
697
718
698
- claim_bolt12_payment ( bob, & [ alice] ) ;
719
+ claim_bolt12_payment ( bob, & [ alice] , payment_context ) ;
699
720
expect_recent_payment ! ( bob, RecentPaymentDetails :: Fulfilled , payment_id) ;
700
721
}
701
722
@@ -1068,12 +1089,13 @@ fn fails_paying_invoice_more_than_once() {
1068
1089
david. onion_messenger . handle_onion_message ( & charlie_id, & onion_message) ;
1069
1090
1070
1091
// David pays the first invoice
1092
+ let payment_context = PaymentContext :: Bolt12Refund ( Bolt12RefundContext { } ) ;
1071
1093
let invoice1 = extract_invoice ( david, & onion_message) ;
1072
1094
1073
1095
route_bolt12_payment ( david, & [ charlie, bob, alice] , & invoice1) ;
1074
1096
expect_recent_payment ! ( david, RecentPaymentDetails :: Pending , payment_id) ;
1075
1097
1076
- claim_bolt12_payment ( david, & [ charlie, bob, alice] ) ;
1098
+ claim_bolt12_payment ( david, & [ charlie, bob, alice] , payment_context ) ;
1077
1099
expect_recent_payment ! ( david, RecentPaymentDetails :: Fulfilled , payment_id) ;
1078
1100
1079
1101
disconnect_peers ( alice, & [ charlie] ) ;
0 commit comments