From e74dcd85b98dee38cfa463ade18bd001bf7792fc Mon Sep 17 00:00:00 2001 From: furszy Date: Thu, 23 Jul 2020 00:48:19 -0300 Subject: [PATCH 1/2] AvailableCoins: improving core readability. --- src/wallet/wallet.cpp | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 29fa4b5515b2..4c03de71d95f 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2153,24 +2153,32 @@ bool CWallet::AvailableCoins(std::vector* pCoins, // --> populates if (nCoinType == STAKEABLE_COINS && nDepth < Params().GetConsensus().nStakeMinDepth) continue; for (unsigned int i = 0; i < pcoin->vout.size(); i++) { - bool found = false; - if (nCoinType == ONLY_10000) { - found = pcoin->vout[i].nValue == 10000 * COIN; - } else { - found = true; - } - if (!found) continue; + // Check for only 10k utxo + if (nCoinType == ONLY_10000 && pcoin->vout[i].nValue != 10000 * COIN) continue; + + // Check for stakeable utxo if (nCoinType == STAKEABLE_COINS && pcoin->vout[i].IsZerocoinMint()) continue; + + // Check if the utxo was spent. if (IsSpent(wtxid, i)) continue; isminetype mine = IsMine(pcoin->vout[i]); - if ( (mine == ISMINE_NO) || - (mine == ISMINE_WATCH_ONLY && coinControl && !coinControl->fAllowWatchOnly) || - (IsLockedCoin((*it).first, i) && nCoinType != ONLY_10000) || - (pcoin->vout[i].nValue <= 0 && !fIncludeZeroValue) || - (fCoinsSelected && !coinControl->fAllowOtherInputs && !coinControl->IsSelected(COutPoint((*it).first, i))) - ) continue; + + // Check If not mine + if (mine == ISMINE_NO) continue; + + // Check if watch only utxo are allowed + if (mine == ISMINE_WATCH_ONLY && coinControl && !coinControl->fAllowWatchOnly) continue; + + // Skip locked utxo + if (IsLockedCoin((*it).first, i) && nCoinType != ONLY_10000) continue; + + // Check if we should include zero value utxo + if (pcoin->vout[i].nValue <= 0 && !fIncludeZeroValue) continue; + + if (fCoinsSelected && !coinControl->fAllowOtherInputs && !coinControl->IsSelected(COutPoint((*it).first, i))) + continue; // --Skip P2CS outputs // skip cold coins From a13c24569a4fa7dfd4714192fd69561164b2b340 Mon Sep 17 00:00:00 2001 From: furszy Date: Thu, 23 Jul 2020 00:52:02 -0300 Subject: [PATCH 2/2] AvailableCoins: remove unused "includeZeroValue" flag. --- src/wallet/rpcwallet.cpp | 1 - src/wallet/wallet.cpp | 4 +--- src/wallet/wallet.h | 1 - 3 files changed, 1 insertion(+), 5 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index d6e6d38223da..7b35308332f1 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -3194,7 +3194,6 @@ UniValue listunspent(const JSONRPCRequest& request) false, // include cold staking ALL_COINS, // coin type false, // only confirmed - false, // include zero value false // use IX ); for (const COutput& out : vecOutputs) { diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 4c03de71d95f..22f8070cd8e9 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2128,7 +2128,6 @@ bool CWallet::AvailableCoins(std::vector* pCoins, // --> populates bool fIncludeColdStaking, // Default: false AvailableCoinsType nCoinType, // Default: ALL_COINS bool fOnlyConfirmed, // Default: true - bool fIncludeZeroValue, // Default: false bool fUseIX // Default: false ) const { @@ -2175,7 +2174,7 @@ bool CWallet::AvailableCoins(std::vector* pCoins, // --> populates if (IsLockedCoin((*it).first, i) && nCoinType != ONLY_10000) continue; // Check if we should include zero value utxo - if (pcoin->vout[i].nValue <= 0 && !fIncludeZeroValue) continue; + if (pcoin->vout[i].nValue <= 0) continue; if (fCoinsSelected && !coinControl->fAllowOtherInputs && !coinControl->IsSelected(COutPoint((*it).first, i))) continue; @@ -2569,7 +2568,6 @@ bool CWallet::CreateTransaction(const std::vector& vecSend, false, // fIncludeColdStaking coin_type, true, // fOnlyConfirmed - false, // fIncludeZeroValue useIX); nFeeRet = 0; diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 2a8034048ede..9d52f6b4f47d 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -362,7 +362,6 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface bool fIncludeColdStaking = false, AvailableCoinsType nCoinType = ALL_COINS, bool fOnlyConfirmed = true, - bool fIncludeZeroValue = false, bool fUseIX = false ) const; //! >> Available coins (spending)