Skip to content

Commit

Permalink
Merge #1441: Remove duplicated InsufficientFunds error member
Browse files Browse the repository at this point in the history
29c8a00 chore(wallet): remove duplicated InsufficientFunds error member from CreateTxError (e1a0a0ea)

Pull request description:

  closes #1440

  ### Description

  - Replace `CreateTxError::InsufficientFunds` use by `coin_selection::Error::InsufficientFunds`
  - Remove `InsufficientFunds` member from `CreateTxError` enum
  - Rename `coin_selection::Error` to `coin_selection::CoinSelectionError`

  ### Notes to the reviewers

  - We could also keep both members but rename one of them to avoid confusion

  ### Checklists

  #### All Submissions:

  * [X] I've signed all my commits
  * [X] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md)
  * [X] I ran `cargo fmt` and `cargo clippy` before committing

ACKs for top commit:
  evanlinjin:
    ACK 29c8a00
  notmandatory:
    ACK 29c8a00

Tree-SHA512: a1132d09929f99f0a5e82d3ccfaa85695ae50d7d4d5d9e8fd9ef847313918ed8c7a01005f45483fef6aeae36730a0da2fed9a9f10c3ce2f0a679527caf798bfe
  • Loading branch information
evanlinjin committed Jun 6, 2024
2 parents c5a3b62 + 29c8a00 commit b4a847f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 16 deletions.
14 changes: 0 additions & 14 deletions crates/wallet/src/wallet/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,6 @@ pub enum CreateTxError {
OutputBelowDustLimit(usize),
/// There was an error with coin selection
CoinSelection(coin_selection::Error),
/// Wallet's UTXO set is not enough to cover recipient's requested plus fee
InsufficientFunds {
/// Sats needed for some transaction
needed: u64,
/// Sats available for spending
available: u64,
},
/// Cannot build a tx without recipients
NoRecipients,
/// Partially signed bitcoin transaction error
Expand Down Expand Up @@ -176,13 +169,6 @@ impl fmt::Display for CreateTxError {
write!(f, "Output below the dust limit: {}", limit)
}
CreateTxError::CoinSelection(e) => e.fmt(f),
CreateTxError::InsufficientFunds { needed, available } => {
write!(
f,
"Insufficient funds: {} sat available of {} sat needed",
available, needed
)
}
CreateTxError::NoRecipients => {
write!(f, "Cannot build tx without recipients")
}
Expand Down
6 changes: 4 additions & 2 deletions crates/wallet/src/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ use crate::types::*;
use crate::wallet::coin_selection::Excess::{Change, NoChange};
use crate::wallet::error::{BuildFeeBumpError, CreateTxError, MiniscriptPsbtError};

use self::coin_selection::Error;

const COINBASE_MATURITY: u32 = 100;

/// A Bitcoin wallet
Expand Down Expand Up @@ -1562,10 +1564,10 @@ impl Wallet {
change_fee,
} = excess
{
return Err(CreateTxError::InsufficientFunds {
return Err(CreateTxError::CoinSelection(Error::InsufficientFunds {
needed: *dust_threshold,
available: remaining_amount.saturating_sub(*change_fee),
});
}));
}
} else {
return Err(CreateTxError::NoRecipients);
Expand Down

0 comments on commit b4a847f

Please sign in to comment.