Skip to content

Commit

Permalink
add tor proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Trevethan authored and ssantos21 committed Dec 22, 2023
1 parent 844b00a commit 2e797bd
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 11 deletions.
3 changes: 2 additions & 1 deletion clients/standalone-rust/Settings.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
statechain_entity = "http://127.0.0.1:8000"
statechain_entity = "caqa7fv4wmmhj7owhmkdq23nfejxoibsi74qos2ggldbtg75u45g4uid.onion"
tor_proxy = ""socks5://127.0.0.1:9150"
electrum_server = "tcp://127.0.0.1:50001"
network = "signet"
fee_rate_tolerance = 5
Expand Down
4 changes: 4 additions & 0 deletions clients/standalone-rust/src/client_config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ use sqlx::{Sqlite, migrate::MigrateDatabase, SqlitePool};
pub struct ClientConfig {
/// Active lockbox server addresses
pub statechain_entity: String,
/// Tor SOCKS5 proxy address
pub tor_proxy: String,
/// Electrum client
pub electrum_client: electrum_client::Client,
/// Electrum server url
Expand All @@ -28,6 +30,7 @@ impl ClientConfig {
.unwrap();

let statechain_entity = settings.get_string("statechain_entity").unwrap();
let tor_proxy = settings.get_string("tor_proxy").unwrap();
let electrum_server = settings.get_string("electrum_server").unwrap();
let network = settings.get_string("network").unwrap();
let fee_rate_tolerance = settings.get_int("fee_rate_tolerance").unwrap() as u32;
Expand Down Expand Up @@ -66,6 +69,7 @@ impl ClientConfig {

ClientConfig {
statechain_entity,
tor_proxy,
electrum_client,
electrum_server_url: electrum_server,
network,
Expand Down
9 changes: 8 additions & 1 deletion clients/standalone-rust/src/deposit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,14 @@ pub async fn init(client_config: &ClientConfig, address_data: &key_derivation::A
let endpoint = client_config.statechain_entity.clone();
let path = "deposit/init/pod";

let client: reqwest::Client = reqwest::Client::new();
let tor_proxy = client_config.tor_proxy.clone();

let mut client: reqwest::Client = reqwest::Client::new();
if tor_proxy != "".to_string() {
let tor_proxy = reqwest::Proxy::all(tor_proxy).unwrap();
client = reqwest::Client::builder().proxy(tor_proxy).build().unwrap();
}

let request = client.post(&format!("{}/{}", endpoint, path));

let value = match request.json(&deposit_request_payload).send().await {
Expand Down
16 changes: 14 additions & 2 deletions clients/standalone-rust/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,13 @@ async fn musig_sign_psbt_taproot(
let endpoint = client_config.statechain_entity.clone();
let path = "sign/first";

let client: reqwest::Client = reqwest::Client::new();
let tor_proxy = client_config.tor_proxy.clone();

let mut client: reqwest::Client = reqwest::Client::new();
if tor_proxy != "".to_string() {
let tor_proxy = reqwest::Proxy::all(tor_proxy).unwrap();
client = reqwest::Client::builder().proxy(tor_proxy).build().unwrap();
}
let request = client.post(&format!("{}/{}", endpoint, path));

let sign_first_request_payload = SignFirstRequestPayload {
Expand Down Expand Up @@ -324,7 +330,13 @@ async fn musig_sign_psbt_taproot(

let path = "sign/second";

let client: reqwest::Client = reqwest::Client::new();
let tor_proxy = client_config.tor_proxy.clone();

let mut client: reqwest::Client = reqwest::Client::new();
if tor_proxy != "".to_string() {
let tor_proxy = reqwest::Proxy::all(tor_proxy).unwrap();
client = reqwest::Client::builder().proxy(tor_proxy).build().unwrap();
}
let request = client.post(&format!("{}/{}", endpoint, path));

let value = match request.json(&payload).send().await {
Expand Down
24 changes: 21 additions & 3 deletions clients/standalone-rust/src/transfer_receiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ async fn get_msg_addr(auth_pubkey: &secp256k1_zkp::PublicKey, statechain_entity_
let endpoint = statechain_entity_url;
let path = format!("transfer/get_msg_addr/{}", auth_pubkey.to_string());

let client: reqwest::Client = reqwest::Client::new();
let tor_proxy = client_config.tor_proxy.clone();

let mut client: reqwest::Client = reqwest::Client::new();
if tor_proxy != "".to_string() {
let tor_proxy = reqwest::Proxy::all(tor_proxy).unwrap();
client = reqwest::Client::builder().proxy(tor_proxy).build().unwrap();
}
let request = client.get(&format!("{}/{}", endpoint, path));

let value = match request.send().await {
Expand Down Expand Up @@ -247,7 +253,13 @@ async fn get_statechain_info(statechain_id: &str, statechain_entity_url: &str) -
println!("statechain_id: {}", statechain_id.to_string());
println!("path: {}", path);

let client: reqwest::Client = reqwest::Client::new();
let tor_proxy = client_config.tor_proxy.clone();

let mut client: reqwest::Client = reqwest::Client::new();
if tor_proxy != "".to_string() {
let tor_proxy = reqwest::Proxy::all(tor_proxy).unwrap();
client = reqwest::Client::builder().proxy(tor_proxy).build().unwrap();
}
let request = client.get(&format!("{}/{}", endpoint, path));

let value = match request.send().await {
Expand Down Expand Up @@ -400,7 +412,13 @@ async fn process_encrypted_message(
let endpoint = client_config.statechain_entity.clone();
let path = "transfer/receiver";

let client = reqwest::Client::new();
let tor_proxy = client_config.tor_proxy.clone();

let mut client: reqwest::Client = reqwest::Client::new();
if tor_proxy != "".to_string() {
let tor_proxy = reqwest::Proxy::all(tor_proxy).unwrap();
client = reqwest::Client::builder().proxy(tor_proxy).build().unwrap();
}
let request = client.post(&format!("{}/{}", endpoint, path));

let value = match request.json(&transfer_receiver_request_payload).send().await {
Expand Down
16 changes: 14 additions & 2 deletions clients/standalone-rust/src/transfer_sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ async fn get_new_x1(client_config: &ClientConfig, statechain_id: &str, signed_s
let endpoint = client_config.statechain_entity.clone();
let path = "transfer/sender";

let client = reqwest::Client::new();
let tor_proxy = client_config.tor_proxy.clone();

let mut client: reqwest::Client = reqwest::Client::new();
if tor_proxy != "".to_string() {
let tor_proxy = reqwest::Proxy::all(tor_proxy).unwrap();
client = reqwest::Client::builder().proxy(tor_proxy).build().unwrap();
}
let request = client.post(&format!("{}/{}", endpoint, path));

let transfer_sender_request_payload = TransferSenderRequestPayload {
Expand Down Expand Up @@ -163,7 +169,13 @@ pub async fn init(client_config: &ClientConfig, recipient_address: &str, statech
let endpoint = client_config.statechain_entity.clone();
let path = "transfer/update_msg";

let client = reqwest::Client::new();
let tor_proxy = client_config.tor_proxy.clone();

let mut client: reqwest::Client = reqwest::Client::new();
if tor_proxy != "".to_string() {
let tor_proxy = reqwest::Proxy::all(tor_proxy).unwrap();
client = reqwest::Client::builder().proxy(tor_proxy).build().unwrap();
}
let request = client.post(&format!("{}/{}", endpoint, path));

match request.json(&transfer_update_msg_request_payload).send().await {
Expand Down
8 changes: 7 additions & 1 deletion clients/standalone-rust/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ pub async fn info_config(statechain_entity_url: &str, electrum_client: &electrum

let path = "info/config";

let client: reqwest::Client = reqwest::Client::new();
let tor_proxy = client_config.tor_proxy.clone();

let mut client: reqwest::Client = reqwest::Client::new();
if tor_proxy != "".to_string() {
let tor_proxy = reqwest::Proxy::all(tor_proxy).unwrap();
client = reqwest::Client::builder().proxy(tor_proxy).build().unwrap();
}
let request = client.get(&format!("{}/{}", statechain_entity_url, path));

let value = match request.send().await {
Expand Down
8 changes: 7 additions & 1 deletion clients/standalone-rust/src/withdraw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,13 @@ pub async fn execute(client_config: &ClientConfig, statechain_id: &str, to_addre
let endpoint = client_config.statechain_entity.clone();
let path = "delete_statechain";

let client: reqwest::Client = reqwest::Client::new();
let tor_proxy = client_config.tor_proxy.clone();

let mut client: reqwest::Client = reqwest::Client::new();
if tor_proxy != "".to_string() {
let tor_proxy = reqwest::Proxy::all(tor_proxy).unwrap();
client = reqwest::Client::builder().proxy(tor_proxy).build().unwrap();
}
let request = client.delete(&format!("{}/{}", endpoint, path));

let _ = match request.json(&delete_statechain_payload).send().await {
Expand Down

0 comments on commit 2e797bd

Please sign in to comment.