diff --git a/client/Cargo.toml b/client/Cargo.toml index a064c6cc..481fa51a 100644 --- a/client/Cargo.toml +++ b/client/Cargo.toml @@ -4,13 +4,13 @@ version = "0.13.0" authors = [ "Steven Roose ", "Jean Pierre Dudey ", - "Dawid Ciężarkiewicz " + "Dawid Ciężarkiewicz ", ] license = "CC0-1.0" homepage = "https://github.com/rust-bitcoin/rust-bitcoincore-rpc/" repository = "https://github.com/rust-bitcoin/rust-bitcoincore-rpc/" description = "RPC client library for the Bitcoin Core JSON-RPC API." -keywords = [ "crypto", "bitcoin", "bitcoin-core", "rpc" ] +keywords = ["crypto", "bitcoin", "bitcoin-core", "rpc"] readme = "README.md" [lib] @@ -18,11 +18,11 @@ name = "bitcoincore_rpc" path = "src/lib.rs" [dependencies] -bitcoincore-rpc-json = { version = "0.13.0", path = "../json"} +bitcoincore-rpc-json = { version = "0.13.0", path = "../json" } log = "0.4.5" -jsonrpc = "0.11" +jsonrpc = "0.12.0" # Used for deserialization of JSON. serde = "1" -serde_json = "1" +serde_json = { version = "1", features = ["raw_value"] } diff --git a/client/examples/test_against_node.rs b/client/examples/test_against_node.rs index 595d854b..e658e781 100644 --- a/client/examples/test_against_node.rs +++ b/client/examples/test_against_node.rs @@ -23,7 +23,7 @@ fn main_result() -> Result<(), Error> { let user = args.next().expect("no user given"); let pass = args.next().expect("no pass given"); - let rpc = Client::new(url, Auth::UserPass(user, pass)).unwrap(); + let rpc = Client::new(&url, Auth::UserPass(user, pass)).unwrap(); let _blockchain_info = rpc.get_blockchain_info()?; diff --git a/client/src/client.rs b/client/src/client.rs index fb03fcd1..651acd96 100644 --- a/client/src/client.rs +++ b/client/src/client.rs @@ -1087,11 +1087,7 @@ pub struct Client { impl fmt::Debug for Client { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!( - f, - "bitcoincore_rpc::Client(jsonrpc::Client(last_nonce={}))", - self.client.last_nonce() - ) + write!(f, "bitcoincore_rpc::Client({:?})", self.client) } } @@ -1099,17 +1095,19 @@ impl Client { /// Creates a client to a bitcoind JSON-RPC server. /// /// Can only return [Err] when using cookie authentication. - pub fn new(url: String, auth: Auth) -> Result { + pub fn new(url: &str, auth: Auth) -> Result { let (user, pass) = auth.get_user_pass()?; - Ok(Client { - client: jsonrpc::client::Client::new(url, user, pass), - }) + jsonrpc::client::Client::simple_http(url, user, pass) + .map(|client| Client { + client, + }) + .map_err(|e| super::error::Error::JsonRpc(e.into())) } - /// Create a new Client. + /// Create a new Client using the given [jsonrpc::Client]. pub fn from_jsonrpc(client: jsonrpc::client::Client) -> Client { Client { - client: client, + client, } } @@ -1126,14 +1124,22 @@ impl RpcApi for Client { cmd: &str, args: &[serde_json::Value], ) -> Result { - let req = self.client.build_request(&cmd, &args); + let raw_args: Vec<_> = args + .iter() + .map(|a| { + let json_string = serde_json::to_string(a)?; + serde_json::value::RawValue::from_string(json_string) // we can't use to_raw_value here due to compat with Rust 1.29 + }) + .map(|a| a.map_err(|e| Error::Json(e))) + .collect::>>()?; + let req = self.client.build_request(&cmd, &raw_args); if log_enabled!(Debug) { debug!(target: "bitcoincore_rpc", "JSON-RPC request: {} {}", cmd, serde_json::Value::from(args)); } - let resp = self.client.send_request(&req).map_err(Error::from); + let resp = self.client.send_request(req).map_err(Error::from); log_response(cmd, &resp); - Ok(resp?.into_result()?) + Ok(resp?.result()?) } } @@ -1151,7 +1157,12 @@ fn log_response(cmd: &str, resp: &Result) { debug!(target: "bitcoincore_rpc", "JSON-RPC error for {}: {:?}", cmd, e); } } else if log_enabled!(Trace) { - let result = resp.result.as_ref().unwrap_or(&serde_json::Value::Null); + // we can't use to_raw_value here due to compat with Rust 1.29 + let def = serde_json::value::RawValue::from_string( + serde_json::Value::Null.to_string(), + ) + .unwrap(); + let result = resp.result.as_ref().unwrap_or(&def); trace!(target: "bitcoincore_rpc", "JSON-RPC response for {}: {}", cmd, result); } } diff --git a/contrib/test.sh b/contrib/test.sh index fe249ae7..5f24ff14 100755 --- a/contrib/test.sh +++ b/contrib/test.sh @@ -12,18 +12,13 @@ echo "PATH: \"$PATH\"" if [ "$TRAVIS_RUST_VERSION" = "1.29.0" ]; then cargo generate-lockfile --verbose - # hyper depends on log 0.3 while we depnd on 0.4, so cargo doesn't know which one to pin - LOG_4_PATCH="$(cargo update --package "log" --precise "0.4.13" 2>&1 | sed -n "s/.*log:0.4.\([0-9]*\)/\1/p")" - cargo update --package "log:0.4.$LOG_4_PATCH" --precise "0.4.13" - + cargo update --verbose --package "log" --precise "0.4.13" cargo update --verbose --package "cc" --precise "1.0.41" cargo update --verbose --package "cfg-if" --precise "0.1.9" - cargo update --verbose --package "unicode-normalization" --precise "0.1.9" cargo update --verbose --package "serde_json" --precise "1.0.39" cargo update --verbose --package "serde" --precise "1.0.98" cargo update --verbose --package "serde_derive" --precise "1.0.98" cargo update --verbose --package "byteorder" --precise "1.3.4" - cargo update --verbose --package "unicode-bidi" --precise "0.3.4" fi if [ -n "$RUSTFMTCHECK" ]; then diff --git a/integration_test/src/main.rs b/integration_test/src/main.rs index ec960a8c..0e35ee79 100644 --- a/integration_test/src/main.rs +++ b/integration_test/src/main.rs @@ -127,7 +127,7 @@ fn main() { let rpc_url = format!("{}/wallet/testwallet", get_rpc_url()); let auth = get_auth(); - let cl = Client::new(rpc_url, auth).unwrap(); + let cl = Client::new(&rpc_url, auth).unwrap(); test_get_network_info(&cl); unsafe { VERSION = cl.version().unwrap() }; @@ -969,7 +969,7 @@ fn test_create_wallet(cl: &Client) { assert_eq!(result.warning, expected_warning); let wallet_client_url = format!("{}{}{}", get_rpc_url(), "/wallet/", wallet_param.name); - let wallet_client = Client::new(wallet_client_url, get_auth()).unwrap(); + let wallet_client = Client::new(&wallet_client_url, get_auth()).unwrap(); let wallet_info = wallet_client.get_wallet_info().unwrap(); assert_eq!(wallet_info.wallet_name, wallet_param.name);