diff --git a/src/wallet/coincontrol.cpp b/src/wallet/coincontrol.cpp index 3d9a38b3dd..0303f7a8cb 100644 --- a/src/wallet/coincontrol.cpp +++ b/src/wallet/coincontrol.cpp @@ -20,6 +20,8 @@ void CCoinControl::SetNull(bool fResetCoinType) m_fee_mode = FeeEstimateMode::UNSET; fRequireAllInputs = true; m_discard_feerate.reset(); + m_min_depth = DEFAULT_MIN_DEPTH; + m_max_depth = DEFAULT_MAX_DEPTH; if (fResetCoinType) { nCoinType = CoinType::ALL_COINS; } diff --git a/src/wallet/coincontrol.h b/src/wallet/coincontrol.h index a5a79ca76d..221f5a8e39 100644 --- a/src/wallet/coincontrol.h +++ b/src/wallet/coincontrol.h @@ -29,6 +29,9 @@ enum class CoinType //! Default for -avoidpartialspends static constexpr bool DEFAULT_AVOIDPARTIALSPENDS = false; +const int DEFAULT_MIN_DEPTH = 0; +const int DEFAULT_MAX_DEPTH = 9999999; + /** Coin Control Features. */ class CCoinControl { @@ -55,7 +58,9 @@ public: //! Fee estimation mode to control arguments to estimateSmartFee FeeEstimateMode m_fee_mode; //! Minimum chain depth value for coin availability - int m_min_depth{0}; + int m_min_depth = DEFAULT_MIN_DEPTH; + //! Maximum chain depth value for coin availability + int m_max_depth = DEFAULT_MAX_DEPTH; //! Controls which types of coins are allowed to be used (default: ALL_COINS) CoinType nCoinType; diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 613b0b18d2..7bee95b7f8 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -3120,9 +3120,11 @@ static UniValue listunspent(const JSONRPCRequest& request) std::vector vecOutputs; { coinControl.m_avoid_address_reuse = false; + coinControl.m_min_depth = nMinDepth; + coinControl.m_max_depth = nMaxDepth; LOCK(pwallet->cs_wallet); - pwallet->AvailableCoins(vecOutputs, !include_unsafe, &coinControl, nMinimumAmount, nMaximumAmount, nMinimumSumAmount, nMaximumCount, nMinDepth, nMaxDepth); + pwallet->AvailableCoins(vecOutputs, !include_unsafe, &coinControl, nMinimumAmount, nMaximumAmount, nMinimumSumAmount, nMaximumCount); } LOCK(pwallet->cs_wallet); diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index ced8370d11..1694cab113 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2516,7 +2516,7 @@ CAmount CWallet::GetAvailableBalance(const CCoinControl* coinControl) const return balance; } -void CWallet::AvailableCoins(std::vector &vCoins, bool fOnlySafe, const CCoinControl *coinControl, const CAmount &nMinimumAmount, const CAmount &nMaximumAmount, const CAmount &nMinimumSumAmount, const uint64_t nMaximumCount, const int nMinDepth, const int nMaxDepth) const +void CWallet::AvailableCoins(std::vector &vCoins, bool fOnlySafe, const CCoinControl* coinControl, const CAmount& nMinimumAmount, const CAmount& nMaximumAmount, const CAmount &nMinimumSumAmount, const uint64_t nMaximumCount) const { AssertLockHeld(cs_wallet); @@ -2527,6 +2527,8 @@ void CWallet::AvailableCoins(std::vector &vCoins, bool fOnlySafe, const // Either the WALLET_FLAG_AVOID_REUSE flag is not set (in which case we always allow), or we default to avoiding, and only in the case where // a coin control object is provided, and has the avoid address reuse flag set to false, do we allow already used addresses bool allow_used_addresses = !IsWalletFlagSet(WALLET_FLAG_AVOID_REUSE) || (coinControl && !coinControl->m_avoid_address_reuse); + const int min_depth = {coinControl ? coinControl->m_min_depth : DEFAULT_MIN_DEPTH}; + const int max_depth = {coinControl ? coinControl->m_max_depth : DEFAULT_MAX_DEPTH}; for (auto pcoin : GetSpendableTXs()) { const uint256& wtxid = pcoin->GetHash(); @@ -2550,8 +2552,9 @@ void CWallet::AvailableCoins(std::vector &vCoins, bool fOnlySafe, const continue; } - if (nDepth < nMinDepth || nDepth > nMaxDepth) + if (nDepth < min_depth || nDepth > max_depth) { continue; + } for (unsigned int i = 0; i < pcoin->tx->vout.size(); i++) { bool found = false; @@ -3408,7 +3411,7 @@ bool CWallet::CreateTransaction(const std::vector& vecSend, CTransac { CAmount nAmountAvailable{0}; std::vector vAvailableCoins; - AvailableCoins(vAvailableCoins, true, &coin_control, 1, MAX_MONEY, MAX_MONEY, 0, coin_control.m_min_depth); + AvailableCoins(vAvailableCoins, true, &coin_control, 1, MAX_MONEY, MAX_MONEY, 0); CoinSelectionParams coin_selection_params; // Parameters for coin selection, init with dummy coin_selection_params.use_bnb = false; // never use BnB diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 2a8e153232..4ff2dca1b2 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -864,7 +864,7 @@ public: /** * populate vCoins with vector of available COutputs. */ - void AvailableCoins(std::vector& vCoins, bool fOnlySafe=true, const CCoinControl *coinControl = nullptr, const CAmount& nMinimumAmount = 1, const CAmount& nMaximumAmount = MAX_MONEY, const CAmount& nMinimumSumAmount = MAX_MONEY, const uint64_t nMaximumCount = 0, const int nMinDepth = 0, const int nMaxDepth = 9999999) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); + void AvailableCoins(std::vector& vCoins, bool fOnlySafe = true, const CCoinControl* coinControl = nullptr, const CAmount& nMinimumAmount = 1, const CAmount& nMaximumAmount = MAX_MONEY, const CAmount& nMinimumSumAmount = MAX_MONEY, const uint64_t nMaximumCount = 0) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); /** * Return list of available coins and locked coins grouped by non-change output address.