diff --git a/crates/bdk/src/wallet/mod.rs b/crates/bdk/src/wallet/mod.rs index 0e427087..c6c922d5 100644 --- a/crates/bdk/src/wallet/mod.rs +++ b/crates/bdk/src/wallet/mod.rs @@ -12,7 +12,7 @@ //! Wallet //! //! This module defines the [`Wallet`]. -use crate::collections::{BTreeMap, HashMap, HashSet}; +use crate::collections::{BTreeMap, HashMap}; use alloc::{ boxed::Box, string::{String, ToString}, @@ -1518,15 +1518,8 @@ impl Wallet { return Err(CreateTxError::ChangePolicyDescriptor); } - let (required_utxos, optional_utxos) = self.preselect_utxos( - params.change_policy, - ¶ms.unspendable, - params.utxos.clone(), - params.drain_wallet, - params.manually_selected_only, - params.bumping_fee.is_some(), // we mandate confirmed transactions if we're bumping the fee - Some(current_height.to_consensus_u32()), - ); + let (required_utxos, optional_utxos) = + self.preselect_utxos(¶ms, Some(current_height.to_consensus_u32())); // get drain script let drain_script = match params.drain_to { @@ -2063,17 +2056,26 @@ impl Wallet { /// Given the options returns the list of utxos that must be used to form the /// transaction and any further that may be used if needed. - #[allow(clippy::too_many_arguments)] fn preselect_utxos( &self, - change_policy: tx_builder::ChangeSpendPolicy, - unspendable: &HashSet, - manually_selected: Vec, - must_use_all_available: bool, - manual_only: bool, - must_only_use_confirmed_tx: bool, + params: &TxParams, current_height: Option, ) -> (Vec, Vec) { + let TxParams { + change_policy, + unspendable, + utxos, + drain_wallet, + manually_selected_only, + bumping_fee, + .. + } = params; + + let manually_selected = utxos.clone(); + // we mandate confirmed transactions if we're bumping the fee + let must_only_use_confirmed_tx = bumping_fee.is_some(); + let must_use_all_available = *drain_wallet; + let chain_tip = self.chain.tip().block_id(); // must_spend <- manually selected utxos // may_spend <- all other available utxos @@ -2088,7 +2090,7 @@ impl Wallet { // NOTE: we are intentionally ignoring `unspendable` here. i.e manual // selection overrides unspendable. - if manual_only { + if *manually_selected_only { return (must_spend, vec![]); }