Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/wallet/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Comment thread
random-zebra marked this conversation as resolved.

"\nResult\n"
"[ (array of json object)\n"
Expand Down Expand Up @@ -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<COutput> 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;
Expand Down
6 changes: 2 additions & 4 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2079,8 +2079,7 @@ bool CWallet::AvailableCoins(std::vector<COutput>* 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();
Expand Down Expand Up @@ -2117,8 +2116,7 @@ bool CWallet::AvailableCoins(std::vector<COutput>* 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)))
Expand Down
3 changes: 1 addition & 2 deletions src/wallet/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<COutput>& vAvailableCoins, const CAmount& nTargetValue, std::set<std::pair<const CWalletTx*, unsigned int> >& setCoinsRet, CAmount& nValueRet, const CCoinControl* coinControl = nullptr) const;
Expand Down
2 changes: 1 addition & 1 deletion test/functional/wallet_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down