Skip to content

Commit

Permalink
Update client
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rajarshimaitra committed Sep 28, 2022
1 parent bde02d7 commit 6230777
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
5 changes: 4 additions & 1 deletion client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ path = "src/lib.rs"
bitcoincore-rpc-json = { version = "0.16.0", path = "../json" }

log = "0.4.5"
jsonrpc = "0.13.0"
jsonrpc = { git = "https://github.com/apoelstra/rust-jsonrpc", rev = "7c94adf8aad7d55afad8f890ab1fbc79ecb7abc7"}

# Used for deserialization of JSON.
serde = "1"
serde_json = "1"

[features]
proxy = ["jsonrpc/proxy"]
16 changes: 16 additions & 0 deletions client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1217,6 +1217,22 @@ impl Client {
.map_err(|e| super::error::Error::JsonRpc(e.into()))
}

#[cfg(feature = "proxy")]
/// Creates a client to a bitcoind JSON-RPC server via SOCK5 proxy.
pub fn new_with_proxy(
url: &str,
auth: Auth,
proxy_addr: &str,
proxy_auth: Option<(&str, &str)>,
) -> Result<Self> {
let (user, pass) = auth.get_user_pass()?;
jsonrpc::client::Client::http_proxy(url, user, pass, proxy_addr, proxy_auth)
.map(|client| Client {
client,
})
.map_err(|e| super::error::Error::JsonRpc(e.into()))
}

/// Create a new Client using the given [jsonrpc::Client].
pub fn from_jsonrpc(client: jsonrpc::client::Client) -> Client {
Client {
Expand Down

0 comments on commit 6230777

Please sign in to comment.