@@ -298,23 +298,35 @@ 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 . get_payment_preimage ( * payment_hash, * payment_secret) . ok ( ) , * payment_secret)
306
+ }
303
307
}
304
308
PaymentPurpose :: SpontaneousPayment ( preimage) => Some ( * preimage) ,
305
309
} ;
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
+ } )
312
317
. 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
+ }
313
325
}
314
326
LdkEvent :: PaymentClaimed { payment_hash, purpose, amount_msat } => {
315
327
log_info ! (
316
328
self . logger,
317
- "Claimed payment from payment hash {} of {} millisatoshis" ,
329
+ "Claimed payment from payment hash {} of {} millisatoshis. " ,
318
330
hex_utils:: to_string( & payment_hash. 0 ) ,
319
331
amount_msat,
320
332
) ;
0 commit comments