Skip to content

Commit

Permalink
Allow rpc listunspent to have options for watchonly transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
blondfrogs committed Feb 13, 2018
1 parent 24f5818 commit c3671b5
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/rpcclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ static const CRPCConvertParam vRPCConvertParams[] =
{"listunspent", 0},
{"listunspent", 1},
{"listunspent", 2},
{"listunspent", 3},
{"getblock", 1},
{"getblockheader", 1},
{"gettransaction", 1},
Expand Down
14 changes: 11 additions & 3 deletions src/rpcrawtransaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ UniValue getrawtransaction(const UniValue& params, bool fHelp)
#ifdef ENABLE_WALLET
UniValue listunspent(const UniValue& params, bool fHelp)
{
if (fHelp || params.size() > 3)
if (fHelp || params.size() > 4)
throw runtime_error(
"listunspent ( minconf maxconf [\"address\",...] )\n"
"\nReturns array of unspent transaction outputs\n"
Expand All @@ -214,6 +214,7 @@ UniValue listunspent(const UniValue& params, bool fHelp)
" \"address\" (string) pivx address\n"
" ,...\n"
" ]\n"
"4. watchonlyconfig (numberic, optional, default=1) 1 = list regular unspent transactions, 2 = list only watchonly transactions, 3 = list all unspent transactions (including watchonly)\n"
"\nResult\n"
"[ (array of json object)\n"
" {\n"
Expand All @@ -231,7 +232,7 @@ UniValue listunspent(const UniValue& params, bool fHelp)
"\nExamples\n" +
HelpExampleCli("listunspent", "") + HelpExampleCli("listunspent", "6 9999999 \"[\\\"1PGFqEzfmQch1gKD3ra4k18PNj3tTUUSqg\\\",\\\"1LtvqCaApEdUGFkpKMM4MstjcaL4dKg8SP\\\"]\"") + HelpExampleRpc("listunspent", "6, 9999999 \"[\\\"1PGFqEzfmQch1gKD3ra4k18PNj3tTUUSqg\\\",\\\"1LtvqCaApEdUGFkpKMM4MstjcaL4dKg8SP\\\"]\""));

RPCTypeCheck(params, boost::assign::list_of(UniValue::VNUM)(UniValue::VNUM)(UniValue::VARR));
RPCTypeCheck(params, boost::assign::list_of(UniValue::VNUM)(UniValue::VNUM)(UniValue::VARR)(UniValue::VNUM));

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

int nWatchonlyConfig = 1;
if(params.size() > 3) {
nWatchonlyConfig = params[3].get_int();
if (nWatchonlyConfig > 3 || nWatchonlyConfig < 1)
nWatchonlyConfig = 1;
}

UniValue results(UniValue::VARR);
vector<COutput> vecOutputs;
assert(pwalletMain != NULL);
LOCK2(cs_main, pwalletMain->cs_wallet);
pwalletMain->AvailableCoins(vecOutputs, false);
pwalletMain->AvailableCoins(vecOutputs, false, NULL, false, ALL_COINS, false, nWatchonlyConfig);
BOOST_FOREACH (const COutput& out, vecOutputs) {
if (out.nDepth < nMinDepth || out.nDepth > nMaxDepth)
continue;
Expand Down
9 changes: 7 additions & 2 deletions src/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1892,7 +1892,7 @@ CAmount CWallet::GetLockedWatchOnlyBalance() const
/**
* populate vCoins with vector of available COutputs.
*/
void CWallet::AvailableCoins(vector<COutput>& vCoins, bool fOnlyConfirmed, const CCoinControl* coinControl, bool fIncludeZeroValue, AvailableCoinsType nCoinType, bool fUseIX) const
void CWallet::AvailableCoins(vector<COutput>& vCoins, bool fOnlyConfirmed, const CCoinControl* coinControl, bool fIncludeZeroValue, AvailableCoinsType nCoinType, bool fUseIX, int nWatchonlyConfig) const
{
vCoins.clear();

Expand Down Expand Up @@ -1948,7 +1948,11 @@ void CWallet::AvailableCoins(vector<COutput>& vCoins, bool fOnlyConfirmed, const
continue;
if (mine == ISMINE_NO)
continue;
if (mine == ISMINE_WATCH_ONLY)

if ((mine == ISMINE_MULTISIG || mine == ISMINE_SPENDABLE) && nWatchonlyConfig == 2)
continue;

if (mine == ISMINE_WATCH_ONLY && nWatchonlyConfig == 1)
continue;

if (IsLockedCoin((*it).first, i) && nCoinType != ONLY_10000)
Expand All @@ -1963,6 +1967,7 @@ void CWallet::AvailableCoins(vector<COutput>& vCoins, bool fOnlyConfirmed, const
fIsSpendable = true;
if ((mine & ISMINE_MULTISIG) != ISMINE_NO)
fIsSpendable = true;

vCoins.emplace_back(COutput(pcoin, i, nDepth, fIsSpendable));
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
return nWalletMaxVersion >= wf;
}

void AvailableCoins(std::vector<COutput>& vCoins, bool fOnlyConfirmed = true, const CCoinControl* coinControl = NULL, bool fIncludeZeroValue = false, AvailableCoinsType nCoinType = ALL_COINS, bool fUseIX = false) const;
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;
std::map<CBitcoinAddress, std::vector<COutput> > AvailableCoinsByAddress(bool fConfirmed = true, CAmount maxCoinValue = 0);
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;

Expand Down

0 comments on commit c3671b5

Please sign in to comment.