From 733355a6ae5e53a59f53b0d7a1d7b8d988e0d539 Mon Sep 17 00:00:00 2001 From: Alekos Filini Date: Tue, 12 Jan 2021 21:41:30 +0100 Subject: [PATCH 1/6] Bump version to 0.3.0-rc.1 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index b4f392f0..be80477d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bdk" -version = "0.2.1-dev" +version = "0.3.0-rc.1" edition = "2018" authors = ["Alekos Filini ", "Riccardo Casatta "] homepage = "https://bitcoindevkit.org" From 52b45c5b89c9c42f6f2b6a165e9b3307156c7465 Mon Sep 17 00:00:00 2001 From: Justin Moon Date: Tue, 17 Nov 2020 18:05:33 -0600 Subject: [PATCH 2/6] [wallet] Add "needed" and "available" metadata to Error::InsufficientFunds --- src/error.rs | 7 ++++++- src/wallet/coin_selection.rs | 19 +++++++++++++------ src/wallet/mod.rs | 17 ++++++++++++++--- src/wallet/utils.rs | 2 +- 4 files changed, 34 insertions(+), 11 deletions(-) diff --git a/src/error.rs b/src/error.rs index 40e29533..226ee43b 100644 --- a/src/error.rs +++ b/src/error.rs @@ -47,7 +47,12 @@ pub enum Error { /// Output created is under the dust limit, 546 satoshis OutputBelowDustLimit(usize), /// Wallet's UTXO set is not enough to cover recipient's requested plus fee - InsufficientFunds, + InsufficientFunds { + /// Sats needed for some transaction + needed: u64, + /// Sats available for spending + available: u64, + }, /// Branch and bound coin selection possible attempts with sufficiently big UTXO set could grow /// exponentially, thus a limit is set, and when hit, this error is thrown BnBTotalTriesExceeded, diff --git a/src/wallet/coin_selection.rs b/src/wallet/coin_selection.rs index 87808db1..d4fcd02a 100644 --- a/src/wallet/coin_selection.rs +++ b/src/wallet/coin_selection.rs @@ -71,9 +71,9 @@ //! }) //! .collect::>(); //! let additional_fees = additional_weight as f32 * fee_rate.as_sat_vb() / 4.0; -//! -//! if (fee_amount + additional_fees).ceil() as u64 + amount_needed > selected_amount { -//! return Err(bdk::Error::InsufficientFunds); +//! let amount_needed_with_fees = (fee_amount + additional_fees).ceil() as u64 + amount_needed; +//! if amount_needed_with_fees > selected_amount { +//! return Err(bdk::Error::InsufficientFunds{ needed: amount_needed_with_fees, available: selected_amount }); //! } //! //! Ok(CoinSelectionResult { @@ -221,8 +221,12 @@ impl CoinSelectionAlgorithm for LargestFirstCoinSelection { ) .collect::>(); - if selected_amount < amount_needed + (fee_amount.ceil() as u64) { - return Err(Error::InsufficientFunds); + let amount_needed_with_fees = amount_needed + (fee_amount.ceil() as u64); + if selected_amount < amount_needed_with_fees { + return Err(Error::InsufficientFunds { + needed: amount_needed_with_fees, + available: selected_amount, + }); } Ok(CoinSelectionResult { @@ -321,7 +325,10 @@ impl CoinSelectionAlgorithm for BranchAndBoundCoinSelection { let cost_of_change = self.size_of_change as f32 * fee_rate.as_sat_vb(); if curr_available_value + curr_value < actual_target { - return Err(Error::InsufficientFunds); + return Err(Error::InsufficientFunds { + needed: actual_target, + available: curr_available_value + curr_value, + }); } Ok(self diff --git a/src/wallet/mod.rs b/src/wallet/mod.rs index c9b4a5be..1a82f16f 100644 --- a/src/wallet/mod.rs +++ b/src/wallet/mod.rs @@ -59,7 +59,10 @@ pub use utils::IsDust; use address_validator::AddressValidator; use signer::{Signer, SignerId, SignerOrdering, SignersContainer}; use tx_builder::{BumpFee, CreateTx, FeePolicy, TxBuilder, TxBuilderContext}; -use utils::{check_nlocktime, check_nsequence_rbf, descriptor_to_pk_ctx, After, Older, SecpCtx}; +use utils::{ + check_nlocktime, check_nsequence_rbf, descriptor_to_pk_ctx, After, Older, SecpCtx, + DUST_LIMIT_SATOSHI, +}; use crate::blockchain::{Blockchain, Progress}; use crate::database::{BatchDatabase, BatchOperations, DatabaseUtils}; @@ -508,7 +511,11 @@ where match change_output { None if change_val.is_dust() => { // single recipient, but the only output would be below dust limit - return Err(Error::InsufficientFunds); // TODO: or OutputBelowDustLimit? + // TODO: or OutputBelowDustLimit? + return Err(Error::InsufficientFunds { + needed: DUST_LIMIT_SATOSHI, + available: change_val, + }); } Some(_) if change_val.is_dust() => { // skip the change output because it's dust -- just include it in the fee. @@ -786,7 +793,11 @@ where } Some(_) if change_val_after_add.is_dust() => { // single_recipient but the only output would be below dust limit - return Err(Error::InsufficientFunds); // TODO: or OutputBelowDustLimit? + // TODO: or OutputBelowDustLimit? + return Err(Error::InsufficientFunds { + needed: DUST_LIMIT_SATOSHI, + available: change_val_after_add, + }); } None => { removed_updatable_output.value = change_val_after_add; diff --git a/src/wallet/utils.rs b/src/wallet/utils.rs index 108a21a7..5f2b8004 100644 --- a/src/wallet/utils.rs +++ b/src/wallet/utils.rs @@ -29,7 +29,7 @@ use miniscript::descriptor::DescriptorPublicKeyCtx; use miniscript::{MiniscriptKey, Satisfier, ToPublicKey}; // De-facto standard "dust limit" (even though it should change based on the output type) -const DUST_LIMIT_SATOSHI: u64 = 546; +pub const DUST_LIMIT_SATOSHI: u64 = 546; // MSB of the nSequence. If set there's no consensus-constraint, so it must be disabled when // spending using CSV in order to enforce CSV rules From 01585227c54b4422bc65fab7f294dc19f32f476b Mon Sep 17 00:00:00 2001 From: Tobin Harding Date: Mon, 18 Jan 2021 19:28:18 +1100 Subject: [PATCH 3/6] Use contains combinator As suggested by clippy, use the `contains` combinator instead of doing manual range check on floats. --- src/blockchain/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/blockchain/mod.rs b/src/blockchain/mod.rs index 66538816..25c6055b 100644 --- a/src/blockchain/mod.rs +++ b/src/blockchain/mod.rs @@ -169,7 +169,7 @@ pub fn progress() -> (Sender, Receiver) { impl Progress for Sender { fn update(&self, progress: f32, message: Option) -> Result<(), Error> { - if progress < 0.0 || progress > 100.0 { + if !(0.0..=100.0).contains(&progress) { return Err(Error::InvalidProgressValue(progress)); } From 49db898acb457b56606eeb706c9c0a3e8cb98dab Mon Sep 17 00:00:00 2001 From: Alekos Filini Date: Wed, 20 Jan 2021 10:27:28 -0500 Subject: [PATCH 4/6] Update CHANGELOG.md in preparation of tag `v0.3.0` --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a3f63f7..0ce56fbe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [v0.3.0] - [v0.2.0] + ### Descriptor #### Changed - Added an alias `DescriptorError` for `descriptor::error::Error` @@ -230,3 +232,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 [unreleased]: https://github.com/bitcoindevkit/bdk/compare/v0.2.0...HEAD [0.1.0-beta.1]: https://github.com/bitcoindevkit/bdk/compare/96c87ea5...0.1.0-beta.1 [v0.2.0]: https://github.com/bitcoindevkit/bdk/compare/0.1.0-beta.1...v0.2.0 +[v0.3.0]: https://github.com/bitcoindevkit/bdk/compare/v0.2.0...v0.3.0 From bddd418c8e0c2b363d5ca633591c76a76ab6a2a2 Mon Sep 17 00:00:00 2001 From: Alekos Filini Date: Wed, 20 Jan 2021 10:39:24 -0500 Subject: [PATCH 5/6] Bump version to 0.3.0 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index be80477d..3d121b3f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bdk" -version = "0.3.0-rc.1" +version = "0.3.0" edition = "2018" authors = ["Alekos Filini ", "Riccardo Casatta "] homepage = "https://bitcoindevkit.org" From 1420cf8d0fec7030f63a1fe5f33eb67d90d8a7f5 Mon Sep 17 00:00:00 2001 From: Alekos Filini Date: Wed, 20 Jan 2021 10:58:04 -0500 Subject: [PATCH 6/6] Bump version to 0.3.1-dev --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 3d121b3f..aea1df63 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bdk" -version = "0.3.0" +version = "0.3.1-dev" edition = "2018" authors = ["Alekos Filini ", "Riccardo Casatta "] homepage = "https://bitcoindevkit.org"