From 9e65619b6fc12720242fe8feabd495b010289f3d Mon Sep 17 00:00:00 2001 From: rorp Date: Thu, 8 Dec 2022 09:47:58 -0800 Subject: [PATCH 1/9] TOR+Esplora example --- Cargo.toml | 9 +- examples/esplora_backend_with_tor.rs | 173 +++++++++++++++++++++++++++ 2 files changed, 181 insertions(+), 1 deletion(-) create mode 100644 examples/esplora_backend_with_tor.rs diff --git a/Cargo.toml b/Cargo.toml index 681da7f07..a13ece267 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -109,6 +109,8 @@ env_logger = "0.7" electrsd = "0.21" # Move back to importing from rust-bitcoin once https://github.com/rust-bitcoin/rust-bitcoin/pull/1342 is released base64 = "^0.13" +libtor = "47.8.0+0.4.7.x" +ureq = {version = "*", features = ["json", "socks-proxy"]} [[example]] name = "compact_filters_balance" @@ -146,13 +148,18 @@ required-features = ["electrum"] [[example]] name = "esplora_backend_synchronous" path = "examples/esplora_backend_synchronous.rs" -required-features = ["use-esplora-ureq"] +required-features = ["use-esplora-blocking"] [[example]] name = "esplora_backend_asynchronous" path = "examples/esplora_backend_asynchronous.rs" required-features = ["use-esplora-reqwest", "reqwest-default-tls", "async-interface"] +[[example]] +name = "esplora_backend_with_tor" +path = "examples/esplora_backend_with_tor.rs" +required-features = ["use-esplora-blocking"] + [[example]] name = "mnemonic_to_descriptors" path = "examples/mnemonic_to_descriptors.rs" diff --git a/examples/esplora_backend_with_tor.rs b/examples/esplora_backend_with_tor.rs new file mode 100644 index 000000000..e4601678b --- /dev/null +++ b/examples/esplora_backend_with_tor.rs @@ -0,0 +1,173 @@ +use std::fs::File; +use std::io::Read; +use std::str::FromStr; +use std::time::Duration; +use std::{env, thread}; + +use bdk::blockchain::Blockchain; +use bdk::{ + blockchain::esplora::EsploraBlockchain, + database::MemoryDatabase, + template::Bip84, + wallet::{export::FullyNodedExport, AddressIndex}, + KeychainKind, SyncOptions, Wallet, +}; +use bitcoin::{ + util::bip32::{self, ExtendedPrivKey}, + Network, +}; +use esplora_client::Builder; +use libtor::{LogDestination, LogLevel, Tor, TorFlag}; + +pub mod utils; + +use crate::utils::tx::build_signed_tx; + +/// This will create a wallet from an xpriv and get the balance by connecting to an Esplora server +/// over Tor network, using blocking calls with `ureq`. +/// If enough amount is available, this will send a transaction to an address. +/// Otherwise, this will display a wallet address to receive funds. +/// +/// This can be run with `cargo run --features=use-esplora-ureq --example esplora_backend_synchronous` +/// in the root folder. +fn main() { + let network = Network::Signet; + + let xpriv = "tprv8ZgxMBicQKsPcx5nBGsR63Pe8KnRUqmbJNENAfGftF3yuXoMMoVJJcYeUw5eVkm9WBPjWYt6HMWYJNesB5HaNVBaFc1M6dRjWSYnmewUMYy"; + + let esplora_url = + "http://explorerzydxu5ecjrkwceayqybizmpjjznk5izmitf2modhcusuqlid.onion/testnet/api"; + + run(&network, esplora_url, xpriv); +} + +fn create_wallet(network: &Network, xpriv: &ExtendedPrivKey) -> Wallet { + Wallet::new( + Bip84(*xpriv, KeychainKind::External), + Some(Bip84(*xpriv, KeychainKind::Internal)), + *network, + MemoryDatabase::default(), + ) + .unwrap() +} + +fn run(network: &Network, esplora_url: &str, xpriv: &str) { + let xpriv = bip32::ExtendedPrivKey::from_str(xpriv).unwrap(); + + let socks_addr = start_tor(); + + let client = Builder::new(esplora_url) + .proxy(&format!("socks5://{}", socks_addr)) + .timeout(120) // seconds + .build_blocking() + .expect("Should never fail with no proxy and timeout"); + + println!( + "Connecting to {} via SOCKS5 proxy {}", + &esplora_url, &socks_addr + ); + + let blockchain = EsploraBlockchain::from_client(client, 20); + + let wallet = create_wallet(network, &xpriv); + + wallet.sync(&blockchain, SyncOptions::default()).unwrap(); + + let address = wallet.get_address(AddressIndex::New).unwrap().address; + + println!("address: {}", address); + + let balance = wallet.get_balance().unwrap(); + + println!("Available coins in BDK wallet : {} sats", balance); + + if balance.confirmed > 10500 { + // the wallet sends the amount to itself. + let recipient_address = wallet + .get_address(AddressIndex::New) + .unwrap() + .address + .to_string(); + + let amount = 9359; + + let tx = build_signed_tx(&wallet, &recipient_address, amount); + + blockchain.broadcast(&tx).unwrap(); + + println!("tx id: {}", tx.txid()); + } else { + println!("Insufficient Funds. Fund the wallet with the address above"); + } + + let export = FullyNodedExport::export_wallet(&wallet, "exported wallet", true) + .map_err(ToString::to_string) + .map_err(bdk::Error::Generic) + .unwrap(); + + println!("------\nWallet Backup: {}", export.to_string()); +} + +pub fn start_tor() -> String { + let socks_port = 19050; + + let data_dir = format!("{}/{}", env::temp_dir().display(), "bdk-tor-example"); + let log_file_name = format!("{}/{}", &data_dir, "log"); + + println!("Staring Tor in {}", &data_dir); + + truncate_log(&log_file_name); + + Tor::new() + .flag(TorFlag::DataDirectory(data_dir.into())) + .flag(TorFlag::LogTo( + LogLevel::Notice, + LogDestination::File(log_file_name.as_str().into()), + )) + .flag(TorFlag::SocksPort(socks_port)) + .flag(TorFlag::Custom("ExitPolicy reject *:*".into())) + .flag(TorFlag::Custom("BridgeRelay 0".into())) + .start_background(); + + let mut started = false; + let mut tries = 0; + while !started { + tries += 1; + if tries > 120 { + panic!( + "It took too long to start Tor. See {} for details", + &log_file_name + ); + } + + thread::sleep(Duration::from_millis(1000)); + started = find_string_in_log(&log_file_name, &"Bootstrapped 100%".into()); + } + + println!("Tor started"); + + format!("127.0.0.1:{}", socks_port) +} + +fn truncate_log(filename: &String) { + let path = std::path::Path::new(filename); + if path.exists() { + let file = File::options() + .write(true) + .open(path) + .expect("no such file"); + file.set_len(0).expect("cannot set size to 0"); + } +} + +fn find_string_in_log(filename: &String, str: &String) -> bool { + let path = std::path::Path::new(filename); + if path.exists() { + let mut file = File::open(path).expect("cannot open log file"); + let mut buf = String::new(); + file.read_to_string(&mut buf).expect("cannot read log file"); + buf.contains(str) + } else { + false + } +} From 5c84c52ddfb567ea735113d380981fc3a681dc63 Mon Sep 17 00:00:00 2001 From: rorp Date: Sat, 24 Dec 2022 10:09:19 -0800 Subject: [PATCH 2/9] respond to the PR comments --- Cargo.toml | 2 +- examples/esplora_backend_asynchronous.rs | 2 +- examples/esplora_backend_synchronous.rs | 2 +- examples/esplora_backend_with_tor.rs | 98 +++++++----------------- 4 files changed, 30 insertions(+), 74 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a13ece267..4ff835ac3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -153,7 +153,7 @@ required-features = ["use-esplora-blocking"] [[example]] name = "esplora_backend_asynchronous" path = "examples/esplora_backend_asynchronous.rs" -required-features = ["use-esplora-reqwest", "reqwest-default-tls", "async-interface"] +required-features = ["use-esplora-async", "reqwest-default-tls", "async-interface"] [[example]] name = "esplora_backend_with_tor" diff --git a/examples/esplora_backend_asynchronous.rs b/examples/esplora_backend_asynchronous.rs index 4aa149ba3..1c170ff3b 100644 --- a/examples/esplora_backend_asynchronous.rs +++ b/examples/esplora_backend_asynchronous.rs @@ -22,7 +22,7 @@ use crate::utils::tx::build_signed_tx; /// If enough amount is available, this will send a transaction to an address. /// Otherwise, this will display a wallet address to receive funds. /// -/// This can be run with `cargo run --no-default-features --features="use-esplora-reqwest, reqwest-default-tls, async-interface" --example esplora_backend_asynchronous` +/// This can be run with `cargo run --no-default-features --features="use-esplora-async reqwest-default-tls async-interface" --example esplora_backend_asynchronous` /// in the root folder. #[tokio::main(flavor = "current_thread")] async fn main() { diff --git a/examples/esplora_backend_synchronous.rs b/examples/esplora_backend_synchronous.rs index 31907f836..033b4daba 100644 --- a/examples/esplora_backend_synchronous.rs +++ b/examples/esplora_backend_synchronous.rs @@ -22,7 +22,7 @@ use crate::utils::tx::build_signed_tx; /// If enough amount is available, this will send a transaction to an address. /// Otherwise, this will display a wallet address to receive funds. /// -/// This can be run with `cargo run --features=use-esplora-ureq --example esplora_backend_synchronous` +/// This can be run with `cargo run --features=use-esplora-blocking --example esplora_backend_synchronous` /// in the root folder. fn main() { let network = Network::Signet; diff --git a/examples/esplora_backend_with_tor.rs b/examples/esplora_backend_with_tor.rs index e4601678b..2b8c30499 100644 --- a/examples/esplora_backend_with_tor.rs +++ b/examples/esplora_backend_with_tor.rs @@ -1,58 +1,35 @@ -use std::fs::File; +use std::fs::OpenOptions; use std::io::Read; use std::str::FromStr; use std::time::Duration; use std::{env, thread}; -use bdk::blockchain::Blockchain; +use bitcoin::{util::bip32, Network}; +use esplora_client::Builder; +use libtor::{LogDestination, LogLevel, Tor, TorFlag}; + use bdk::{ - blockchain::esplora::EsploraBlockchain, - database::MemoryDatabase, - template::Bip84, - wallet::{export::FullyNodedExport, AddressIndex}, + blockchain::esplora::EsploraBlockchain, database::MemoryDatabase, template::Bip84, KeychainKind, SyncOptions, Wallet, }; -use bitcoin::{ - util::bip32::{self, ExtendedPrivKey}, - Network, -}; -use esplora_client::Builder; -use libtor::{LogDestination, LogLevel, Tor, TorFlag}; pub mod utils; -use crate::utils::tx::build_signed_tx; - -/// This will create a wallet from an xpriv and get the balance by connecting to an Esplora server +/// This will create a wallet from an xpriv and sync it by connecting to an Esplora server /// over Tor network, using blocking calls with `ureq`. -/// If enough amount is available, this will send a transaction to an address. -/// Otherwise, this will display a wallet address to receive funds. /// -/// This can be run with `cargo run --features=use-esplora-ureq --example esplora_backend_synchronous` +/// This can be run with `cargo run --features="use-esplora-blocking" --example esplora_backend_with_tor` /// in the root folder. fn main() { - let network = Network::Signet; + let network = Network::Testnet; - let xpriv = "tprv8ZgxMBicQKsPcx5nBGsR63Pe8KnRUqmbJNENAfGftF3yuXoMMoVJJcYeUw5eVkm9WBPjWYt6HMWYJNesB5HaNVBaFc1M6dRjWSYnmewUMYy"; + let xpriv_str = + "tprv8ZgxMBicQKsPcx5nBGsR63Pe8KnRUqmbJNENAfGftF3yuXoMMoVJJcYeUw5eVkm9WBPjWYt6HMWYJNesB5HaNVBaFc1M6dRjWSYnmewUMYy"; let esplora_url = "http://explorerzydxu5ecjrkwceayqybizmpjjznk5izmitf2modhcusuqlid.onion/testnet/api"; - run(&network, esplora_url, xpriv); -} - -fn create_wallet(network: &Network, xpriv: &ExtendedPrivKey) -> Wallet { - Wallet::new( - Bip84(*xpriv, KeychainKind::External), - Some(Bip84(*xpriv, KeychainKind::Internal)), - *network, - MemoryDatabase::default(), - ) - .unwrap() -} - -fn run(network: &Network, esplora_url: &str, xpriv: &str) { - let xpriv = bip32::ExtendedPrivKey::from_str(xpriv).unwrap(); + let xpriv = bip32::ExtendedPrivKey::from_str(xpriv_str).unwrap(); let socks_addr = start_tor(); @@ -69,43 +46,19 @@ fn run(network: &Network, esplora_url: &str, xpriv: &str) { let blockchain = EsploraBlockchain::from_client(client, 20); - let wallet = create_wallet(network, &xpriv); - - wallet.sync(&blockchain, SyncOptions::default()).unwrap(); - - let address = wallet.get_address(AddressIndex::New).unwrap().address; - - println!("address: {}", address); - - let balance = wallet.get_balance().unwrap(); - - println!("Available coins in BDK wallet : {} sats", balance); - - if balance.confirmed > 10500 { - // the wallet sends the amount to itself. - let recipient_address = wallet - .get_address(AddressIndex::New) - .unwrap() - .address - .to_string(); - - let amount = 9359; - - let tx = build_signed_tx(&wallet, &recipient_address, amount); - - blockchain.broadcast(&tx).unwrap(); + let wallet = Wallet::new( + Bip84(xpriv, KeychainKind::External), + Some(Bip84(xpriv, KeychainKind::Internal)), + network, + MemoryDatabase::default(), + ) + .unwrap(); - println!("tx id: {}", tx.txid()); - } else { - println!("Insufficient Funds. Fund the wallet with the address above"); - } + println!("Syncing the wallet"); - let export = FullyNodedExport::export_wallet(&wallet, "exported wallet", true) - .map_err(ToString::to_string) - .map_err(bdk::Error::Generic) - .unwrap(); + wallet.sync(&blockchain, SyncOptions::default()).unwrap(); - println!("------\nWallet Backup: {}", export.to_string()); + println!("Done!"); } pub fn start_tor() -> String { @@ -152,7 +105,7 @@ pub fn start_tor() -> String { fn truncate_log(filename: &String) { let path = std::path::Path::new(filename); if path.exists() { - let file = File::options() + let file = OpenOptions::new() .write(true) .open(path) .expect("no such file"); @@ -163,7 +116,10 @@ fn truncate_log(filename: &String) { fn find_string_in_log(filename: &String, str: &String) -> bool { let path = std::path::Path::new(filename); if path.exists() { - let mut file = File::open(path).expect("cannot open log file"); + let mut file = OpenOptions::new() + .read(true) + .open(path) + .expect("no such file"); let mut buf = String::new(); file.read_to_string(&mut buf).expect("cannot read log file"); buf.contains(str) From bb7591c5d6c7878dbd914ccdf2e15e12a365f1e2 Mon Sep 17 00:00:00 2001 From: rorp Date: Sat, 24 Dec 2022 18:01:21 -0800 Subject: [PATCH 3/9] cleanup --- examples/esplora_backend_with_tor.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/examples/esplora_backend_with_tor.rs b/examples/esplora_backend_with_tor.rs index 2b8c30499..03b5cb162 100644 --- a/examples/esplora_backend_with_tor.rs +++ b/examples/esplora_backend_with_tor.rs @@ -12,9 +12,6 @@ use bdk::{ blockchain::esplora::EsploraBlockchain, database::MemoryDatabase, template::Bip84, KeychainKind, SyncOptions, Wallet, }; - -pub mod utils; - /// This will create a wallet from an xpriv and sync it by connecting to an Esplora server /// over Tor network, using blocking calls with `ureq`. /// From 997498abd43d50d5d8fc4f7676052eb959c49c3a Mon Sep 17 00:00:00 2001 From: rorp Date: Mon, 26 Dec 2022 15:15:44 -0800 Subject: [PATCH 4/9] fix build --- examples/esplora_backend_with_tor.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/esplora_backend_with_tor.rs b/examples/esplora_backend_with_tor.rs index 03b5cb162..698c99395 100644 --- a/examples/esplora_backend_with_tor.rs +++ b/examples/esplora_backend_with_tor.rs @@ -69,7 +69,7 @@ pub fn start_tor() -> String { truncate_log(&log_file_name); Tor::new() - .flag(TorFlag::DataDirectory(data_dir.into())) + .flag(TorFlag::DataDirectory(data_dir)) .flag(TorFlag::LogTo( LogLevel::Notice, LogDestination::File(log_file_name.as_str().into()), From 7085eadd7ee601d233cf054e486179da382c2733 Mon Sep 17 00:00:00 2001 From: rorp Date: Tue, 27 Dec 2022 12:26:07 -0800 Subject: [PATCH 5/9] more cleanup --- examples/esplora_backend_with_tor.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/esplora_backend_with_tor.rs b/examples/esplora_backend_with_tor.rs index 698c99395..d97586a32 100644 --- a/examples/esplora_backend_with_tor.rs +++ b/examples/esplora_backend_with_tor.rs @@ -34,7 +34,7 @@ fn main() { .proxy(&format!("socks5://{}", socks_addr)) .timeout(120) // seconds .build_blocking() - .expect("Should never fail with no proxy and timeout"); + .unwrap(); println!( "Connecting to {} via SOCKS5 proxy {}", From 1314418f150ab4a7bdd10bf9bf011e00d7308b7c Mon Sep 17 00:00:00 2001 From: rorp Date: Wed, 28 Dec 2022 10:12:23 -0800 Subject: [PATCH 6/9] revert the transaction creation part --- examples/esplora_backend_with_tor.rs | 34 ++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/examples/esplora_backend_with_tor.rs b/examples/esplora_backend_with_tor.rs index d97586a32..5bd5e0f8a 100644 --- a/examples/esplora_backend_with_tor.rs +++ b/examples/esplora_backend_with_tor.rs @@ -12,6 +12,12 @@ use bdk::{ blockchain::esplora::EsploraBlockchain, database::MemoryDatabase, template::Bip84, KeychainKind, SyncOptions, Wallet, }; +use bdk::wallet::AddressIndex; + +pub mod utils; + +use crate::utils::tx::build_signed_tx; + /// This will create a wallet from an xpriv and sync it by connecting to an Esplora server /// over Tor network, using blocking calls with `ureq`. /// @@ -56,6 +62,34 @@ fn main() { wallet.sync(&blockchain, SyncOptions::default()).unwrap(); println!("Done!"); + + let address = wallet.get_address(AddressIndex::New).unwrap().address; + + println!("address: {}", address); + + let balance = wallet.get_balance().unwrap(); + + println!("Available coins in BDK wallet : {} sats", balance); + + if balance.confirmed > 10500 { + // the wallet sends the amount to itself. + let recipient_address = wallet + .get_address(AddressIndex::New) + .unwrap() + .address + .to_string(); + + let amount = 9359; + + let tx = build_signed_tx(&wallet, &recipient_address, amount); + + blockchain.broadcast(&tx).unwrap(); + + println!("tx id: {}", tx.txid()); + } else { + println!("Insufficient Funds. Fund the wallet with the address above"); + } + } pub fn start_tor() -> String { From 0ab67a88eacac17b825c6c89560c0e3013ddd11f Mon Sep 17 00:00:00 2001 From: rorp Date: Tue, 10 Jan 2023 11:44:28 -0800 Subject: [PATCH 7/9] make libtor optional --- Cargo.toml | 7 ++++--- examples/esplora_backend_with_tor.rs | 20 +++++++++++++++++++- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f74cc9736..7db8f95d4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,6 +39,9 @@ bitcoinconsensus = { version = "0.19.0-3", optional = true } # Needed by bdk_blockchain_tests macro and the `rpc` feature bitcoincore-rpc = { version = "0.16", optional = true } +# Needed by esplora_backend_with_tor example +libtor = { version = "47.8.0+0.4.7.x", optional = true } + # Platform-specific dependencies [target.'cfg(not(target_arch = "wasm32"))'.dependencies] tokio = { version = "1", features = ["rt", "macros"] } @@ -110,8 +113,6 @@ electrsd = "0.21" # Move back to importing from rust-bitcoin once https://github.com/rust-bitcoin/rust-bitcoin/pull/1342 is released base64 = "^0.13" assert_matches = "1.5.0" -libtor = "47.8.0+0.4.7.x" -ureq = {version = "*", features = ["json", "socks-proxy"]} [[example]] name = "compact_filters_balance" @@ -159,7 +160,7 @@ required-features = ["use-esplora-async", "reqwest-default-tls", "async-interfac [[example]] name = "esplora_backend_with_tor" path = "examples/esplora_backend_with_tor.rs" -required-features = ["use-esplora-blocking"] +required-features = ["use-esplora-blocking", "libtor"] [[example]] name = "mnemonic_to_descriptors" diff --git a/examples/esplora_backend_with_tor.rs b/examples/esplora_backend_with_tor.rs index 5bd5e0f8a..8f588536f 100644 --- a/examples/esplora_backend_with_tor.rs +++ b/examples/esplora_backend_with_tor.rs @@ -21,8 +21,26 @@ use crate::utils::tx::build_signed_tx; /// This will create a wallet from an xpriv and sync it by connecting to an Esplora server /// over Tor network, using blocking calls with `ureq`. /// -/// This can be run with `cargo run --features="use-esplora-blocking" --example esplora_backend_with_tor` +/// This can be run with `cargo run --features="use-esplora-blocking libtor" --example esplora_backend_with_tor` /// in the root folder. +/// +/// Note, that libtor requires a C compiler and C build tools. +/// +/// Here is how to install them on Ubuntu: +/// ``` +/// sudo apt install autoconf automake clang file libtool openssl pkg-config +/// ``` +/// And here is how to install them on Mac OS X: +/// ``` +/// xcode-select --install +/// brew install autoconf +/// brew install automake +/// brew install libtool +/// brew install openssl +/// brew install pkg-config +/// export LDFLAGS="-L/opt/homebrew/opt/openssl/lib" +/// export CPPFLAGS="-I/opt/homebrew/opt/openssl/include" +/// ``` fn main() { let network = Network::Testnet; From 12fb51b350d9ffaba90a278ffd2404d22d5f8f72 Mon Sep 17 00:00:00 2001 From: rorp Date: Wed, 11 Jan 2023 11:02:27 -0800 Subject: [PATCH 8/9] use EsploraBlockchain::from_config() --- examples/esplora_backend_with_tor.rs | 32 +++++++++++++++------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/examples/esplora_backend_with_tor.rs b/examples/esplora_backend_with_tor.rs index 8f588536f..9fe88807a 100644 --- a/examples/esplora_backend_with_tor.rs +++ b/examples/esplora_backend_with_tor.rs @@ -5,19 +5,20 @@ use std::time::Duration; use std::{env, thread}; use bitcoin::{util::bip32, Network}; -use esplora_client::Builder; use libtor::{LogDestination, LogLevel, Tor, TorFlag}; -use bdk::{ - blockchain::esplora::EsploraBlockchain, database::MemoryDatabase, template::Bip84, - KeychainKind, SyncOptions, Wallet, -}; +use bdk::blockchain::esplora::EsploraBlockchain; +use bdk::blockchain::esplora::EsploraBlockchainConfig; +use bdk::blockchain::ConfigurableBlockchain; +use bdk::database::MemoryDatabase; +use bdk::template::Bip84; use bdk::wallet::AddressIndex; - -pub mod utils; +use bdk::{KeychainKind, SyncOptions, Wallet}; use crate::utils::tx::build_signed_tx; +pub mod utils; + /// This will create a wallet from an xpriv and sync it by connecting to an Esplora server /// over Tor network, using blocking calls with `ureq`. /// @@ -54,18 +55,20 @@ fn main() { let socks_addr = start_tor(); - let client = Builder::new(esplora_url) - .proxy(&format!("socks5://{}", socks_addr)) - .timeout(120) // seconds - .build_blocking() - .unwrap(); - println!( "Connecting to {} via SOCKS5 proxy {}", &esplora_url, &socks_addr ); - let blockchain = EsploraBlockchain::from_client(client, 20); + let esplora_config = EsploraBlockchainConfig { + base_url: esplora_url.into(), + concurrency: None, + proxy: Some(format!("socks5://{}", socks_addr)), + stop_gap: 20, + timeout: Some(120), + }; + + let blockchain = EsploraBlockchain::from_config(&esplora_config).unwrap(); let wallet = Wallet::new( Bip84(xpriv, KeychainKind::External), @@ -107,7 +110,6 @@ fn main() { } else { println!("Insufficient Funds. Fund the wallet with the address above"); } - } pub fn start_tor() -> String { From 113c38f6756fc68491ac1376b5656c096d31d3d8 Mon Sep 17 00:00:00 2001 From: rorp Date: Thu, 16 Mar 2023 21:21:21 -0700 Subject: [PATCH 9/9] cleanup --- Cargo.toml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 36a487d43..dea593613 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,10 +15,6 @@ members = [ "nursery/coin_select" ] -#exclude = [ -# "example-crates/wallet_esplora_tor", -#] - default-members = [ "crates/bdk", "crates/chain",