Skip to content

Commit c3671b5

Browse files
committed
Allow rpc listunspent to have options for watchonly transactions
1 parent 24f5818 commit c3671b5

File tree

4 files changed

+20
-6
lines changed

4 files changed

+20
-6
lines changed

src/rpcclient.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ static const CRPCConvertParam vRPCConvertParams[] =
7272
{"listunspent", 0},
7373
{"listunspent", 1},
7474
{"listunspent", 2},
75+
{"listunspent", 3},
7576
{"getblock", 1},
7677
{"getblockheader", 1},
7778
{"gettransaction", 1},

src/rpcrawtransaction.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ UniValue getrawtransaction(const UniValue& params, bool fHelp)
198198
#ifdef ENABLE_WALLET
199199
UniValue listunspent(const UniValue& params, bool fHelp)
200200
{
201-
if (fHelp || params.size() > 3)
201+
if (fHelp || params.size() > 4)
202202
throw runtime_error(
203203
"listunspent ( minconf maxconf [\"address\",...] )\n"
204204
"\nReturns array of unspent transaction outputs\n"
@@ -214,6 +214,7 @@ UniValue listunspent(const UniValue& params, bool fHelp)
214214
" \"address\" (string) pivx address\n"
215215
" ,...\n"
216216
" ]\n"
217+
"4. watchonlyconfig (numberic, optional, default=1) 1 = list regular unspent transactions, 2 = list only watchonly transactions, 3 = list all unspent transactions (including watchonly)\n"
217218
"\nResult\n"
218219
"[ (array of json object)\n"
219220
" {\n"
@@ -231,7 +232,7 @@ UniValue listunspent(const UniValue& params, bool fHelp)
231232
"\nExamples\n" +
232233
HelpExampleCli("listunspent", "") + HelpExampleCli("listunspent", "6 9999999 \"[\\\"1PGFqEzfmQch1gKD3ra4k18PNj3tTUUSqg\\\",\\\"1LtvqCaApEdUGFkpKMM4MstjcaL4dKg8SP\\\"]\"") + HelpExampleRpc("listunspent", "6, 9999999 \"[\\\"1PGFqEzfmQch1gKD3ra4k18PNj3tTUUSqg\\\",\\\"1LtvqCaApEdUGFkpKMM4MstjcaL4dKg8SP\\\"]\""));
233234

234-
RPCTypeCheck(params, boost::assign::list_of(UniValue::VNUM)(UniValue::VNUM)(UniValue::VARR));
235+
RPCTypeCheck(params, boost::assign::list_of(UniValue::VNUM)(UniValue::VNUM)(UniValue::VARR)(UniValue::VNUM));
235236

236237
int nMinDepth = 1;
237238
if (params.size() > 0)
@@ -255,11 +256,18 @@ UniValue listunspent(const UniValue& params, bool fHelp)
255256
}
256257
}
257258

259+
int nWatchonlyConfig = 1;
260+
if(params.size() > 3) {
261+
nWatchonlyConfig = params[3].get_int();
262+
if (nWatchonlyConfig > 3 || nWatchonlyConfig < 1)
263+
nWatchonlyConfig = 1;
264+
}
265+
258266
UniValue results(UniValue::VARR);
259267
vector<COutput> vecOutputs;
260268
assert(pwalletMain != NULL);
261269
LOCK2(cs_main, pwalletMain->cs_wallet);
262-
pwalletMain->AvailableCoins(vecOutputs, false);
270+
pwalletMain->AvailableCoins(vecOutputs, false, NULL, false, ALL_COINS, false, nWatchonlyConfig);
263271
BOOST_FOREACH (const COutput& out, vecOutputs) {
264272
if (out.nDepth < nMinDepth || out.nDepth > nMaxDepth)
265273
continue;

src/wallet.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1892,7 +1892,7 @@ CAmount CWallet::GetLockedWatchOnlyBalance() const
18921892
/**
18931893
* populate vCoins with vector of available COutputs.
18941894
*/
1895-
void CWallet::AvailableCoins(vector<COutput>& vCoins, bool fOnlyConfirmed, const CCoinControl* coinControl, bool fIncludeZeroValue, AvailableCoinsType nCoinType, bool fUseIX) const
1895+
void CWallet::AvailableCoins(vector<COutput>& vCoins, bool fOnlyConfirmed, const CCoinControl* coinControl, bool fIncludeZeroValue, AvailableCoinsType nCoinType, bool fUseIX, int nWatchonlyConfig) const
18961896
{
18971897
vCoins.clear();
18981898

@@ -1948,7 +1948,11 @@ void CWallet::AvailableCoins(vector<COutput>& vCoins, bool fOnlyConfirmed, const
19481948
continue;
19491949
if (mine == ISMINE_NO)
19501950
continue;
1951-
if (mine == ISMINE_WATCH_ONLY)
1951+
1952+
if ((mine == ISMINE_MULTISIG || mine == ISMINE_SPENDABLE) && nWatchonlyConfig == 2)
1953+
continue;
1954+
1955+
if (mine == ISMINE_WATCH_ONLY && nWatchonlyConfig == 1)
19521956
continue;
19531957

19541958
if (IsLockedCoin((*it).first, i) && nCoinType != ONLY_10000)
@@ -1963,6 +1967,7 @@ void CWallet::AvailableCoins(vector<COutput>& vCoins, bool fOnlyConfirmed, const
19631967
fIsSpendable = true;
19641968
if ((mine & ISMINE_MULTISIG) != ISMINE_NO)
19651969
fIsSpendable = true;
1970+
19661971
vCoins.emplace_back(COutput(pcoin, i, nDepth, fIsSpendable));
19671972
}
19681973
}

src/wallet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
358358
return nWalletMaxVersion >= wf;
359359
}
360360

361-
void AvailableCoins(std::vector<COutput>& vCoins, bool fOnlyConfirmed = true, const CCoinControl* coinControl = NULL, bool fIncludeZeroValue = false, AvailableCoinsType nCoinType = ALL_COINS, bool fUseIX = false) const;
361+
void AvailableCoins(std::vector<COutput>& vCoins, bool fOnlyConfirmed = true, const CCoinControl* coinControl = NULL, bool fIncludeZeroValue = false, AvailableCoinsType nCoinType = ALL_COINS, bool fUseIX = false, int nWatchonlyConfig = 1) const;
362362
std::map<CBitcoinAddress, std::vector<COutput> > AvailableCoinsByAddress(bool fConfirmed = true, CAmount maxCoinValue = 0);
363363
bool SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int nConfTheirs, std::vector<COutput> vCoins, std::set<std::pair<const CWalletTx*, unsigned int> >& setCoinsRet, CAmount& nValueRet) const;
364364

0 commit comments

Comments
 (0)