- Event::FundingBroadcastSafe { funding_txo, .. } => {
- Event::PaymentReceived { payment_hash, payment_secret, amt: amt_msat } => {
- let mut payments = payment_storage.lock().unwrap();
- if let Some((Some(preimage), _, _, _)) = payments.get(&payment_hash) {
- assert!(loop_channel_manager.claim_funds(
- preimage.clone(),
- &payment_secret,
- amt_msat
- ));
- println!(
- "\nEVENT: received payment from payment_hash {} of {} satoshis",
- hex_utils::hex_str(&payment_hash.0),
- amt_msat / 1000
- );
- print!("> ");
- io::stdout().flush().unwrap();
- let (_, _, ref mut status, _) = payments.get_mut(&payment_hash).unwrap();
- *status = HTLCStatus::Succeeded;
+ Event::PaymentReceived { payment_hash, payment_secret, amt } => {
+ let mut payments = inbound_payments.lock().unwrap();
+ if let Some(payment) = payments.get_mut(&payment_hash) {
+ if payment.secret == payment_secret {
+ assert!(loop_channel_manager.claim_funds(
+ payment.preimage.unwrap().clone(),
+ &payment.secret,
+ payment.amt_msat.0.unwrap(),
+ ));
+ println!(
+ "\nEVENT: received payment from payment hash {} of {} millisatoshis",
+ hex_utils::hex_str(&payment_hash.0),
+ payment.amt_msat
+ );
+ print!("> ");
+ io::stdout().flush().unwrap();
+ payment.status = HTLCStatus::Succeeded;
+ } else {
+ loop_channel_manager
+ .fail_htlc_backwards(&payment_hash, &payment.secret);
+ println!("\nERROR: we received a payment from payment hash {} but the payment secret didn't match", hex_utils::hex_str(&payment_hash.0));
+ print!("> ");
+ io::stdout().flush().unwrap();
+ payment.status = HTLCStatus::Failed;
+ }