From: Matt Corallo Date: Tue, 4 May 2021 17:10:18 +0000 (+0000) Subject: Make an initial dummy RPC call to check that the connection works X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=a7a3f78356c28b252744f2a2743b0266686b4d4d;p=ldk-sample Make an initial dummy RPC call to check that the connection works This provides a much better panic message if the RPC password is incorrect. --- diff --git a/src/bitcoind_client.rs b/src/bitcoind_client.rs index 58510ae..6d29ca0 100644 --- a/src/bitcoind_client.rs +++ b/src/bitcoind_client.rs @@ -67,7 +67,10 @@ 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::("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 = HashMap::new(); fees.insert(Target::Background, AtomicU32::new(253)); fees.insert(Target::Normal, AtomicU32::new(2000));