Skip to content

Add Socks5 Proxy #249

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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
@@ -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 {
3 changes: 3 additions & 0 deletions integration_test/Cargo.toml
Original file line number Diff line number Diff line change
@@ -9,3 +9,6 @@ bitcoincore-rpc = { path = "../client" }
bitcoin = { version = "0.29.0", features = ["serde", "rand"]}
lazy_static = "1.4.0"
log = "0.4"

[features]
proxy = ["bitcoincore-rpc/proxy"]
13 changes: 11 additions & 2 deletions integration_test/src/main.rs
Original file line number Diff line number Diff line change
@@ -25,8 +25,8 @@ use bitcoin::hashes::hex::{FromHex, ToHex};
use bitcoin::hashes::Hash;
use bitcoin::secp256k1;
use bitcoin::{
Address, Amount, PackedLockTime, Network, OutPoint, PrivateKey, Script, EcdsaSighashType, SignedAmount,
Sequence, Transaction, TxIn, TxOut, Txid, Witness,
Address, Amount, EcdsaSighashType, Network, OutPoint, PackedLockTime, PrivateKey, Script,
Sequence, SignedAmount, Transaction, TxIn, TxOut, Txid, Witness,
};
use bitcoincore_rpc::bitcoincore_rpc_json::{
GetBlockTemplateModes, GetBlockTemplateRules, ScanTxOutRequest,
@@ -119,14 +119,23 @@ 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");
}

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

let rpc_url = format!("{}/wallet/testwallet", get_rpc_url());
let auth = get_auth();

#[cfg(not(feature = "proxy"))]
let cl = Client::new(&rpc_url, auth).unwrap();

#[cfg(feature = "proxy")]
let cl = Client::new_with_proxy(&rpc_url, auth, &get_proxy_url(), None).unwrap();

test_get_network_info(&cl);
unsafe { VERSION = cl.version().unwrap() };
println!("Version: {}", version());