mirror of
https://github.com/dashpay/dash.git
synced 2024-12-26 04:22:55 +01:00
Merge #15906: [wallet] Move min_depth and max_depth to coin control
80ba4241a6773590f6b2c18dae758097b5adc02e extract min & max depth onto coin control (Amiti Uttarwar) Pull request description: - Refactor `AvailableCoins` to pull min & max depths from coin control. - Add `m_max_depth` to coin control to support this. - Addresses issue https://github.com/bitcoin/bitcoin/issues/15823, see thread for further details. ACKs for top commit: laanwj: ACK 80ba4241a6773590f6b2c18dae758097b5adc02e Tree-SHA512: 8f7c0aa90b3bc3667baf6741b1da2829f3919e1df92ae097d86c6b239f0c024eb410d7100e6251ea8fc49d022fb5a1214bf79b0f8b0014945b7784b2311647d1
This commit is contained in:
parent
389f9591b6
commit
15d37f896f
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
|
@ -3120,9 +3120,11 @@ static UniValue listunspent(const JSONRPCRequest& request)
|
||||
std::vector<COutput> 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);
|
||||
|
@ -2516,7 +2516,7 @@ CAmount CWallet::GetAvailableBalance(const CCoinControl* coinControl) const
|
||||
return balance;
|
||||
}
|
||||
|
||||
void CWallet::AvailableCoins(std::vector<COutput> &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<COutput> &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<COutput> &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<COutput> &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<CRecipient>& vecSend, CTransac
|
||||
{
|
||||
CAmount nAmountAvailable{0};
|
||||
std::vector<COutput> 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
|
||||
|
||||
|
@ -864,7 +864,7 @@ public:
|
||||
/**
|
||||
* populate vCoins with vector of available COutputs.
|
||||
*/
|
||||
void AvailableCoins(std::vector<COutput>& 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<COutput>& 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.
|
||||
|
Loading…
Reference in New Issue
Block a user