Skip to content

Commit 75d88eb

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

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

src/event.rs

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -298,23 +298,37 @@ 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
306+
.get_payment_preimage(*payment_hash, *payment_secret)
307+
.ok()
308+
}
303309
}
304310
PaymentPurpose::SpontaneousPayment(preimage) => Some(*preimage),
305311
};
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-
})
312+
if let Some(preimage) = payment_preimage {
313+
self.channel_manager.claim_funds(preimage);
314+
self.event_queue
315+
.add_event(LdkLiteEvent::PaymentReceived {
316+
payment_hash: *payment_hash,
317+
amount_msat: *amount_msat,
318+
})
312319
.unwrap();
320+
} else {
321+
log_error!(
322+
self.logger,
323+
"Failed to claim payment with hash {}: preimage unknown.",
324+
hex_utils::to_string(&payment_hash.0),
325+
);
326+
}
313327
}
314328
LdkEvent::PaymentClaimed { payment_hash, purpose, amount_msat } => {
315329
log_info!(
316330
self.logger,
317-
"Claimed payment from payment hash {} of {} millisatoshis",
331+
"Claimed payment from payment hash {} of {} millisatoshis.",
318332
hex_utils::to_string(&payment_hash.0),
319333
amount_msat,
320334
);

0 commit comments

Comments
 (0)