Skip to content

Commit 6230777

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 bde02d7 commit 6230777

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.13.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
@@ -1217,6 +1217,22 @@ impl Client {
12171217
.map_err(|e| super::error::Error::JsonRpc(e.into()))
12181218
}
12191219

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

0 commit comments

Comments
 (0)