Merge pull request #43 from TheBlueMatt/2021-12-0.0.104
[ldk-sample] / src / main.rs
index 39237d844d6969ddc341d8b5c2f802b423f4ba51..0e18bc03c52af47596608488bbad4cfe807263a4 100644 (file)
@@ -25,7 +25,7 @@ use lightning::ln::channelmanager::{
 use lightning::ln::peer_handler::{IgnoringMessageHandler, MessageHandler, SimpleArcPeerManager};
 use lightning::ln::{PaymentHash, PaymentPreimage, PaymentSecret};
 use lightning::routing::network_graph::{NetGraphMsgHandler, NetworkGraph};
-use lightning::routing::scorer::Scorer;
+use lightning::routing::scoring::Scorer;
 use lightning::util::config::UserConfig;
 use lightning::util::events::{Event, PaymentPurpose};
 use lightning::util::ser::ReadableArgs;
@@ -128,7 +128,7 @@ async fn handle_ldk_events(
                                        Network::Bitcoin => bitcoin_bech32::constants::Network::Bitcoin,
                                        Network::Testnet => bitcoin_bech32::constants::Network::Testnet,
                                        Network::Regtest => bitcoin_bech32::constants::Network::Regtest,
-                                       Network::Signet => panic!("Signet unsupported"),
+                                       Network::Signet => bitcoin_bech32::constants::Network::Signet,
                                },
                        )
                        .expect("Lightning funding tx should always be to a SegWit output")
@@ -195,16 +195,21 @@ async fn handle_ldk_events(
                                }
                        }
                }
-               Event::PaymentSent { payment_preimage, payment_hash, .. } => {
+               Event::PaymentSent { payment_preimage, payment_hash, fee_paid_msat, .. } => {
                        let mut payments = outbound_payments.lock().unwrap();
                        for (hash, payment) in payments.iter_mut() {
                                if *hash == *payment_hash {
                                        payment.preimage = Some(*payment_preimage);
                                        payment.status = HTLCStatus::Succeeded;
                                        println!(
-                                               "\nEVENT: successfully sent payment of {} millisatoshis from \
+                                               "\nEVENT: successfully sent payment of {} millisatoshis{} from \
                                                                 payment hash {:?} with preimage {:?}",
                                                payment.amt_msat,
+                                               if let Some(fee) = fee_paid_msat {
+                                                       format!(" (fee {} msat)", fee)
+                                               } else {
+                                                       "".to_string()
+                                               },
                                                hex_utils::hex_str(&payment_hash.0),
                                                hex_utils::hex_str(&payment_preimage.0)
                                        );
@@ -213,26 +218,13 @@ async fn handle_ldk_events(
                                }
                        }
                }
-               Event::PaymentPathFailed {
-                       payment_hash,
-                       rejected_by_dest,
-                       all_paths_failed,
-                       short_channel_id,
-                       ..
-               } => {
+               Event::PaymentPathSuccessful { .. } => {}
+               Event::PaymentPathFailed { .. } => {}
+               Event::PaymentFailed { payment_hash, .. } => {
                        print!(
-                               "\nEVENT: Failed to send payment{} to payment hash {:?}",
-                               if *all_paths_failed { "" } else { " along MPP path" },
+                               "\nEVENT: Failed to send payment to payment hash {:?}: exhausted payment retry attempts",
                                hex_utils::hex_str(&payment_hash.0)
                        );
-                       if let Some(scid) = short_channel_id {
-                               print!(" because of failure at channel {}", scid);
-                       }
-                       if *rejected_by_dest {
-                               println!(": re-attempting the payment will not succeed");
-                       } else {
-                               println!(": exhausted payment retry attempts");
-                       }
                        print!("> ");
                        io::stdout().flush().unwrap();
 
@@ -701,12 +693,9 @@ async fn start_ldk() {
                peer_manager.clone(),
                channel_manager.clone(),
                keys_manager.clone(),
-               network_graph.clone(),
-               scorer.clone(),
                inbound_payments,
                outbound_payments,
                ldk_data_dir.clone(),
-               logger.clone(),
                network,
        )
        .await;