mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 12:02:48 +01:00
RPC: Add listaddressbalances
(#1972)
This commit is contained in:
parent
118eeded6d
commit
9451782a04
@ -47,6 +47,7 @@ static const CRPCConvertParam vRPCConvertParams[] =
|
||||
{ "getreceivedbyaddress", 2, "addlockconf" },
|
||||
{ "getreceivedbyaccount", 1, "minconf" },
|
||||
{ "getreceivedbyaccount", 2, "addlockconf" },
|
||||
{ "listaddressbalances", 0, "minamount" },
|
||||
{ "listreceivedbyaddress", 0, "minconf" },
|
||||
{ "listreceivedbyaddress", 1, "addlockconf" },
|
||||
{ "listreceivedbyaddress", 2, "include_empty" },
|
||||
|
@ -553,6 +553,45 @@ UniValue listaddressgroupings(const JSONRPCRequest& request)
|
||||
return jsonGroupings;
|
||||
}
|
||||
|
||||
UniValue listaddressbalances(const JSONRPCRequest& request)
|
||||
{
|
||||
if (!EnsureWalletIsAvailable(request.fHelp))
|
||||
return NullUniValue;
|
||||
|
||||
if (request.fHelp || request.params.size() > 1)
|
||||
throw std::runtime_error(
|
||||
"listaddressbalances ( minamount )\n"
|
||||
"\nLists addresses of this wallet and their balances\n"
|
||||
"\nArguments:\n"
|
||||
"1. minamount (numeric, optional, default=0) Minimum balance in " + CURRENCY_UNIT + " an address should have to be shown in the list\n"
|
||||
"\nResult:\n"
|
||||
"{\n"
|
||||
" \"address\": amount, (string) The dash address and the amount in " + CURRENCY_UNIT + "\n"
|
||||
" ,...\n"
|
||||
"}\n"
|
||||
"\nExamples:\n"
|
||||
+ HelpExampleCli("listaddressbalances", "")
|
||||
+ HelpExampleCli("listaddressbalances", "10")
|
||||
+ HelpExampleRpc("listaddressbalances", "")
|
||||
+ HelpExampleRpc("listaddressbalances", "10")
|
||||
);
|
||||
|
||||
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||||
|
||||
// Whether to include addresses with zero balances
|
||||
CAmount nMinAmount = 0;
|
||||
if (request.params.size() > 0)
|
||||
nMinAmount = request.params[0].get_int64() * COIN;
|
||||
|
||||
UniValue jsonBalances(UniValue::VOBJ);
|
||||
std::map<CTxDestination, CAmount> balances = pwalletMain->GetAddressBalances();
|
||||
for (auto& balance : balances)
|
||||
if (balance.second >= nMinAmount)
|
||||
jsonBalances.push_back(Pair(CBitcoinAddress(balance.first).ToString(), ValueFromAmount(balance.second)));
|
||||
|
||||
return jsonBalances;
|
||||
}
|
||||
|
||||
UniValue signmessage(const JSONRPCRequest& request)
|
||||
{
|
||||
if (!EnsureWalletIsAvailable(request.fHelp))
|
||||
@ -2832,6 +2871,7 @@ static const CRPCCommand commands[] =
|
||||
{ "wallet", "keypoolrefill", &keypoolrefill, true, {"newsize"} },
|
||||
{ "wallet", "listaccounts", &listaccounts, false, {"minconf","addlockconf","include_watchonly"} },
|
||||
{ "wallet", "listaddressgroupings", &listaddressgroupings, false, {} },
|
||||
{ "wallet", "listaddressbalances", &listaddressbalances, false, {"minamount"} },
|
||||
{ "wallet", "listlockunspent", &listlockunspent, false, {} },
|
||||
{ "wallet", "listreceivedbyaccount", &listreceivedbyaccount, false, {"minconf","addlockconf","include_empty","include_watchonly"} },
|
||||
{ "wallet", "listreceivedbyaddress", &listreceivedbyaddress, false, {"minconf","addlockconf","include_empty","include_watchonly"} },
|
||||
|
Loading…
Reference in New Issue
Block a user