Skip to content

Feat/use minreq #385

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
16 changes: 16 additions & 0 deletions client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<Self> {
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 {
Expand Down
Loading