@@ -298,23 +298,37 @@ impl LdkEventHandler for LdkLiteEventHandler {
298
298
amount_msat,
299
299
) ;
300
300
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
+ }
303
309
}
304
310
PaymentPurpose :: SpontaneousPayment ( preimage) => Some ( * preimage) ,
305
311
} ;
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
+ } )
312
319
. 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
+ }
313
327
}
314
328
LdkEvent :: PaymentClaimed { payment_hash, purpose, amount_msat } => {
315
329
log_info ! (
316
330
self . logger,
317
- "Claimed payment from payment hash {} of {} millisatoshis" ,
331
+ "Claimed payment from payment hash {} of {} millisatoshis. " ,
318
332
hex_utils:: to_string( & payment_hash. 0 ) ,
319
333
amount_msat,
320
334
) ;
0 commit comments