Merge pull request #5 from TheBlueMatt/main
authorJeffrey Czyz <jkczyz@gmail.com>
Tue, 4 May 2021 19:18:02 +0000 (12:18 -0700)
committerGitHub <noreply@github.com>
Tue, 4 May 2021 19:18:02 +0000 (12:18 -0700)
Trivial Usability Fixes

Cargo.lock
Cargo.toml
src/bitcoind_client.rs
src/cli.rs
src/convert.rs
src/main.rs

index 243c2c078fca797ec866aa8635c3837653f3e1a5..5bc89f35e721bb8fe60969bf91d8f2a6f4134e09 100644 (file)
@@ -255,16 +255,18 @@ checksum = "b7282d924be3275cec7f6756ff4121987bc6481325397dde6ba3e7802b1a8b1c"
 
 [[package]]
 name = "lightning"
-version = "0.0.13"
-source = "git+https://github.com/rust-bitcoin/rust-lightning?rev=d4d322580994857b1222488f8467311d6db61482#d4d322580994857b1222488f8467311d6db61482"
+version = "0.0.14"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6f99cce0a9a62b73144dad86cf9d722379db3de049fec5df8f5437a6c92542ab"
 dependencies = [
  "bitcoin",
 ]
 
 [[package]]
 name = "lightning-background-processor"
