Skip to content

Commit

Permalink
f Insert inbound payment in request_refund
Browse files Browse the repository at this point in the history
  • Loading branch information
tnull committed May 29, 2024
1 parent da05085 commit 0495d39
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 38 deletions.
37 changes: 1 addition & 36 deletions src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
23 changes: 21 additions & 2 deletions src/payment/bolt12.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Bolt12Invoice, Error> {
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.
Expand Down

0 comments on commit 0495d39

Please sign in to comment.