- Event::PaymentReceived {
- payment_hash,
- payment_preimage,
- payment_secret,
- amt,
- ..
- } => {
- let mut payments = inbound_payments.lock().unwrap();
- let status = match loop_channel_manager.claim_funds(payment_preimage.unwrap()) {
- true => {
- println!(
- "\nEVENT: received payment from payment hash {} of {} millisatoshis",
- hex_utils::hex_str(&payment_hash.0),
- amt
- );
- print!("> ");
- io::stdout().flush().unwrap();
- HTLCStatus::Succeeded
- }
- _ => 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,
- amt_msat: MillisatAmount(Some(amt)),
- });
- }
- }
- }
- Event::PaymentSent { payment_preimage } => {
- let hashed = PaymentHash(Sha256::hash(&payment_preimage.0).into_inner());
- let mut payments = outbound_payments.lock().unwrap();
- for (payment_hash, payment) in payments.iter_mut() {
- if *payment_hash == hashed {
- payment.preimage = Some(payment_preimage);
- payment.status = HTLCStatus::Succeeded;
- println!(
- "\nEVENT: successfully sent payment of {} millisatoshis from \
- payment hash {:?} with preimage {:?}",
- payment.amt_msat,
- hex_utils::hex_str(&payment_hash.0),
- hex_utils::hex_str(&payment_preimage.0)
- );
- print!("> ");
- io::stdout().flush().unwrap();
- }
- }
- }
- Event::PaymentFailed { payment_hash, rejected_by_dest } => {
- print!(
- "\nEVENT: Failed to send payment to payment hash {:?}: ",
- hex_utils::hex_str(&payment_hash.0)
+ PaymentPurpose::SpontaneousPayment(preimage) => (Some(preimage), None),
+ };
+ let status = match channel_manager.claim_funds(payment_preimage.unwrap()) {
+ true => {
+ println!(
+ "\nEVENT: received payment from payment hash {} of {} millisatoshis",
+ hex_utils::hex_str(&payment_hash.0),
+ amt