Skip to content

Commit

Permalink
Cherry pick changes of rust-bitcoin#249
Browse files Browse the repository at this point in the history
into `0.17.0`
  • Loading branch information
sectore committed Apr 21, 2023
1 parent e265d32 commit d4cf3cf
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
5 changes: 4 additions & 1 deletion client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ path = "src/lib.rs"
bitcoincore-rpc-json = { version = "0.17.0", path = "../json" }

log = "0.4.5"
jsonrpc = "0.14.0"
jsonrpc = "0.14.1"

# Used for deserialization of JSON.
serde = "1"
serde_json = "1"
bitcoin-private = "0.1.0"

[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 @@ -1289,6 +1289,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
3 changes: 3 additions & 0 deletions integration_test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ bitcoincore-rpc = { path = "../client" }
bitcoin = { version = "0.30.0", features = ["serde", "rand"]}
lazy_static = "1.4.0"
log = "0.4"

[features]
proxy = ["bitcoincore-rpc/proxy"]
16 changes: 15 additions & 1 deletion integration_test/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,25 @@ fn get_auth() -> bitcoincore_rpc::Auth {
};
}

#[cfg(feature = "proxy")]
fn get_proxy_url() -> String {
return std::env::var("PROXY_URL").expect("PROXY_URL must be set in proxy feature");
}

#[cfg(not(feature = "proxy"))]
fn new_wallet_client(wallet_name: &str) -> Client {
let url = format!("{}{}{}", get_rpc_url(), "/wallet/", wallet_name);
let url = format!("{}{}{}", get_rpc_url(), "/wallet/", wallet_name);
Client::new(&url, get_auth()).unwrap()
}


#[cfg(feature = "proxy")]
fn new_wallet_client(wallet_name: &str) -> Client {
let url = format!("{}{}{}", get_rpc_url(), "/wallet/", wallet_name);
Client::new_with_proxy(&url, auth, &get_proxy_url(), None).unwrap()
}


fn main() {
log::set_logger(&LOGGER).map(|()| log::set_max_level(log::LevelFilter::max())).unwrap();

Expand Down

0 comments on commit d4cf3cf

Please sign in to comment.