Skip to content

Commit e491e5b

Browse files
committed
fix listreceivedbyaddress to sum amounts for each asset.
1 parent 28c66dc commit e491e5b

File tree

1 file changed

+25
-20
lines changed

1 file changed

+25
-20
lines changed

src/wallet/rpcwallet.cpp

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,7 @@ UniValue getreceivedbyaccount(const JSONRPCRequest& request)
839839
set<CTxDestination> setAddress = pwalletMain->GetAccountAddresses(strAccount);
840840

841841
// Tally
842-
CAmount nAmount = 0;
842+
CAmountMap mapAmount;
843843
for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it)
844844
{
845845
const CWalletTx& wtx = (*it).second;
@@ -849,13 +849,17 @@ UniValue getreceivedbyaccount(const JSONRPCRequest& request)
849849
for (unsigned int i = 0; i < wtx.tx->vout.size(); i++)
850850
{
851851
CTxDestination address;
852-
if (ExtractDestination(wtx.tx->vout[i].scriptPubKey, address) && IsMine(*pwalletMain, address) && setAddress.count(address))
853-
if (wtx.GetDepthInMainChain() >= nMinDepth && wtx.GetOutputValueOut(i) >= 0)
854-
nAmount += wtx.GetOutputValueOut(i);
852+
if (ExtractDestination(wtx.tx->vout[i].scriptPubKey, address) && IsMine(*pwalletMain, address) && setAddress.count(address)) {
853+
if (wtx.GetDepthInMainChain() >= nMinDepth && wtx.GetOutputValueOut(i) >= 0) {
854+
CAmountMap wtxValue;
855+
wtxValue[wtx.GetOutputAsset(i)] = wtx.GetOutputValueOut(i);
856+
mapAmount += wtxValue;
857+
}
858+
}
855859
}
856860
}
857861

858-
return ValueFromAmount(nAmount);
862+
return PushAssetBalance(mapAmount, pwalletMain, "");
859863
}
860864

861865

