From c5a5af48975b36b03c4e1ab120cbe3e87796121a Mon Sep 17 00:00:00 2001 From: furszy Date: Wed, 22 Jul 2020 21:12:57 -0300 Subject: [PATCH] AvailableCoins: remove duplicated watchonly config argument. --- src/wallet/rpcwallet.cpp | 15 ++++++++++----- src/wallet/wallet.cpp | 6 ++---- src/wallet/wallet.h | 3 +-- test/functional/wallet_basic.py | 2 +- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index c5cc988c1bf4..61e6b6114e71 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -8,6 +8,7 @@ #include "addressbook.h" #include "amount.h" #include "base58.h" +#include "coincontrol.h" #include "core_io.h" #include "init.h" #include "key_io.h" @@ -3054,7 +3055,7 @@ UniValue listunspent(const JSONRPCRequest& request) " \"address\" (string) pivx address\n" " ,...\n" " ]\n" - "4. watchonlyconfig (numeric, optional, default=1) 1 = list regular unspent transactions, 2 = list only watchonly transactions, 3 = list all unspent transactions (including watchonly)\n" + "4. watchonlyconfig (numeric, optional, default=1) 1 = list regular unspent transactions, 2 = list all unspent transactions (including watchonly)\n" "\nResult\n" "[ (array of json object)\n" @@ -3100,26 +3101,30 @@ UniValue listunspent(const JSONRPCRequest& request) } } + // List watch only utxo int nWatchonlyConfig = 1; if(request.params.size() > 3) { nWatchonlyConfig = request.params[3].get_int(); - if (nWatchonlyConfig > 3 || nWatchonlyConfig < 1) + if (nWatchonlyConfig > 2 || nWatchonlyConfig < 1) nWatchonlyConfig = 1; } + CCoinControl coinControl; + coinControl.fAllowWatchOnly = nWatchonlyConfig == 2; + UniValue results(UniValue::VARR); std::vector vecOutputs; assert(pwalletMain != NULL); LOCK2(cs_main, pwalletMain->cs_wallet); pwalletMain->AvailableCoins(&vecOutputs, - nullptr, // coin control + &coinControl, // coin control true, // include delegated false, // include cold staking ALL_COINS, // coin type false, // only confirmed false, // include zero value - false, // use IX - nWatchonlyConfig); + false // use IX + ); for (const COutput& out : vecOutputs) { if (out.nDepth < nMinDepth || out.nDepth > nMaxDepth) continue; diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 981721758332..7275fc9a180a 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2079,8 +2079,7 @@ bool CWallet::AvailableCoins(std::vector* pCoins, // --> populates AvailableCoinsType nCoinType, // Default: ALL_COINS bool fOnlyConfirmed, // Default: true bool fIncludeZeroValue, // Default: false - bool fUseIX, // Default: false - int nWatchonlyConfig // Default: 1 + bool fUseIX // Default: false ) const { if (pCoins) pCoins->clear(); @@ -2117,8 +2116,7 @@ bool CWallet::AvailableCoins(std::vector* pCoins, // --> populates isminetype mine = IsMine(pcoin->vout[i]); if ( (mine == ISMINE_NO) || - (mine == ISMINE_SPENDABLE && nWatchonlyConfig == 2) || - (mine == ISMINE_WATCH_ONLY && nWatchonlyConfig == 1) || + (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))) diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index cc135c86e515..c22924ee137a 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -351,8 +351,7 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface AvailableCoinsType nCoinType = ALL_COINS, bool fOnlyConfirmed = true, bool fIncludeZeroValue = false, - bool fUseIX = false, - int nWatchonlyConfig = 1 + bool fUseIX = false ) const; //! >> Available coins (spending) bool SelectCoinsToSpend(const std::vector& vAvailableCoins, const CAmount& nTargetValue, std::set >& setCoinsRet, CAmount& nValueRet, const CCoinControl* coinControl = nullptr) const; diff --git a/test/functional/wallet_basic.py b/test/functional/wallet_basic.py index 9ba15e502914..f3c6af3edd54 100755 --- a/test/functional/wallet_basic.py +++ b/test/functional/wallet_basic.py @@ -147,7 +147,7 @@ def run_test(self): assert(self.nodes[1].validateaddress(address_to_import)["iswatchonly"]) # 4. Check that the unspents after import are not spendable - listunspent = self.nodes[1].listunspent(1, 9999999, [], 3) + listunspent = self.nodes[1].listunspent(1, 9999999, [], 2) assert_array_result(listunspent, {"address": address_to_import}, {"spendable": False})