@@ -298,24 +298,37 @@ impl LdkEventHandler for LdkLiteEventHandler {
298
298
hex_utils:: to_string( & payment_hash. 0 ) ,
299
299
amount_msat,
300
300
) ;
301
- let payment_preimage = match purpose {
301
+ let ( payment_preimage, payment_secret ) = match purpose {
302
302
PaymentPurpose :: InvoicePayment { payment_preimage, payment_secret } => {
303
303
if payment_preimage. is_some ( ) {
304
- * payment_preimage
304
+ ( * payment_preimage, * payment_secret )
305
305
} else {
306
306
( self . channel_manager . get_payment_preimage ( * payment_hash, * payment_secret) . ok ( ) , * payment_secret)
307
307
}
308
308
}
309
309
PaymentPurpose :: SpontaneousPayment ( preimage) => ( Some ( * preimage) , None ) ,
310
310
} ;
311
+
312
+ let mut payments = self . inbound_payments . lock ( ) . unwrap ( ) ;
313
+ match payments. entry ( * payment_hash) {
314
+ hash_map:: Entry :: Occupied ( mut e) => {
315
+ let payment = e. get_mut ( ) ;
316
+ payment. status = PaymentStatus :: Pending ;
317
+ payment. preimage = payment_preimage;
318
+ payment. secret = payment_secret;
319
+ }
320
+ hash_map:: Entry :: Vacant ( e) => {
321
+ e. insert ( PaymentInfo {
322
+ preimage : payment_preimage,
323
+ secret : payment_secret,
324
+ status : PaymentStatus :: Pending ,
325
+ amount_msat : Some ( * amount_msat) ,
326
+ } ) ;
327
+ }
328
+ }
329
+
311
330
if let Some ( preimage) = payment_preimage {
312
331
self . channel_manager . claim_funds ( preimage) ;
313
- self . event_queue
314
- . add_event ( LdkLiteEvent :: PaymentReceived {
315
- payment_hash : * payment_hash,
316
- amount_msat : * amount_msat,
317
- } )
318
- . unwrap ( ) ;
319
332
} else {
320
333
log_error ! (
321
334
self . logger,
@@ -358,6 +371,12 @@ impl LdkEventHandler for LdkLiteEventHandler {
358
371
} ) ;
359
372
}
360
373
}
374
+ self . event_queue
375
+ . add_event ( LdkLiteEvent :: PaymentReceived {
376
+ payment_hash : * payment_hash,
377
+ amount_msat : * amount_msat,
378
+ } )
379
+ . unwrap ( ) ;
361
380
}
362
381
LdkEvent :: PaymentSent {
363
382
payment_preimage,
0 commit comments