Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updates to newer jsonrpc dependencies containing swappable transports #180

Merged
merged 2 commits into from Jul 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions client/Cargo.toml
Expand Up @@ -4,24 +4,24 @@ version = "0.13.0"
authors = [
"Steven Roose <steven@stevenroose.org>",
"Jean Pierre Dudey <jeandudey@hotmail.com>",
"Dawid Ciężarkiewicz <dpc@dpc.pw>"
"Dawid Ciężarkiewicz <dpc@dpc.pw>",
]
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]
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"
Expand Down
2 changes: 1 addition & 1 deletion client/examples/test_against_node.rs
Expand Up @@ -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()?;

Expand Down
41 changes: 26 additions & 15 deletions client/src/client.rs
Expand Up @@ -1087,29 +1087,27 @@ 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)
}
}

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<Self> {
pub fn new(url: &str, auth: Auth) -> Result<Self> {
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,
}
}

Expand All @@ -1126,14 +1124,22 @@ impl RpcApi for Client {
cmd: &str,
args: &[serde_json::Value],
) -> Result<T> {
let req = self.client.build_request(&cmd, &args);
let raw_args: Vec<_> = args
.iter()
.map(|a| {
let json_string = serde_json::to_string(a)?;
sgeisler marked this conversation as resolved.
Show resolved Hide resolved
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::<Result<Vec<_>>>()?;
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()?)
}
}

Expand All @@ -1151,7 +1157,12 @@ fn log_response(cmd: &str, resp: &Result<jsonrpc::Response>) {
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(
sgeisler marked this conversation as resolved.
Show resolved Hide resolved
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);
}
}
Expand Down
7 changes: 1 addition & 6 deletions contrib/test.sh
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions integration_test/src/main.rs
Expand Up @@ -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() };
Expand Down Expand Up @@ -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);
Expand Down