From 02965091106f63cad63531f53589c12f4130e8da Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Thu, 12 Aug 2021 16:40:52 +1000 Subject: [PATCH] Upgrade to bdk 0.10 This fixes #546. I don't know why, but I can't reproduce the problem with the updated dependency. --- CHANGELOG.md | 4 ++++ Cargo.lock | 19 ++++++++++++++----- swap/Cargo.toml | 2 +- swap/src/bitcoin/wallet.rs | 13 ++++++++----- 4 files changed, 27 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a472642b..3c113de3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed + +- An occasional error where users couldn't start a swap because of `InsufficientFunds` that were off by exactly 1 satoshi. + ## [0.8.0] - 2021-07-09 ### Added diff --git a/Cargo.lock b/Cargo.lock index 3fa58fb4..3799b5f0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -235,11 +235,20 @@ version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" +[[package]] +name = "base64-compat" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a8d4d2746f89841e49230dd26917df1876050f95abafafbe34f47cb534b88d7" +dependencies = [ + "byteorder", +] + [[package]] name = "bdk" -version = "0.8.0" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05d7fee1aedf8935ba1e2c9aeee640d1b9754da1b64f30ad47e8b8e2b7904ec0" +checksum = "8f4da304c23a06c21807598a7fe3223566e84c76c6bba2cab2504370dd6f4938" dependencies = [ "async-trait", "bdk-macros", @@ -252,14 +261,13 @@ dependencies = [ "serde", "serde_json", "sled", - "tokio", ] [[package]] name = "bdk-macros" -version = "0.4.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b45570b78250774145859a8f85bfdb6e310663fc82640d7e159a44b1386074a2" +checksum = "c3f510015e946c5995cc169f7ed4c92ba032bbce795c0956ee0d98d82f7aff78" dependencies = [ "proc-macro2 1.0.27", "quote 1.0.9", @@ -331,6 +339,7 @@ version = "0.26.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6742ec672d3f12506f4ac5c0d853926ff1f94e675f60ffd3224039972bf663f1" dependencies = [ + "base64-compat", "bech32", "bitcoin_hashes", "secp256k1", diff --git a/swap/Cargo.toml b/swap/Cargo.toml index 727f8e65..ff384dee 100644 --- a/swap/Cargo.toml +++ b/swap/Cargo.toml @@ -15,7 +15,7 @@ async-trait = "0.1" atty = "0.2" backoff = { version = "0.3", features = [ "tokio" ] } base64 = "0.13" -bdk = "0.8" +bdk = "0.10" big-bytes = "1" bitcoin = { version = "0.26", features = [ "rand", "use-serde" ] } bmrng = "0.5" diff --git a/swap/src/bitcoin/wallet.rs b/swap/src/bitcoin/wallet.rs index 82be3dc6..b2554e80 100644 --- a/swap/src/bitcoin/wallet.rs +++ b/swap/src/bitcoin/wallet.rs @@ -306,7 +306,8 @@ where .iter() .find(|tx| tx.txid == txid) .context("Could not find tx in bdk wallet when trying to determine fees")? - .fees; + .fee + .expect("fees are always present with Electrum backend"); Ok(Amount::from_sat(fees)) } @@ -394,14 +395,16 @@ where let mut tx_builder = wallet.build_tx(); let dummy_script = Script::from(vec![0u8; locking_script_size]); - tx_builder.set_single_recipient(dummy_script); - tx_builder.drain_wallet(); + tx_builder.drain_to(dummy_script); tx_builder.fee_rate(fee_rate); let response = tx_builder.finish(); match response { Ok((_, details)) => { - let max_giveable = details.sent - details.fees; + let max_giveable = details.sent + - details + .fee + .expect("fees are always present with Electrum backend"); Ok(Amount::from_sat(max_giveable)) } Err(bdk::Error::InsufficientFunds { .. }) => Ok(Amount::ZERO), @@ -600,7 +603,7 @@ impl WalletBuilder { pub fn build(self) -> Wallet<(), bdk::database::MemoryDatabase, StaticFeeRate> { use bdk::database::MemoryDatabase; - use bdk::{LocalUtxo, TransactionDetails}; + use bdk::{ConfirmationTime, LocalUtxo, TransactionDetails}; use bitcoin::OutPoint; use testutils::testutils;