Skip to content

Commit 70110d1

Browse files
Update client
This PR uses the `proxy` feature of rust-jsonrpc to create a http transport via sock5 proxy. Which can be activated using the `proxy` feature of this library. - Update Cargo.toml to include `proxy` feature. - Add a new `new_with_proxy()` constructor for client.
1 parent 400a3c0 commit 70110d1

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

client/Cargo.toml

+4-1
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@ path = "src/lib.rs"
2222
bitcoincore-rpc-json = { version = "0.16.0", path = "../json" }
2323

2424
log = "0.4.5"
25-
jsonrpc = "0.12.0"
25+
jsonrpc = { git = "https://github.com/apoelstra/rust-jsonrpc", rev = "7c94adf8aad7d55afad8f890ab1fbc79ecb7abc7"}
2626

2727
# Used for deserialization of JSON.
2828
serde = "1"
2929
serde_json = "1"
30+
31+
[features]
32+
proxy = ["jsonrpc/proxy"]

client/src/client.rs

+16
Original file line numberDiff line numberDiff line change
@@ -1215,6 +1215,22 @@ impl Client {
12151215
.map_err(|e| super::error::Error::JsonRpc(e.into()))
12161216
}
12171217

1218+
#[cfg(feature = "proxy")]
1219+
/// Creates a client to a bitcoind JSON-RPC server via SOCK5 proxy.
1220+
pub fn new_with_proxy(
1221+
url: &str,
1222+
auth: Auth,
1223+
proxy_addr: &str,
1224+
proxy_auth: Option<(&str, &str)>,
1225+
) -> Result<Self> {
1226+
let (user, pass) = auth.get_user_pass()?;
1227+
jsonrpc::client::Client::http_proxy(url, user, pass, proxy_addr, proxy_auth)
1228+
.map(|client| Client {
1229+
client,
1230+
})
1231+
.map_err(|e| super::error::Error::JsonRpc(e.into()))
1232+
}
1233+
12181234
/// Create a new Client using the given [jsonrpc::Client].
12191235
pub fn from_jsonrpc(client: jsonrpc::client::Client) -> Client {
12201236
Client {

0 commit comments

Comments
 (0)