- } else {
- loop_channel_manager.fail_htlc_backwards(&payment_hash, &payment_secret);
- println!("\nERROR: we received a payment for payment hash {} but didn't know the preimage", hex_utils::hex_str(&payment_hash.0));
- print!("> ");
- io::stdout().flush().unwrap();
- payments.insert(
- payment_hash,
- PaymentInfo {
- preimage: None,
- secret: payment_secret,
- status: HTLCStatus::Failed,
+ _ => HTLCStatus::Failed,
+ };
+ match payments.entry(payment_hash) {
+ Entry::Occupied(mut e) => {
+ let payment = e.get_mut();
+ payment.status = status;
+ payment.preimage = Some(payment_preimage.unwrap());
+ payment.secret = Some(payment_secret);
+ }
+ Entry::Vacant(e) => {
+ e.insert(PaymentInfo {
+ preimage: Some(payment_preimage.unwrap()),
+ secret: Some(payment_secret),
+ status,