@@ -1380,12 +1384,12 @@ struct tallyitem
13801384
{
13811385
CBitcoinAddress address;
13821386
CAmount nAmount;
1387+
CAmountMap mapAmount;
13831388
int nConf;
13841389
vector<uint256> txids;
13851390
bool fIsWatchonly;
13861391
tallyitem()
13871392
{
1388-
nAmount = 0;
13891393
nConf = std::numeric_limits<int>::max();
13901394
fIsWatchonly = false;
13911395
}
@@ -1408,14 +1412,14 @@ UniValue ListReceived(const UniValue& params, bool fByAccounts)
14081412
if(params[2].get_bool())
14091413
filter = filter | ISMINE_WATCH_ONLY;
14101414

1411-
std::string strasset = "bitcoin";
1415+
std::string strasset = "";
14121416
if (params.size() > 3 && params[3].isStr()) {
14131417
if (fByAccounts)
14141418
throw JSONRPCError(RPC_WALLET_ERROR, "Accounts are completely disabled for assets.");
14151419
strasset = params[3].get_str();
14161420
}
14171421
CAsset asset;
1418-
if (strasset != "*")
1422+
if (strasset != "")
14191423
asset = GetAssetFromString(strasset);
14201424

14211425
// Tally
@@ -1444,14 +1448,16 @@ UniValue ListReceived(const UniValue& params, bool fByAccounts)
14441448
if (wtx.GetOutputValueOut(i) < 0)
14451449
continue;
14461450

1447-
if (strasset != "*" && wtx.GetOutputAsset(i) != asset)
1451+
if (strasset != "" && wtx.GetOutputAsset(i) != asset)
14481452
continue;
14491453

14501454
CBitcoinAddress bitcoinaddress(address);
14511455

14521456
tallyitem& item = mapTally[address];
14531457
item.address = bitcoinaddress;
1454-
item.nAmount += wtx.GetOutputValueOut(i);
1458+
CAmountMap wtxValue;
1459+
wtxValue[wtx.GetOutputAsset(i)] = wtx.GetOutputValueOut(i);
1460+
item.mapAmount += wtxValue;
14551461
item.nConf = min(item.nConf, nDepth);
14561462
item.txids.push_back(wtx.GetHash());
14571463
if (mine & ISMINE_WATCH_ONLY)
@@ -1471,21 +1477,21 @@ UniValue ListReceived(const UniValue& params, bool fByAccounts)
14711477
continue;
14721478

14731479
CBitcoinAddress fulladdress = address;
1474-
CAmount nAmount = 0;
1480+
CAmountMap mapAmount;
14751481
int nConf = std::numeric_limits<int>::max();
14761482
bool fIsWatchonly = false;
14771483
if (it != mapTally.end())
14781484
{
14791485
fulladdress = (*it).second.address;
1480-
nAmount = (*it).second.nAmount;
1486+
mapAmount = (*it).second.mapAmount;
14811487
nConf = (*it).second.nConf;
14821488
fIsWatchonly = (*it).second.fIsWatchonly;
14831489
}
14841490

14851491
if (fByAccounts)
14861492
{
14871493
tallyitem& _item = mapAccountTally[strAccount];
1488-
_item.nAmount += nAmount;
1494+
_item.mapAmount += mapAmount;
14891495
_item.nConf = min(_item.nConf, nConf);
14901496
_item.fIsWatchonly = fIsWatchonly;
14911497
}
@@ -1498,10 +1504,9 @@ UniValue ListReceived(const UniValue& params, bool fByAccounts)
14981504
fulladdress = fulladdress.GetUnblinded();
14991505
obj.push_back(Pair("address", fulladdress.ToString()));
15001506
obj.push_back(Pair("account", strAccount));
1501-
obj.push_back(Pair("amount", ValueFromAmount(nAmount)));
1507+
obj.push_back(Pair("amount", PushAssetBalance(mapAmount, pwalletMain, strasset)));
15021508
obj.push_back(Pair("confirmations", (nConf == std::numeric_limits<int>::max() ? 0 : nConf)));
1503-
if (!fByAccounts)
1504-
obj.push_back(Pair("label", strAccount));
1509+
obj.push_back(Pair("label", strAccount));
15051510
UniValue transactions(UniValue::VARR);
15061511
if (it != mapTally.end())
15071512
{
@@ -1519,13 +1524,13 @@ UniValue ListReceived(const UniValue& params, bool fByAccounts)
15191524
{
15201525
for (map<string, tallyitem>::iterator it = mapAccountTally.begin(); it != mapAccountTally.end(); ++it)
15211526
{
1522-
CAmount nAmount = (*it).second.nAmount;
1527+
CAmountMap mapAmount = (*it).second.mapAmount;
15231528
int nConf = (*it).second.nConf;
15241529
UniValue obj(UniValue::VOBJ);
15251530
if((*it).second.fIsWatchonly)
15261531
obj.push_back(Pair("involvesWatchonly", true));
15271532
obj.push_back(Pair("account", (*it).first));
1528-
obj.push_back(Pair("amount", ValueFromAmount(nAmount)));
1533+
obj.push_back(Pair("amount", PushAssetBalance(mapAmount, pwalletMain, strasset)));
15291534
obj.push_back(Pair("confirmations", (nConf == std::numeric_limits<int>::max() ? 0 : nConf)));
15301535
ret.push_back(obj);
15311536
}
@@ -1541,13 +1546,13 @@ UniValue listreceivedbyaddress(const JSONRPCRequest& request)
15411546

15421547
if (request.fHelp || request.params.size() > 4)
15431548
throw runtime_error(
1544-
"listreceivedbyaddress ( minconf include_empty include_watchonly, asset)\n"
1549+
"listreceivedbyaddress ( minconf include_empty include_watchonly, \"assetlabel\" )\n"
15451550
"\nList balances by receiving address.\n"
15461551
"\nArguments:\n"
15471552
"1. minconf (numeric, optional, default=1) The minimum number of confirmations before payments are included.\n"
15481553
"2. include_empty (bool, optional, default=false) Whether to include addresses that haven't received any payments.\n"
15491554
"3. include_watchonly (bool, optional, default=false) Whether to include watch-only addresses (see 'importaddress').\n"
1550-
"4. \"asset\" (string, optional, default=bitcoin) The hex asset id or label to filter for. \"*\" is used to list all results.\n"
1555+
"4. \"assetlabel\" (string, optional) The hex asset id or asset label to filter for.\n"
15511556
"\nResult:\n"
15521557
"[\n"
15531558
" {\n"

0 commit comments

Comments
 (0)