Check that the node we connect to matches the user-provided chain
[ldk-sample] / src / main.rs
index b024e9354ef220429fea58c841688dde7b2b1a28..7f4b5bf4a3b2e72b79983b26ca3124a6eaed95d5 100644 (file)
@@ -168,10 +168,10 @@ async fn handle_ldk_events(
                                        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
-                                                     );
+                                                               "\nEVENT: received payment from payment hash {} of {} millisatoshis",
+                                                               hex_utils::hex_str(&payment_hash.0),
+                                                               amt
+                                                       );
                                                        print!("> ");
                                                        io::stdout().flush().unwrap();
                                                        HTLCStatus::Succeeded
@@ -290,6 +290,18 @@ async fn start_ldk() {
                }
        };
 
+       // Check that the bitcoind we've connected to is running the network we expect
+       let bitcoind_chain = bitcoind_client.get_blockchain_info().await.chain;
+       if bitcoind_chain != match args.network {
+               bitcoin::Network::Bitcoin => "main",
+               bitcoin::Network::Testnet => "test",
+               bitcoin::Network::Regtest => "regtest",
+               bitcoin::Network::Signet => "signet",
+       } {
+               println!("Chain argument ({}) didn't match bitcoind chain ({})", args.network, bitcoind_chain);
+               return;
+       }
+
        // ## Setup
        // Step 1: Initialize the FeeEstimator