Skip to content

Commit

Permalink
added includedWatchonly argument to listreceivedbyaddress/...account
Browse files Browse the repository at this point in the history
  • Loading branch information
sdkfjlsfjlskdfjlsdjflsjf committed Jul 2, 2014
1 parent f87ba3d commit 0fa2f88
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/rpcclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ static const CRPCConvertParam vRPCConvertParams[] =
{ "getreceivedbyaccount", 1 },
{ "listreceivedbyaddress", 0 },
{ "listreceivedbyaddress", 1 },
{ "listreceivedbyaddress", 2 },
{ "listreceivedbyaccount", 0 },
{ "listreceivedbyaccount", 1 },
{ "listreceivedbyaccount", 2 },
{ "getbalance", 1 },
{ "getbalance", 2 },
{ "getblockhash", 0 },
Expand All @@ -65,7 +67,6 @@ static const CRPCConvertParam vRPCConvertParams[] =
{ "listunspent", 1 },
{ "listunspent", 2 },
{ "getblock", 1 },
{ "gettransaction", 1},
{ "getrawtransaction", 1 },
{ "createrawtransaction", 0 },
{ "createrawtransaction", 1 },
Expand Down
38 changes: 31 additions & 7 deletions src/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -932,10 +932,12 @@ struct tallyitem
int64_t nAmount;
int nConf;
vector<uint256> txids;
bool fIsWatchonly;
tallyitem()
{
nAmount = 0;
nConf = std::numeric_limits<int>::max();
fIsWatchonly = false;
}
};

Expand All @@ -951,6 +953,11 @@ Value ListReceived(const Array& params, bool fByAccounts)
if (params.size() > 1)
fIncludeEmpty = params[1].get_bool();

isminefilter filter = MINE_SPENDABLE;
if(params.size() > 2)
if(params[2].get_bool())
filter = filter | MINE_WATCH_ONLY;

// Tally
map<CBitcoinAddress, tallyitem> mapTally;
for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it)
Expand All @@ -967,13 +974,19 @@ Value ListReceived(const Array& params, bool fByAccounts)
BOOST_FOREACH(const CTxOut& txout, wtx.vout)
{
CTxDestination address;
if (!ExtractDestination(txout.scriptPubKey, address) || !IsMine(*pwalletMain, address))
if (!ExtractDestination(txout.scriptPubKey, address))
continue;

isminefilter mine = IsMine(*pwalletMain, address);
if(!mine & filter)
continue;

tallyitem& item = mapTally[address];
item.nAmount += txout.nValue;
item.nConf = min(item.nConf, nDepth);
item.txids.push_back(wtx.GetHash());
if (mine & MINE_WATCH_ONLY)
item.fIsWatchonly = true;
}
}

Expand All @@ -990,21 +1003,26 @@ Value ListReceived(const Array& params, bool fByAccounts)

int64_t nAmount = 0;
int nConf = std::numeric_limits<int>::max();
bool fIsWatchonly = false;
if (it != mapTally.end())
{
nAmount = (*it).second.nAmount;
nConf = (*it).second.nConf;
fIsWatchonly = (*it).second.fIsWatchonly;
}

if (fByAccounts)
{
tallyitem& item = mapAccountTally[strAccount];
item.nAmount += nAmount;
item.nConf = min(item.nConf, nConf);
item.fIsWatchonly = fIsWatchonly;
}
else
{
Object obj;
if(fIsWatchonly)
obj.push_back(Pair("involvesWatchonly", true));
obj.push_back(Pair("address", address.ToString()));
obj.push_back(Pair("account", strAccount));
obj.push_back(Pair("amount", ValueFromAmount(nAmount)));
Expand All @@ -1029,6 +1047,8 @@ Value ListReceived(const Array& params, bool fByAccounts)
int64_t nAmount = (*it).second.nAmount;
int nConf = (*it).second.nConf;
Object obj;
if((*it).second.fIsWatchonly)
obj.push_back(Pair("involvesWatchonly", true));
obj.push_back(Pair("account", (*it).first));
obj.push_back(Pair("amount", ValueFromAmount(nAmount)));
obj.push_back(Pair("confirmations", (nConf == std::numeric_limits<int>::max() ? 0 : nConf)));
Expand All @@ -1041,17 +1061,19 @@ Value ListReceived(const Array& params, bool fByAccounts)

Value listreceivedbyaddress(const Array& params, bool fHelp)
{
if (fHelp || params.size() > 2)
if (fHelp || params.size() > 3)
throw runtime_error(
"listreceivedbyaddress ( minconf includeempty )\n"
"listreceivedbyaddress ( minconf includeempty includeWatchonly)\n"
"\nList balances by receiving address.\n"
"\nArguments:\n"
"1. minconf (numeric, optional, default=1) The minimum number of confirmations before payments are included.\n"
"2. includeempty (numeric, optional, dafault=false) Whether to include addresses that haven't received any payments.\n"
"3. includeWatchonly (bool, optional, default=false) Whether to include watchonly addresses (see 'importaddress').\n"

"\nResult:\n"
"[\n"
" {\n"
" \"involvesWatchonly\" : \"true\", (bool) Only returned if imported addresses were involved in transaction\n"
" \"address\" : \"receivingaddress\", (string) The receiving address\n"
" \"account\" : \"accountname\", (string) The account of the receiving address. The default account is \"\".\n"
" \"amount\" : x.xxx, (numeric) The total amount in btc received by the address\n"
Expand All @@ -1063,25 +1085,27 @@ Value listreceivedbyaddress(const Array& params, bool fHelp)
"\nExamples:\n"
+ HelpExampleCli("listreceivedbyaddress", "")
+ HelpExampleCli("listreceivedbyaddress", "6 true")
+ HelpExampleRpc("listreceivedbyaddress", "6, true")
+ HelpExampleRpc("listreceivedbyaddress", "6, true, true")
);

return ListReceived(params, false);
}

Value listreceivedbyaccount(const Array& params, bool fHelp)
{
if (fHelp || params.size() > 2)
if (fHelp || params.size() > 3)
throw runtime_error(
"listreceivedbyaccount ( minconf includeempty )\n"
"listreceivedbyaccount ( minconf includeempty includeWatchonly)\n"
"\nList balances by account.\n"
"\nArguments:\n"
"1. minconf (numeric, optional, default=1) The minimum number of confirmations before payments are included.\n"
"2. includeempty (boolean, optional, default=false) Whether to include accounts that haven't received any payments.\n"
"3. includeWatchonly (bool, optional, default=false) Whether to include watchonly addresses (see 'importaddress').\n"

"\nResult:\n"
"[\n"
" {\n"
" \"involvesWatchonly\" : \"true\", (bool) Only returned if imported addresses were involved in transaction\n"
" \"account\" : \"accountname\", (string) The account name of the receiving account\n"
" \"amount\" : x.xxx, (numeric) The total amount received by addresses with this account\n"
" \"confirmations\" : n (numeric) The number of confirmations of the most recent transaction included\n"
Expand All @@ -1092,7 +1116,7 @@ Value listreceivedbyaccount(const Array& params, bool fHelp)
"\nExamples:\n"
+ HelpExampleCli("listreceivedbyaccount", "")
+ HelpExampleCli("listreceivedbyaccount", "6 true")
+ HelpExampleRpc("listreceivedbyaccount", "6, true")
+ HelpExampleRpc("listreceivedbyaccount", "6, true, true")
);

return ListReceived(params, true);
Expand Down

0 comments on commit 0fa2f88

Please sign in to comment.