diff --git a/client/Cargo.toml b/client/Cargo.toml index 90b92fdc..a0f56f11 100644 --- a/client/Cargo.toml +++ b/client/Cargo.toml @@ -27,6 +27,7 @@ bitcoincore-rpc-json = { version = "0.19.0", path = "../json" } log = "0.4.5" jsonrpc = { version = "0.18.0", features = ["minreq_http"] } +minreq = { version = "2.7.0", features = ["json-using-serde", "https"] } # Used for deserialization of JSON. serde = "1" diff --git a/client/src/client.rs b/client/src/client.rs index 2f809a79..89f9a53b 100644 --- a/client/src/client.rs +++ b/client/src/client.rs @@ -19,6 +19,7 @@ use crate::bitcoin; use crate::bitcoin::consensus::encode; use bitcoin::hex::DisplayHex; use jsonrpc; +use jsonrpc::minreq_http::MinreqHttpTransport; use serde; use serde_json; @@ -1293,6 +1294,21 @@ impl Client { .map_err(|e| super::error::Error::JsonRpc(e.into())) } + pub fn new_with_minreq(url: &str, auth: Auth) -> Result { + let (user, pass) = auth.get_user_pass()?; + if user.is_none() { + return Err(Error::ReturnedError("User is None".to_string())); + } + let transport = MinreqHttpTransport::builder() + .url(url) + .map_err(|e| super::error::Error::JsonRpc(e.into()))? + .basic_auth(user.unwrap(), pass) + .build(); + Ok(Client { + client: jsonrpc::client::Client::with_transport(transport), + }) + } + /// Create a new Client using the given [jsonrpc::Client]. pub fn from_jsonrpc(client: jsonrpc::client::Client) -> Client { Client {