diff --git a/Cargo.lock b/Cargo.lock index 2df5047e..604d3e4f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -255,9 +255,9 @@ checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" [[package]] name = "bdk" -version = "0.4.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "daeccaea73c9fc27e218e2a4402070707fb8354afd30fecd4a1c9a0bea8b79c4" +checksum = "4260e70501c2f9d6fb2915cf2be2f5b8ba57743e527834de5de6e371827f1e19" dependencies = [ "async-trait", "bdk-macros", @@ -275,9 +275,9 @@ dependencies = [ [[package]] name = "bdk-macros" -version = "0.3.0" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b96757dbe9c7e0a8f0635c5366464d9c713528e111f47490e96385f70d6a67a6" +checksum = "b45570b78250774145859a8f85bfdb6e310663fc82640d7e159a44b1386074a2" dependencies = [ "proc-macro2", "quote", @@ -899,9 +899,9 @@ checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" [[package]] name = "electrum-client" -version = "0.6.0" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21453800c95bb1aaa57490458c42d60c6277cb8a3e386030ec2381d5c2d4fa77" +checksum = "4cab4d90cc575a7daab4cfed9e315912a88071bc47462e6be57516a2f01ccc89" dependencies = [ "bitcoin", "log", diff --git a/swap/Cargo.toml b/swap/Cargo.toml index 27d1465c..e6502c98 100644 --- a/swap/Cargo.toml +++ b/swap/Cargo.toml @@ -16,7 +16,7 @@ async-trait = "0.1" atty = "0.2" backoff = { version = "0.3", features = ["tokio"] } base64 = "0.13" -bdk = { version = "0.4" } +bdk = { version = "0.5" } big-bytes = "1" bitcoin = { version = "0.26", features = ["rand", "use-serde"] } config = { version = "0.11", default-features = false, features = ["toml"] } diff --git a/swap/src/bitcoin/wallet.rs b/swap/src/bitcoin/wallet.rs index dbd38a3f..97ae5424 100644 --- a/swap/src/bitcoin/wallet.rs +++ b/swap/src/bitcoin/wallet.rs @@ -3,10 +3,10 @@ use crate::bitcoin::{Address, Amount, Transaction}; use crate::env; use ::bitcoin::util::psbt::PartiallySignedTransaction; use ::bitcoin::Txid; -use anyhow::{anyhow, bail, Context, Result}; +use anyhow::{bail, Context, Result}; use bdk::blockchain::{noop_progress, Blockchain, ElectrumBlockchain}; use bdk::descriptor::Segwitv0; -use bdk::electrum_client::{self, ElectrumApi, GetHistoryRes}; +use bdk::electrum_client::{ElectrumApi, GetHistoryRes}; use bdk::keys::DerivableKey; use bdk::{FeeRate, KeychainKind}; use bitcoin::Script; @@ -35,12 +35,8 @@ impl Wallet { key: impl DerivableKey + Clone, env_config: env::Config, ) -> Result { - // Workaround for https://github.com/bitcoindevkit/rust-electrum-client/issues/47. - let config = electrum_client::ConfigBuilder::default().retry(2).build(); - - let client = - bdk::electrum_client::Client::from_config(electrum_rpc_url.as_str(), config.clone()) - .map_err(|e| anyhow!("Failed to init electrum rpc client: {:?}", e))?; + let client = bdk::electrum_client::Client::new(electrum_rpc_url.as_str()) + .context("Failed to initialize Electrum RPC client")?; let db = bdk::sled::open(wallet_dir)?.open_tree(SLED_TREE_NAME)?; @@ -52,8 +48,8 @@ impl Wallet { ElectrumBlockchain::from(client), )?; - let electrum = bdk::electrum_client::Client::from_config(electrum_rpc_url.as_str(), config) - .map_err(|e| anyhow!("Failed to init electrum rpc client {:?}", e))?; + let electrum = bdk::electrum_client::Client::new(electrum_rpc_url.as_str()) + .context("Failed to initialize Electrum RPC client")?; Ok(Self { wallet: Arc::new(Mutex::new(bdk_wallet)), @@ -101,9 +97,7 @@ impl Wallet { .list_transactions(true)? .iter() .find(|tx| tx.txid == txid) - .ok_or_else(|| { - anyhow!("Could not find tx in bdk wallet when trying to determine fees") - })? + .context("Could not find tx in bdk wallet when trying to determine fees")? .fees; Ok(Amount::from_sat(fees)) @@ -205,7 +199,7 @@ impl Wallet { pub async fn get_raw_transaction(&self, txid: Txid) -> Result { self.get_tx(txid) .await? - .ok_or_else(|| anyhow!("Could not get raw tx with id: {}", txid)) + .with_context(|| format!("Could not get raw tx with id: {}", txid)) } pub async fn status_of_script(&self, tx: &T) -> Result @@ -313,12 +307,9 @@ struct Client { impl Client { fn new(electrum: bdk::electrum_client::Client, interval: Duration) -> Result { - let latest_block = electrum.block_headers_subscribe().map_err(|e| { - anyhow!( - "Electrum client failed to subscribe to header notifications: {:?}", - e - ) - })?; + let latest_block = electrum + .block_headers_subscribe() + .context("Failed to subscribe to header notifications")?; Ok(Self { electrum, @@ -409,7 +400,7 @@ impl Client { let latest_block = std::iter::from_fn(|| self.electrum.block_headers_pop().transpose()) .last() .transpose() - .map_err(|e| anyhow!("Failed to pop header notification: {:?}", e))?; + .context("Failed to pop header notification")?; if let Some(new_block) = latest_block { tracing::debug!( @@ -426,7 +417,7 @@ impl Client { let histories = self .electrum .batch_script_get_history(self.script_history.keys()) - .map_err(|e| anyhow!("Failed to get script histories {:?}", e))?; + .context("Failed to get script histories")?; if histories.len() != self.script_history.len() { bail!(