From 0495d394fb2c5147c9466c1a1b1353663b43ff57 Mon Sep 17 00:00:00 2001 From: Elias Rohrer Date: Wed, 29 May 2024 10:05:38 +0200 Subject: [PATCH] f Insert inbound payment in `request_refund` --- src/event.rs | 37 +------------------------------------ src/payment/bolt12.rs | 23 +++++++++++++++++++++-- 2 files changed, 22 insertions(+), 38 deletions(-) diff --git a/src/event.rs b/src/event.rs index 6586323f1..b49fc96e8 100644 --- a/src/event.rs +++ b/src/event.rs @@ -549,42 +549,7 @@ where } payment_preimage }, - PaymentPurpose::Bolt12RefundPayment { - payment_preimage, - payment_secret, - .. - } => { - let payment = PaymentDetails { - id: payment_id, - kind: PaymentKind::Bolt12Refund { - hash: Some(payment_hash), - preimage: payment_preimage, - secret: Some(payment_secret), - }, - amount_msat: Some(amount_msat), - direction: PaymentDirection::Inbound, - status: PaymentStatus::Pending, - }; - match self.payment_store.insert(payment) { - Ok(false) => (), - Ok(true) => { - log_error!( - self.logger, - "Bolt12RefundPayment with ID {} was previously known", - payment_id, - ); - debug_assert!(false); - }, - Err(e) => { - log_error!( - self.logger, - "Failed to insert payment with ID {}: {}", - payment_id, - e - ); - debug_assert!(false); - }, - } + PaymentPurpose::Bolt12RefundPayment { payment_preimage, .. } => { payment_preimage }, PaymentPurpose::SpontaneousPayment(preimage) => { diff --git a/src/payment/bolt12.rs b/src/payment/bolt12.rs index a5ad7be3d..d4cc04a8a 100644 --- a/src/payment/bolt12.rs +++ b/src/payment/bolt12.rs @@ -273,10 +273,29 @@ impl Bolt12Payment { /// The returned [`Bolt12Invoice`] is for informational purposes only (i.e., isn't needed to /// retrieve the refund). pub fn request_refund(&self, refund: &Refund) -> Result { - self.channel_manager.request_refund_payment(refund).map_err(|e| { + let invoice = self.channel_manager.request_refund_payment(refund).map_err(|e| { log_error!(self.logger, "Failed to request refund payment: {:?}", e); Error::InvoiceRequestCreationFailed - }) + })?; + + let payment_hash = invoice.payment_hash(); + let payment_id = PaymentId(payment_hash.0); + + let payment = PaymentDetails { + id: payment_id, + kind: PaymentKind::Bolt12Refund { + hash: Some(payment_hash), + preimage: None, + secret: None, + }, + amount_msat: Some(refund.amount_msats()), + direction: PaymentDirection::Inbound, + status: PaymentStatus::Pending, + }; + + self.payment_store.insert(payment)?; + + Ok(invoice) } /// Returns a [`Refund`] that can be used to offer a refund payment of the amount given.