Skip to content

Commit 9122405

Browse files
committed
add client with minreq
1 parent b7176c8 commit 9122405

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

client/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ bitcoincore-rpc-json = { version = "0.19.0", path = "../json" }
2727

2828
log = "0.4.5"
2929
jsonrpc = { version = "0.18.0", features = ["minreq_http"] }
30+
minreq = { version = "2.7.0", features = ["json-using-serde", "https"] }
3031

3132
# Used for deserialization of JSON.
3233
serde = "1"

client/src/client.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use crate::bitcoin;
1919
use crate::bitcoin::consensus::encode;
2020
use bitcoin::hex::DisplayHex;
2121
use jsonrpc;
22+
use jsonrpc::minreq_http::MinreqHttpTransport;
2223
use serde;
2324
use serde_json;
2425

@@ -1293,6 +1294,21 @@ impl Client {
12931294
.map_err(|e| super::error::Error::JsonRpc(e.into()))
12941295
}
12951296

1297+
pub fn new_with_minreq(url: &str, auth: Auth) -> Result<Self> {
1298+
let (user, pass) = auth.get_user_pass()?;
1299+
if user.is_none() {
1300+
return Err(Error::ReturnedError("User is None".to_string()));
1301+
}
1302+
let transport = MinreqHttpTransport::builder()
1303+
.url(url)
1304+
.map_err(|e| super::error::Error::JsonRpc(e.into()))?
1305+
.basic_auth(user.unwrap(), pass)
1306+
.build();
1307+
Ok(Client {
1308+
client: jsonrpc::client::Client::with_transport(transport),
1309+
})
1310+
}
1311+
12961312
/// Create a new Client using the given [jsonrpc::Client].
12971313
pub fn from_jsonrpc(client: jsonrpc::client::Client) -> Client {
12981314
Client {

0 commit comments

Comments
 (0)