diff --git a/src/wallet/coincontrol.h b/src/wallet/coincontrol.h --- a/src/wallet/coincontrol.h +++ b/src/wallet/coincontrol.h @@ -10,6 +10,9 @@ #include +const int DEFAULT_MIN_DEPTH = 0; +const int DEFAULT_MAX_DEPTH = 9999999; + /** Coin Control Features. */ class CCoinControl { public: @@ -31,6 +34,10 @@ bool m_avoid_partial_spends; //! Forbids inclusion of dirty (previously used) addresses bool m_avoid_address_reuse; + //! Minimum chain depth value for coin availability + int m_min_depth = DEFAULT_MIN_DEPTH; + //! Maximum chain depth value for coin availability + int m_max_depth = DEFAULT_MAX_DEPTH; CCoinControl() { SetNull(); } diff --git a/src/wallet/coincontrol.cpp b/src/wallet/coincontrol.cpp --- a/src/wallet/coincontrol.cpp +++ b/src/wallet/coincontrol.cpp @@ -18,4 +18,6 @@ m_feerate.reset(); fOverrideFeeRate = false; m_confirm_target.reset(); + m_min_depth = DEFAULT_MIN_DEPTH; + m_max_depth = DEFAULT_MAX_DEPTH; } diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -3429,12 +3429,13 @@ { CCoinControl cctl; cctl.m_avoid_address_reuse = false; + cctl.m_min_depth = nMinDepth; + cctl.m_max_depth = nMaxDepth; auto locked_chain = pwallet->chain().lock(); LOCK(pwallet->cs_wallet); pwallet->AvailableCoins(*locked_chain, vecOutputs, !include_unsafe, &cctl, nMinimumAmount, nMaximumAmount, - nMinimumSumAmount, nMaximumCount, nMinDepth, - nMaxDepth); + nMinimumSumAmount, nMaximumCount); } LOCK(pwallet->cs_wallet); diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -1027,9 +1027,7 @@ const Amount nMinimumAmount = SATOSHI, const Amount nMaximumAmount = MAX_MONEY, const Amount nMinimumSumAmount = MAX_MONEY, - const uint64_t nMaximumCount = 0, - const int nMinDepth = 0, - const int nMaxDepth = 9999999) const + const uint64_t nMaximumCount = 0) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); /** diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2687,8 +2687,7 @@ const Amount nMinimumAmount, const Amount nMaximumAmount, const Amount nMinimumSumAmount, - const uint64_t nMaximumCount, const int nMinDepth, - const int nMaxDepth) const { + const uint64_t nMaximumCount) const { AssertLockHeld(cs_wallet); vCoins.clear(); @@ -2700,6 +2699,10 @@ 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}; const Consensus::Params params = Params().GetConsensus(); @@ -2755,7 +2758,7 @@ continue; } - if (nDepth < nMinDepth || nDepth > nMaxDepth) { + if (nDepth < min_depth || nDepth > max_depth) { continue; }