@@ -298,24 +298,37 @@ impl LdkEventHandler for LdkLiteEventHandler {
298298 hex_utils:: to_string( & payment_hash. 0 ) ,
299299 amount_msat,
300300 ) ;
301- let payment_preimage = match purpose {
301+ let ( payment_preimage, payment_secret ) = match purpose {
302302 PaymentPurpose :: InvoicePayment { payment_preimage, payment_secret } => {
303303 if payment_preimage. is_some ( ) {
304- * payment_preimage
304+ ( * payment_preimage, * payment_secret )
305305 } else {
306306 ( self . channel_manager . get_payment_preimage ( * payment_hash, * payment_secret) . ok ( ) , * payment_secret)
307307 }
308308 }
309309 PaymentPurpose :: SpontaneousPayment ( preimage) => ( Some ( * preimage) , None ) ,
310310 } ;
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+
311330 if let Some ( preimage) = payment_preimage {
312331 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 ( ) ;
319332 } else {
320333 log_error ! (
321334 self . logger,
@@ -358,6 +371,12 @@ impl LdkEventHandler for LdkLiteEventHandler {
358371 } ) ;
359372 }
360373 }
374+ self . event_queue
375+ . add_event ( LdkLiteEvent :: PaymentReceived {
376+ payment_hash : * payment_hash,
377+ amount_msat : * amount_msat,
378+ } )
379+ . unwrap ( ) ;
361380 }
362381 LdkEvent :: PaymentSent {
363382 payment_preimage,
0 commit comments