diff --git a/Cargo.toml b/Cargo.toml index 54b46230..2cd33026 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,7 @@ rand = "^0.7" # Optional dependencies sled = { version = "0.34", optional = true } -electrum-client = { version = "0.3.0-beta.1", optional = true } +electrum-client = { version = "0.4.0-beta.1", optional = true } reqwest = { version = "0.10", optional = true, features = ["json"] } futures = { version = "0.3", optional = true } clap = { version = "2.33", optional = true } diff --git a/examples/repl.rs b/examples/repl.rs index 09e75f9e..ee0c9a45 100644 --- a/examples/repl.rs +++ b/examples/repl.rs @@ -102,6 +102,8 @@ fn main() { None => AnyBlockchainConfig::Electrum(ElectrumBlockchainConfig { url: matches.value_of("server").unwrap().to_string(), socks5: matches.value_of("proxy").map(ToString::to_string), + retry: 10, + timeout: 10, }), }; let wallet = Arc::new( diff --git a/src/blockchain/any.rs b/src/blockchain/any.rs index 09b7c4b5..b3df1705 100644 --- a/src/blockchain/any.rs +++ b/src/blockchain/any.rs @@ -40,7 +40,7 @@ //! # use bdk::Wallet; //! # #[cfg(feature = "electrum")] //! # { -//! let electrum_blockchain = ElectrumBlockchain::from(electrum_client::Client::new("...", None)?); +//! let electrum_blockchain = ElectrumBlockchain::from(electrum_client::Client::new("...")?); //! let wallet_electrum: Wallet = Wallet::new( //! "...", //! None, diff --git a/src/blockchain/electrum.rs b/src/blockchain/electrum.rs index a134158c..e65b53da 100644 --- a/src/blockchain/electrum.rs +++ b/src/blockchain/electrum.rs @@ -32,7 +32,7 @@ //! //! ```no_run //! # use bdk::blockchain::electrum::ElectrumBlockchain; -//! let client = electrum_client::Client::new("ssl://electrum.blockstream.info:50002", None)?; +//! let client = electrum_client::Client::new("ssl://electrum.blockstream.info:50002")?; //! let blockchain = ElectrumBlockchain::from(client); //! # Ok::<(), bdk::Error>(()) //! ``` @@ -44,7 +44,7 @@ use log::{debug, error, info, trace}; use bitcoin::{BlockHeader, Script, Transaction, Txid}; -use electrum_client::{Client, ElectrumApi}; +use electrum_client::{Client, ConfigBuilder, ElectrumApi, Socks5Config}; use self::utils::{ELSGetHistoryRes, ElectrumLikeSync}; use super::*; @@ -62,7 +62,7 @@ pub struct ElectrumBlockchain(Client); #[cfg(feature = "test-electrum")] #[bdk_blockchain_tests(crate)] fn local_electrs() -> ElectrumBlockchain { - ElectrumBlockchain::from(Client::new(&testutils::get_electrum_url(), None).unwrap()) + ElectrumBlockchain::from(Client::new(&testutils::get_electrum_url()).unwrap()) } impl std::convert::From for ElectrumBlockchain { @@ -117,7 +117,7 @@ impl Blockchain for ElectrumBlockchain { } impl ElectrumLikeSync for Client { - fn els_batch_script_get_history<'s, I: IntoIterator>( + fn els_batch_script_get_history<'s, I: IntoIterator + Clone>( &self, scripts: I, ) -> Result>, Error> { @@ -141,14 +141,14 @@ impl ElectrumLikeSync for Client { .map_err(Error::Electrum) } - fn els_batch_transaction_get<'s, I: IntoIterator>( + fn els_batch_transaction_get<'s, I: IntoIterator + Clone>( &self, txids: I, ) -> Result, Error> { self.batch_transaction_get(txids).map_err(Error::Electrum) } - fn els_batch_block_header>( + fn els_batch_block_header + Clone>( &self, heights: I, ) -> Result, Error> { @@ -161,15 +161,24 @@ impl ElectrumLikeSync for Client { pub struct ElectrumBlockchainConfig { pub url: String, pub socks5: Option, + pub retry: u8, + pub timeout: u8, } impl ConfigurableBlockchain for ElectrumBlockchain { type Config = ElectrumBlockchainConfig; fn from_config(config: &Self::Config) -> Result { - Ok(ElectrumBlockchain(Client::new( + let socks5 = config.socks5.as_ref().map(Socks5Config::new); + let electrum_config = ConfigBuilder::new() + .retry(config.retry) + .socks5(socks5)? + .timeout(config.timeout)? + .build(); + + Ok(ElectrumBlockchain(Client::from_config( config.url.as_str(), - config.socks5.as_deref(), + electrum_config, )?)) } } diff --git a/src/blockchain/utils.rs b/src/blockchain/utils.rs index d2e8f990..8fb0f342 100644 --- a/src/blockchain/utils.rs +++ b/src/blockchain/utils.rs @@ -47,17 +47,17 @@ pub struct ELSGetHistoryRes { /// Implements the synchronization logic for an Electrum-like client. #[maybe_async] pub trait ElectrumLikeSync { - fn els_batch_script_get_history<'s, I: IntoIterator>( + fn els_batch_script_get_history<'s, I: IntoIterator + Clone>( &self, scripts: I, ) -> Result>, Error>; - fn els_batch_transaction_get<'s, I: IntoIterator>( + fn els_batch_transaction_get<'s, I: IntoIterator + Clone>( &self, txids: I, ) -> Result, Error>; - fn els_batch_block_header>( + fn els_batch_block_header + Clone>( &self, heights: I, ) -> Result, Error>; diff --git a/testutils/Cargo.toml b/testutils/Cargo.toml index 77b4e450..a70550a1 100644 --- a/testutils/Cargo.toml +++ b/testutils/Cargo.toml @@ -16,4 +16,4 @@ serde_json = "1.0" serial_test = "0.4" bitcoin = "0.25" bitcoincore-rpc = "0.12" -electrum-client = "0.3.0-beta.1" +electrum-client = "0.4.0-beta.1" diff --git a/testutils/src/lib.rs b/testutils/src/lib.rs index 55b526a2..12de77cf 100644 --- a/testutils/src/lib.rs +++ b/testutils/src/lib.rs @@ -270,7 +270,7 @@ impl TestClient { pub fn new() -> Self { let url = env::var("MAGICAL_RPC_URL").unwrap_or("127.0.0.1:18443".to_string()); let client = RpcClient::new(format!("http://{}", url), get_auth()).unwrap(); - let electrum = ElectrumClient::new(&get_electrum_url(), None).unwrap(); + let electrum = ElectrumClient::new(&get_electrum_url()).unwrap(); TestClient { client, electrum } }