From: shaavan Date: Fri, 5 Jul 2024 12:49:15 +0000 (+0530) Subject: Update extract_invoice to also return the reply_path. X-Git-Tag: v0.0.124-beta~46^2~1 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=887e99900c6a614e1c0acd59b879f731c17297c0;p=rust-lightning Update extract_invoice to also return the reply_path. - This will be utilised in the following commit for a test. --- diff --git a/lightning/src/ln/offers_tests.rs b/lightning/src/ln/offers_tests.rs index 83ff8ce6d..041cc18fa 100644 --- a/lightning/src/ln/offers_tests.rs +++ b/lightning/src/ln/offers_tests.rs @@ -205,12 +205,12 @@ fn extract_invoice_request<'a, 'b, 'c>( } } -fn extract_invoice<'a, 'b, 'c>(node: &Node<'a, 'b, 'c>, message: &OnionMessage) -> Bolt12Invoice { +fn extract_invoice<'a, 'b, 'c>(node: &Node<'a, 'b, 'c>, message: &OnionMessage) -> (Bolt12Invoice, Option) { match node.onion_messenger.peel_onion_message(message) { - Ok(PeeledOnion::Receive(message, _, _)) => match message { + Ok(PeeledOnion::Receive(message, _, reply_path)) => match message { ParsedOnionMessageContents::Offers(offers_message) => match offers_message { OffersMessage::InvoiceRequest(invoice_request) => panic!("Unexpected invoice_request: {:?}", invoice_request), - OffersMessage::Invoice(invoice) => invoice, + OffersMessage::Invoice(invoice) => (invoice, reply_path), #[cfg(async_payments)] OffersMessage::StaticInvoice(invoice) => panic!("Unexpected static invoice: {:?}", invoice), OffersMessage::InvoiceError(error) => panic!("Unexpected invoice_error: {:?}", error), @@ -566,7 +566,7 @@ fn creates_and_pays_for_offer_using_two_hop_blinded_path() { let onion_message = charlie.onion_messenger.next_onion_message_for_peer(david_id).unwrap(); david.onion_messenger.handle_onion_message(&charlie_id, &onion_message); - let invoice = extract_invoice(david, &onion_message); + let (invoice, _) = extract_invoice(david, &onion_message); assert_eq!(invoice.amount_msats(), 10_000_000); assert_ne!(invoice.signing_pubkey(), alice_id); assert!(!invoice.payment_paths().is_empty()); @@ -645,7 +645,7 @@ fn creates_and_pays_for_refund_using_two_hop_blinded_path() { let onion_message = charlie.onion_messenger.next_onion_message_for_peer(david_id).unwrap(); david.onion_messenger.handle_onion_message(&charlie_id, &onion_message); - let invoice = extract_invoice(david, &onion_message); + let (invoice, _) = extract_invoice(david, &onion_message); assert_eq!(invoice, expected_invoice); assert_eq!(invoice.amount_msats(), 10_000_000); @@ -712,7 +712,7 @@ fn creates_and_pays_for_offer_using_one_hop_blinded_path() { let onion_message = alice.onion_messenger.next_onion_message_for_peer(bob_id).unwrap(); bob.onion_messenger.handle_onion_message(&alice_id, &onion_message); - let invoice = extract_invoice(bob, &onion_message); + let (invoice, _) = extract_invoice(bob, &onion_message); assert_eq!(invoice.amount_msats(), 10_000_000); assert_ne!(invoice.signing_pubkey(), alice_id); assert!(!invoice.payment_paths().is_empty()); @@ -765,7 +765,7 @@ fn creates_and_pays_for_refund_using_one_hop_blinded_path() { let onion_message = alice.onion_messenger.next_onion_message_for_peer(bob_id).unwrap(); bob.onion_messenger.handle_onion_message(&alice_id, &onion_message); - let invoice = extract_invoice(bob, &onion_message); + let (invoice, _) = extract_invoice(bob, &onion_message); assert_eq!(invoice, expected_invoice); assert_eq!(invoice.amount_msats(), 10_000_000); @@ -827,7 +827,7 @@ fn pays_for_offer_without_blinded_paths() { let onion_message = alice.onion_messenger.next_onion_message_for_peer(bob_id).unwrap(); bob.onion_messenger.handle_onion_message(&alice_id, &onion_message); - let invoice = extract_invoice(bob, &onion_message); + let (invoice, _) = extract_invoice(bob, &onion_message); route_bolt12_payment(bob, &[alice], &invoice); expect_recent_payment!(bob, RecentPaymentDetails::Pending, payment_id); @@ -868,7 +868,7 @@ fn pays_for_refund_without_blinded_paths() { let onion_message = alice.onion_messenger.next_onion_message_for_peer(bob_id).unwrap(); bob.onion_messenger.handle_onion_message(&alice_id, &onion_message); - let invoice = extract_invoice(bob, &onion_message); + let (invoice, _) = extract_invoice(bob, &onion_message); assert_eq!(invoice, expected_invoice); route_bolt12_payment(bob, &[alice], &invoice); @@ -1012,7 +1012,7 @@ fn creates_offer_with_blinded_path_using_unannounced_introduction_node() { let onion_message = alice.onion_messenger.next_onion_message_for_peer(bob_id).unwrap(); bob.onion_messenger.handle_onion_message(&alice_id, &onion_message); - let invoice = extract_invoice(bob, &onion_message); + let (invoice, _) = extract_invoice(bob, &onion_message); assert_ne!(invoice.signing_pubkey(), alice_id); assert!(!invoice.payment_paths().is_empty()); for (_, path) in invoice.payment_paths() { @@ -1061,7 +1061,7 @@ fn creates_refund_with_blinded_path_using_unannounced_introduction_node() { let onion_message = alice.onion_messenger.next_onion_message_for_peer(bob_id).unwrap(); - let invoice = extract_invoice(bob, &onion_message); + let (invoice, _) = extract_invoice(bob, &onion_message); assert_eq!(invoice, expected_invoice); assert_ne!(invoice.signing_pubkey(), alice_id); assert!(!invoice.payment_paths().is_empty()); @@ -1525,7 +1525,7 @@ fn fails_paying_invoice_more_than_once() { // David pays the first invoice let payment_context = PaymentContext::Bolt12Refund(Bolt12RefundContext {}); - let invoice1 = extract_invoice(david, &onion_message); + let (invoice1, _) = extract_invoice(david, &onion_message); route_bolt12_payment(david, &[charlie, bob, alice], &invoice1); expect_recent_payment!(david, RecentPaymentDetails::Pending, payment_id); @@ -1547,7 +1547,7 @@ fn fails_paying_invoice_more_than_once() { let onion_message = charlie.onion_messenger.next_onion_message_for_peer(david_id).unwrap(); david.onion_messenger.handle_onion_message(&charlie_id, &onion_message); - let invoice2 = extract_invoice(david, &onion_message); + let (invoice2, _) = extract_invoice(david, &onion_message); assert_eq!(invoice1.payer_metadata(), invoice2.payer_metadata()); // David sends an error instead of paying the second invoice