Skip to content

Commit 5c767f0

Browse files
committed
Return the invoice when requesting a refund
When sending an invoice for a refund, information from the invoice may be useful for caller. For instance, the payment_hash can be used to track whether the refund was paid. Return the invoice to facilitate this use case.
1 parent 64de837 commit 5c767f0

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7934,7 +7934,7 @@ where
79347934
///
79357935
/// The resulting invoice uses a [`PaymentHash`] recognized by the [`ChannelManager`] and a
79367936
/// [`BlindedPath`] containing the [`PaymentSecret`] needed to reconstruct the corresponding
7937-
/// [`PaymentPreimage`].
7937+
/// [`PaymentPreimage`]. It is returned purely for informational purposes.
79387938
///
79397939
/// # Limitations
79407940
///
@@ -7951,7 +7951,9 @@ where
79517951
/// the invoice.
79527952
///
79537953
/// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
7954-
pub fn request_refund_payment(&self, refund: &Refund) -> Result<(), Bolt12SemanticError> {
7954+
pub fn request_refund_payment(
7955+
&self, refund: &Refund
7956+
) -> Result<Bolt12Invoice, Bolt12SemanticError> {
79557957
let expanded_key = &self.inbound_payment_key;
79567958
let entropy = &*self.entropy_source;
79577959
let secp_ctx = &self.secp_ctx;
@@ -7990,7 +7992,7 @@ where
79907992
let mut pending_offers_messages = self.pending_offers_messages.lock().unwrap();
79917993
if refund.paths().is_empty() {
79927994
let message = new_pending_onion_message(
7993-
OffersMessage::Invoice(invoice),
7995+
OffersMessage::Invoice(invoice.clone()),
79947996
Destination::Node(refund.payer_id()),
79957997
Some(reply_path),
79967998
);
@@ -8006,7 +8008,7 @@ where
80068008
}
80078009
}
80088010

8009-
Ok(())
8011+
Ok(invoice)
80108012
},
80118013
Err(()) => Err(Bolt12SemanticError::InvalidAmount),
80128014
}

lightning/src/ln/offers_tests.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ fn creates_and_pays_for_refund_using_two_hop_blinded_path() {
473473
}
474474
expect_recent_payment!(david, RecentPaymentDetails::AwaitingInvoice, payment_id);
475475

476-
alice.node.request_refund_payment(&refund).unwrap();
476+
let expected_invoice = alice.node.request_refund_payment(&refund).unwrap();
477477

478478
connect_peers(alice, charlie);
479479

@@ -484,6 +484,8 @@ fn creates_and_pays_for_refund_using_two_hop_blinded_path() {
484484
david.onion_messenger.handle_onion_message(&charlie_id, &onion_message);
485485

486486
let invoice = extract_invoice(david, &onion_message);
487+
assert_eq!(invoice, expected_invoice);
488+
487489
assert_eq!(invoice.amount_msats(), 10_000_000);
488490
assert_ne!(invoice.signing_pubkey(), alice_id);
489491
assert!(!invoice.payment_paths().is_empty());
@@ -589,12 +591,14 @@ fn creates_and_pays_for_refund_using_one_hop_blinded_path() {
589591
}
590592
expect_recent_payment!(bob, RecentPaymentDetails::AwaitingInvoice, payment_id);
591593

592-
alice.node.request_refund_payment(&refund).unwrap();
594+
let expected_invoice = alice.node.request_refund_payment(&refund).unwrap();
593595

594596
let onion_message = alice.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
595597
bob.onion_messenger.handle_onion_message(&alice_id, &onion_message);
596598

597599
let invoice = extract_invoice(bob, &onion_message);
600+
assert_eq!(invoice, expected_invoice);
601+
598602
assert_eq!(invoice.amount_msats(), 10_000_000);
599603
assert_ne!(invoice.signing_pubkey(), alice_id);
600604
assert!(!invoice.payment_paths().is_empty());
@@ -681,12 +685,14 @@ fn pays_for_refund_without_blinded_paths() {
681685
assert!(refund.paths().is_empty());
682686
expect_recent_payment!(bob, RecentPaymentDetails::AwaitingInvoice, payment_id);
683687

684-
alice.node.request_refund_payment(&refund).unwrap();
688+
let expected_invoice = alice.node.request_refund_payment(&refund).unwrap();
685689

686690
let onion_message = alice.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
687691
bob.onion_messenger.handle_onion_message(&alice_id, &onion_message);
688692

689693
let invoice = extract_invoice(bob, &onion_message);
694+
assert_eq!(invoice, expected_invoice);
695+
690696
route_bolt12_payment(bob, &[alice], &invoice);
691697
expect_recent_payment!(bob, RecentPaymentDetails::Pending, payment_id);
692698

0 commit comments

Comments
 (0)