Skip to content

Commit a983cce

Browse files
committed
f Try to retrieve preimage from channel manager
1 parent b7ada42 commit a983cce

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

src/event.rs

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -298,23 +298,35 @@ impl LdkEventHandler for LdkLiteEventHandler {
298298
amount_msat,
299299
);
300300
let payment_preimage = match purpose {
301-
PaymentPurpose::InvoicePayment { payment_preimage, .. } => {
302-
*payment_preimage
301+
PaymentPurpose::InvoicePayment { payment_preimage, payment_secret } => {
302+
if payment_preimage.is_some() {
303+
*payment_preimage
304+
} else {
305+
(self.channel_manager.get_payment_preimage(*payment_hash, *payment_secret).ok(), *payment_secret)
306+
}
303307
}
304308
PaymentPurpose::SpontaneousPayment(preimage) => Some(*preimage),
305309
};
306-
self.channel_manager.claim_funds(payment_preimage.unwrap());
307-
self.event_queue
308-
.add_event(LdkLiteEvent::PaymentReceived {
309-
payment_hash: *payment_hash,
310-
amount_msat: *amount_msat,
311-
})
310+
if let Some(preimage) = payment_preimage {
311+
self.channel_manager.claim_funds(preimage);
312+
self.event_queue
313+
.add_event(LdkLiteEvent::PaymentReceived {
314+
payment_hash: *payment_hash,
315+
amount_msat: *amount_msat,
316+
})
312317
.unwrap();
318+
} else {
319+
log_error!(
320+
self.logger,
321+
"Failed to claim payment with hash {}: preimage unknown.",
322+
hex_utils::to_string(&payment_hash.0),
323+
);
324+
}
313325
}
314326
LdkEvent::PaymentClaimed { payment_hash, purpose, amount_msat } => {
315327
log_info!(
316328
self.logger,
317-
"Claimed payment from payment hash {} of {} millisatoshis",
329+
"Claimed payment from payment hash {} of {} millisatoshis.",
318330
hex_utils::to_string(&payment_hash.0),
319331
amount_msat,
320332
);

0 commit comments

Comments
 (0)