-version = "0.0.13"
-source = "git+https://github.com/rust-bitcoin/rust-lightning?rev=d4d322580994857b1222488f8467311d6db61482#d4d322580994857b1222488f8467311d6db61482"
+version = "0.0.14"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7cd5d18b3f9c4f7ab6c5554411f2e6618f98e4b7dcb6426be2266267dfa8d499"
 dependencies = [
  "bitcoin",
  "lightning",
@@ -273,8 +275,9 @@ dependencies = [
 
 [[package]]
 name = "lightning-block-sync"
-version = "0.0.13"
-source = "git+https://github.com/rust-bitcoin/rust-lightning?rev=d4d322580994857b1222488f8467311d6db61482#d4d322580994857b1222488f8467311d6db61482"
+version = "0.0.14"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "40a773c6711f798c04e14bff4a83220c7d47d9f76cecf6cc5754693b2600f7d1"
 dependencies = [
  "bitcoin",
  "chunked_transfer",
@@ -286,8 +289,9 @@ dependencies = [
 
 [[package]]
 name = "lightning-invoice"
-version = "0.4.0"
-source = "git+https://github.com/rust-bitcoin/rust-lightning?rev=d4d322580994857b1222488f8467311d6db61482#d4d322580994857b1222488f8467311d6db61482"
+version = "0.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c0738f41c16a3501726c4ada573cad59835e4ee66c1e7d08a4ae4d6b7baa9268"
 dependencies = [
  "bech32 0.7.2",
  "bitcoin_hashes",
@@ -298,8 +302,9 @@ dependencies = [
 
 [[package]]
 name = "lightning-net-tokio"
-version = "0.0.13"
-source = "git+https://github.com/rust-bitcoin/rust-lightning?rev=d4d322580994857b1222488f8467311d6db61482#d4d322580994857b1222488f8467311d6db61482"
+version = "0.0.14"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c593aacfff258a317513a409088b92bc1dc8fb28a4a8f2826b827553435e8d9b"
 dependencies = [
  "bitcoin",
  "lightning",
@@ -308,8 +313,9 @@ dependencies = [
 
 [[package]]
 name = "lightning-persister"
-version = "0.0.13"
-source = "git+https://github.com/rust-bitcoin/rust-lightning?rev=d4d322580994857b1222488f8467311d6db61482#d4d322580994857b1222488f8467311d6db61482"
+version = "0.0.14"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "83dc14f2dfed0a6eaddae9e2b54998e327f63fc0bcb64bdb3133a7f20c1536e0"
 dependencies = [
  "bitcoin",
  "libc",
index b32be572ffb1b81c922ee42df3333ecbacddcd96..a51252ec914c7790ddbf14277aaeea052daab7fb 100644 (file)
@@ -8,36 +8,26 @@ edition = "2018"
 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
 
 [dependencies]
-# lightning-background-processor = { git = "https://github.com/rust-bitcoin/rust-lightning", branch = "main" }
-lightning-background-processor = { git = "https://github.com/rust-bitcoin/rust-lightning", rev = "d4d322580994857b1222488f8467311d6db61482" }
-# lightning-background-processor = { path = "../rust-lightning/lightning-background-processor" }
+lightning = "0.0.14"
+lightning-block-sync = { version = "0.0.14", features = [ "rpc-client" ] }
+lightning-invoice = "0.5"
+lightning-net-tokio = "0.0.14"
+lightning-persister = "0.0.14"
+lightning-background-processor = "0.0.14"
+
 base64 = "0.13.0"
 bitcoin = "0.26"
 bitcoin-bech32 = "0.7"
 bech32 = "0.7"
 hex = "0.3"
 
-# lightning = { git = "https://github.com/rust-bitcoin/rust-lightning", branch = "main" }
-lightning = { git = "https://github.com/rust-bitcoin/rust-lightning", rev = "d4d322580994857b1222488f8467311d6db61482" }
-# lightning = { path = "../rust-lightning/lightning" }
-
-# lightning-block-sync = { git = "https://github.com/rust-bitcoin/rust-lightning", features = ["rpc-client"], branch = "main" }
-lightning-block-sync = { git = "https://github.com/rust-bitcoin/rust-lightning", features = ["rpc-client"], rev = "d4d322580994857b1222488f8467311d6db61482" }
-# lightning-block-sync = { path = "../rust-lightning/lightning-block-sync", features = ["rpc-client"] }
-
-# lightning-invoice = { git = "https://github.com/rust-bitcoin/rust-lightning", branch = "main" }
-lightning-invoice = { git = "https://github.com/rust-bitcoin/rust-lightning", rev = "d4d322580994857b1222488f8467311d6db61482" }
-# lightning-invoice = { path = "../rust-lightning/lightning-invoice" }
-
-# lightning-net-tokio = { git = "https://github.com/rust-bitcoin/rust-lightning", branch = "main" }
-lightning-net-tokio = { git = "https://github.com/rust-bitcoin/rust-lightning", rev = "d4d322580994857b1222488f8467311d6db61482" }
-# lightning-net-tokio = { path = "../rust-lightning/lightning-net-tokio" }
-
-# lightning-persister = { git = "https://github.com/rust-bitcoin/rust-lightning", branch = "main" }
-lightning-persister = { git = "https://github.com/rust-bitcoin/rust-lightning", rev = "d4d322580994857b1222488f8467311d6db61482" }
-# lightning-persister = { path = "../rust-lightning/lightning-persister" }
-
 time = "0.2"
 rand = "0.4"
 serde_json = { version = "1.0" }
 tokio = { version = "1.0", features = [ "io-util", "macros", "rt", "rt-multi-thread", "sync", "net", "time" ] }
+
+[profile.release]
+panic = "abort"
+
+[profile.dev]
+panic = "abort"
index 58510ae736bd894cbfece045db24ef4ddd9ded31..7dc67c5fdc51451689798646a5e1b270871c444d 100644 (file)
@@ -67,7 +67,14 @@ impl BitcoindClient {
                let http_endpoint = HttpEndpoint::for_host(host.clone()).with_port(port);
                let rpc_credentials =
                        base64::encode(format!("{}:{}", rpc_user.clone(), rpc_password.clone()));
-               let bitcoind_rpc_client = RpcClient::new(&rpc_credentials, http_endpoint)?;
+               let mut bitcoind_rpc_client = RpcClient::new(&rpc_credentials, http_endpoint)?;
+               let _dummy = bitcoind_rpc_client
+                       .call_method::<BlockchainInfo>("getblockchaininfo", &vec![])
+                       .await
+                       .map_err(|_| {
+                               std::io::Error::new(std::io::ErrorKind::PermissionDenied,
+                               "Failed to make initial call to bitcoind - please check your RPC user/password and access settings")
+                       })?;
                let mut fees: HashMap<Target, AtomicU32> = HashMap::new();
                fees.insert(Target::Background, AtomicU32::new(253));
                fees.insert(Target::Normal, AtomicU32::new(2000));
index c5dda5fc33e11f19cad785bb5e042855e7babf68..32119aef9ea14baa6b68f12b527102f0bb08ea74 100644 (file)
@@ -103,7 +103,9 @@ pub(crate) async fn poll_for_user_input(
        event_notifier: mpsc::Sender<()>, ldk_data_dir: String, logger: Arc<FilesystemLogger>,
        network: Network,
 ) {
-       println!("LDK startup successful. To view available commands: \"help\".\nLDK logs are available at <your-supplied-ldk-data-dir-path>/.ldk/logs");
+       println!("LDK startup successful. To view available commands: \"help\".");
+       println!("LDK logs are available at <your-supplied-ldk-data-dir-path>/.ldk/logs");
+       println!("Local Node ID is {}.", channel_manager.get_our_node_id());
        let stdin = io::stdin();
        print!("> ");
        io::stdout().flush().unwrap(); // Without flushing, the `>` doesn't print
index 7dbd8cceb13caca3938a35077f205b1ff96aa386..a652980e3ddbd9a20e6cbf5e54092938a1ffb5ac 100644 (file)
@@ -72,6 +72,7 @@ impl TryInto<FeeResponse> for JsonResponse {
 pub struct BlockchainInfo {
        pub latest_height: usize,
        pub latest_blockhash: BlockHash,
+       pub chain: String,
 }
 
 impl TryInto<BlockchainInfo> for JsonResponse {
@@ -81,6 +82,7 @@ impl TryInto<BlockchainInfo> for JsonResponse {
                        latest_height: self.0["blocks"].as_u64().unwrap() as usize,
                        latest_blockhash: BlockHash::from_hex(self.0["bestblockhash"].as_str().unwrap())
                                .unwrap(),
+                       chain: self.0["chain"].as_str().unwrap().to_string(),
                })
        }
 }
index b024e9354ef220429fea58c841688dde7b2b1a28..33e5eb5733d30c151bb97adf1260709d593f1b57 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,22 @@ 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