Skip to content

Commit 0495d39

Browse files
committed
f Insert inbound payment in request_refund
1 parent da05085 commit 0495d39

File tree

2 files changed

+22
-38
lines changed

2 files changed

+22
-38
lines changed

src/event.rs

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -549,42 +549,7 @@ where
549549
}
550550
payment_preimage
551551
},
552-
PaymentPurpose::Bolt12RefundPayment {
553-
payment_preimage,
554-
payment_secret,
555-
..
556-
} => {
557-
let payment = PaymentDetails {
558-
id: payment_id,
559-
kind: PaymentKind::Bolt12Refund {
560-
hash: Some(payment_hash),
561-
preimage: payment_preimage,
562-
secret: Some(payment_secret),
563-
},
564-
amount_msat: Some(amount_msat),
565-
direction: PaymentDirection::Inbound,
566-
status: PaymentStatus::Pending,
567-
};
568-
match self.payment_store.insert(payment) {
569-
Ok(false) => (),
570-
Ok(true) => {
571-
log_error!(
572-
self.logger,
573-
"Bolt12RefundPayment with ID {} was previously known",
574-
payment_id,
575-
);
576-
debug_assert!(false);
577-
},
578-
Err(e) => {
579-
log_error!(
580-
self.logger,
581-
"Failed to insert payment with ID {}: {}",
582-
payment_id,
583-
e
584-
);
585-
debug_assert!(false);
586-
},
587-
}
552+
PaymentPurpose::Bolt12RefundPayment { payment_preimage, .. } => {
588553
payment_preimage
589554
},
590555
PaymentPurpose::SpontaneousPayment(preimage) => {

src/payment/bolt12.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,10 +273,29 @@ impl Bolt12Payment {
273273
/// The returned [`Bolt12Invoice`] is for informational purposes only (i.e., isn't needed to
274274
/// retrieve the refund).
275275
pub fn request_refund(&self, refund: &Refund) -> Result<Bolt12Invoice, Error> {
276-
self.channel_manager.request_refund_payment(refund).map_err(|e| {
276+
let invoice = self.channel_manager.request_refund_payment(refund).map_err(|e| {
277277
log_error!(self.logger, "Failed to request refund payment: {:?}", e);
278278
Error::InvoiceRequestCreationFailed
279-
})
279+
})?;
280+
281+
let payment_hash = invoice.payment_hash();
282+
let payment_id = PaymentId(payment_hash.0);
283+
284+
let payment = PaymentDetails {
285+
id: payment_id,
286+
kind: PaymentKind::Bolt12Refund {
287+
hash: Some(payment_hash),
288+
preimage: None,
289+
secret: None,
290+
},
291+
amount_msat: Some(refund.amount_msats()),
292+
direction: PaymentDirection::Inbound,
293+
status: PaymentStatus::Pending,
294+
};
295+
296+
self.payment_store.insert(payment)?;
297+
298+
Ok(invoice)
280299
}
281300

282301
/// Returns a [`Refund`] that can be used to offer a refund payment of the amount given.

0 commit comments

Comments
 (0)