@@ -50,7 +50,8 @@ use crate::blinded_path::message::BlindedMessagePath;
5050use crate :: blinded_path:: payment:: { Bolt12OfferContext , Bolt12RefundContext , PaymentContext } ;
5151use crate :: blinded_path:: message:: OffersContext ;
5252use crate :: events:: { ClosureReason , Event , HTLCHandlingFailureType , PaidBolt12Invoice , PaymentFailureReason , PaymentPurpose } ;
53- use crate :: ln:: channelmanager:: { Bolt12PaymentError , PaymentId , RecentPaymentDetails , RecipientOnionFields , Retry , self } ;
53+ use crate :: ln:: channelmanager:: { self , Bolt12PaymentError , OptionalOfferPaymentParams , PaymentId , RecentPaymentDetails , RecipientOnionFields , Retry } ;
54+ use crate :: offers:: contacts:: ContactSecrets ;
5455use crate :: offers:: offer:: Offer ;
5556use crate :: types:: features:: Bolt12InvoiceFeatures ;
5657use crate :: ln:: functional_test_utils:: * ;
@@ -686,6 +687,8 @@ fn creates_and_pays_for_offer_using_two_hop_blinded_path() {
686687 quantity : None ,
687688 payer_note_truncated : None ,
688689 human_readable_name : None ,
690+ contact_secret : None ,
691+ payer_offer : None ,
689692 } ,
690693 } ) ;
691694 assert_eq ! ( invoice_request. amount_msats( ) , Some ( 10_000_000 ) ) ;
@@ -844,6 +847,8 @@ fn creates_and_pays_for_offer_using_one_hop_blinded_path() {
844847 quantity : None ,
845848 payer_note_truncated : None ,
846849 human_readable_name : None ,
850+ contact_secret : None ,
851+ payer_offer : None ,
847852 } ,
848853 } ) ;
849854 assert_eq ! ( invoice_request. amount_msats( ) , Some ( 10_000_000 ) ) ;
@@ -965,6 +970,8 @@ fn pays_for_offer_without_blinded_paths() {
965970 quantity : None ,
966971 payer_note_truncated : None ,
967972 human_readable_name : None ,
973+ contact_secret : None ,
974+ payer_offer : None ,
968975 } ,
969976 } ) ;
970977
@@ -1232,6 +1239,8 @@ fn creates_and_pays_for_offer_with_retry() {
12321239 quantity : None ,
12331240 payer_note_truncated : None ,
12341241 human_readable_name : None ,
1242+ contact_secret : None ,
1243+ payer_offer : None ,
12351244 } ,
12361245 } ) ;
12371246 assert_eq ! ( invoice_request. amount_msats( ) , Some ( 10_000_000 ) ) ;
@@ -1297,6 +1306,8 @@ fn pays_bolt12_invoice_asynchronously() {
12971306 quantity : None ,
12981307 payer_note_truncated : None ,
12991308 human_readable_name : None ,
1309+ contact_secret : None ,
1310+ payer_offer : None ,
13001311 } ,
13011312 } ) ;
13021313
@@ -1394,6 +1405,8 @@ fn creates_offer_with_blinded_path_using_unannounced_introduction_node() {
13941405 quantity : None ,
13951406 payer_note_truncated : None ,
13961407 human_readable_name : None ,
1408+ contact_secret : None ,
1409+ payer_offer : None ,
13971410 } ,
13981411 } ) ;
13991412 assert_ne ! ( invoice_request. payer_signing_pubkey( ) , bob_id) ;
@@ -2555,28 +2568,16 @@ fn pay_offer_and_add_contacts_info_blip42() {
25552568
25562569 let payment_id = PaymentId ( [ 1 ; 32 ] ) ;
25572570 bob. node . pay_for_offer ( & offer, None , payment_id, Default :: default ( ) ) . unwrap ( ) ;
2558- // Probably a good place to add the information that we use for the contact secret.
2559- // but need to double check if the sender of the invoice request still need to ask anything.
2571+
25602572 expect_recent_payment ! ( bob, RecentPaymentDetails :: AwaitingInvoice , payment_id) ;
25612573 let onion_message = bob. onion_messenger . next_onion_message_for_peer ( alice_id) . unwrap ( ) ;
25622574 alice. onion_messenger . handle_onion_message ( bob_id, & onion_message) ;
25632575
25642576 let ( invoice_request, _reply_path) = extract_invoice_request ( alice, & onion_message) ;
25652577
2566- let payment_context = PaymentContext :: Bolt12Offer ( Bolt12OfferContext {
2567- offer_id : offer. id ( ) ,
2568- invoice_request : InvoiceRequestFields {
2569- payer_signing_pubkey : invoice_request. payer_signing_pubkey ( ) ,
2570- quantity : None ,
2571- payer_note_truncated : None ,
2572- human_readable_name : None ,
2573- } ,
2574- } ) ;
25752578 assert_eq ! ( invoice_request. amount_msats( ) , Some ( 10_000_000 ) ) ;
25762579 assert_ne ! ( invoice_request. payer_signing_pubkey( ) , bob_id) ;
25772580 assert ! ( invoice_request. contact_secret( ) . is_some( ) ) ;
2578- // TODO: we should check also if the contact secret is the same that we inject by bob.
2579-
25802581 assert ! ( invoice_request. payer_offer( ) . is_some( ) ) ;
25812582
25822583 let onion_message = alice. onion_messenger . next_onion_message_for_peer ( bob_id) . unwrap ( ) ;
@@ -2590,7 +2591,18 @@ fn pay_offer_and_add_contacts_info_blip42() {
25902591 route_bolt12_payment ( bob, & [ alice] , & invoice) ;
25912592 expect_recent_payment ! ( bob, RecentPaymentDetails :: Pending , payment_id) ;
25922593
2593- let contact_info = claim_bolt12_payment ( bob, & [ alice] , payment_context, & invoice) ;
2594+ let ( alice_payment_purpose, alice_payment_preimage) = match get_event ! ( alice, Event :: PaymentClaimable ) {
2595+ Event :: PaymentClaimable { purpose, .. } => {
2596+ let preimage = match purpose. preimage ( ) {
2597+ Some ( p) => p,
2598+ None => panic ! ( "No preimage in PaymentClaimable" ) ,
2599+ } ;
2600+ ( purpose, preimage)
2601+ } ,
2602+ _ => panic ! ( "No Event::PaymentClaimable for Alice" ) ,
2603+ } ;
2604+
2605+ let ( _, contact_info) = claim_payment ( bob, & [ alice] , alice_payment_preimage) ;
25942606 expect_recent_payment ! ( bob, RecentPaymentDetails :: Fulfilled , payment_id) ;
25952607
25962608 assert ! ( contact_info. is_some( ) ) ;
@@ -2599,7 +2611,63 @@ fn pay_offer_and_add_contacts_info_blip42() {
25992611 assert ! ( invoice_request. contact_secret( ) . is_some( ) ) ;
26002612 assert_eq ! ( invoice_request. contact_secret( ) . unwrap( ) , contact_info. contact_secrets. primary_secret( ) ) ;
26012613
2602- // TODO: now should be possible that alice will be able to repay bob without that
2603- // bob give any offer in exchange!! but there is a contact list somewhere that allow
2604- // to run something like bob.pay_for_contact(alice_contact_name, amount);
2614+ let alice_invoice_request_fields = match alice_payment_purpose {
2615+ PaymentPurpose :: Bolt12OfferPayment { payment_context, .. } => {
2616+ assert_eq ! ( payment_context. offer_id, offer. id( ) ) ;
2617+ payment_context. invoice_request
2618+ } ,
2619+ _ => panic ! ( "Expected Bolt12OfferPayment purpose for Alice" ) ,
2620+ } ;
2621+
2622+ assert ! ( alice_invoice_request_fields. contact_secret. is_some( ) ) ;
2623+ assert_eq ! ( alice_invoice_request_fields. contact_secret. unwrap( ) , * contact_info. contact_secrets. primary_secret( ) ) ;
2624+
2625+ assert ! ( alice_invoice_request_fields. payer_offer. is_some( ) ) ;
2626+ assert_eq ! ( alice_invoice_request_fields. payer_offer. as_ref( ) . unwrap( ) , & contact_info. payer_offer) ;
2627+
2628+ let alice_contact_secret = alice_invoice_request_fields. contact_secret . unwrap ( ) ;
2629+ let alice_payer_offer = alice_invoice_request_fields. payer_offer . unwrap ( ) ;
2630+
2631+ let payment_id = PaymentId ( [ 1 ; 32 ] ) ;
2632+ alice. node . pay_for_offer ( & alice_payer_offer, Some ( 5_000_000 ) , payment_id, OptionalOfferPaymentParams {
2633+ contact_secrects : Some ( ContactSecrets :: new ( alice_contact_secret) ) ,
2634+ ..Default :: default ( )
2635+ } ) . unwrap ( ) ;
2636+
2637+
2638+ expect_recent_payment ! ( alice, RecentPaymentDetails :: AwaitingInvoice , payment_id) ;
2639+ let onion_message = alice. onion_messenger . next_onion_message_for_peer ( bob_id) . unwrap ( ) ;
2640+ bob. onion_messenger . handle_onion_message ( alice_id, & onion_message) ;
2641+
2642+ let ( invoice_request, _reply_path) = extract_invoice_request ( bob, & onion_message) ;
2643+
2644+ assert_eq ! ( invoice_request. amount_msats( ) , Some ( 5_000_000 ) ) ;
2645+ assert_ne ! ( invoice_request. payer_signing_pubkey( ) , bob_id) ;
2646+ assert ! ( invoice_request. contact_secret( ) . is_some( ) ) ;
2647+ assert ! ( invoice_request. payer_offer( ) . is_some( ) ) ;
2648+
2649+ let onion_message = bob. onion_messenger . next_onion_message_for_peer ( alice_id) . unwrap ( ) ;
2650+ bob. onion_messenger . handle_onion_message ( bob_id, & onion_message) ;
2651+
2652+ let ( invoice, _reply_path) = extract_invoice ( alice, & onion_message) ;
2653+ assert_eq ! ( invoice. amount_msats( ) , 10_000_000 ) ;
2654+ assert_ne ! ( invoice. signing_pubkey( ) , alice_id) ;
2655+ assert ! ( !invoice. payment_paths( ) . is_empty( ) ) ;
2656+
2657+ route_bolt12_payment ( bob, & [ alice] , & invoice) ;
2658+ expect_recent_payment ! ( bob, RecentPaymentDetails :: Pending , payment_id) ;
2659+
2660+ let ( _, alice_payment_preimage) = match get_event ! ( alice, Event :: PaymentClaimable ) {
2661+ Event :: PaymentClaimable { purpose, .. } => {
2662+ let preimage = match purpose. preimage ( ) {
2663+ Some ( p) => p,
2664+ None => panic ! ( "No preimage in PaymentClaimable" ) ,
2665+ } ;
2666+ ( purpose, preimage)
2667+ } ,
2668+ _ => panic ! ( "No Event::PaymentClaimable for Alice" ) ,
2669+ } ;
2670+
2671+ let ( _, _) = claim_payment ( bob, & [ alice] , alice_payment_preimage) ;
2672+ expect_recent_payment ! ( bob, RecentPaymentDetails :: Fulfilled , payment_id) ;
26052673}
0 commit comments