Optionally filter balances by min value in z_getbalances
This commit is contained in:
@@ -3,7 +3,6 @@
|
|||||||
// Copyright (c) 2016-2020 The Hush developers
|
// Copyright (c) 2016-2020 The Hush developers
|
||||||
// Distributed under the GPLv3 software license, see the accompanying
|
// Distributed under the GPLv3 software license, see the accompanying
|
||||||
// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
|
// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
* Copyright © 2014-2019 The SuperNET Developers. *
|
* Copyright © 2014-2019 The SuperNET Developers. *
|
||||||
* *
|
* *
|
||||||
@@ -22,10 +21,8 @@
|
|||||||
#include "rpc/client.h"
|
#include "rpc/client.h"
|
||||||
#include "rpc/protocol.h"
|
#include "rpc/protocol.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include <univalue.h>
|
#include <univalue.h>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
@@ -138,8 +135,6 @@ static const CRPCConvertParam vRPCConvertParams[] =
|
|||||||
{ "z_listunspent", 1 },
|
{ "z_listunspent", 1 },
|
||||||
{ "z_listunspent", 2 },
|
{ "z_listunspent", 2 },
|
||||||
{ "z_listunspent", 3 },
|
{ "z_listunspent", 3 },
|
||||||
{ "z_getbalances", 0},
|
|
||||||
{ "z_getbalances", 1},
|
|
||||||
{ "z_getbalance", 1},
|
{ "z_getbalance", 1},
|
||||||
{ "z_getnotescount", 0},
|
{ "z_getnotescount", 0},
|
||||||
{ "z_gettotalbalance", 0},
|
{ "z_gettotalbalance", 0},
|
||||||
|
|||||||
@@ -3636,7 +3636,7 @@ UniValue z_getbalances(const UniValue& params, bool fHelp, const CPubKey& mypk)
|
|||||||
if (!EnsureWalletIsAvailable(fHelp))
|
if (!EnsureWalletIsAvailable(fHelp))
|
||||||
return NullUniValue;
|
return NullUniValue;
|
||||||
|
|
||||||
if (fHelp || params.size() > 0)
|
if (fHelp || params.size() > 1)
|
||||||
throw runtime_error(
|
throw runtime_error(
|
||||||
"z_getbalances\n"
|
"z_getbalances\n"
|
||||||
"\nReturns array of addresses with their unspent shielded balances.\n"
|
"\nReturns array of addresses with their unspent shielded balances.\n"
|
||||||
@@ -3656,28 +3656,31 @@ UniValue z_getbalances(const UniValue& params, bool fHelp, const CPubKey& mypk)
|
|||||||
|
|
||||||
"\nExamples\n"
|
"\nExamples\n"
|
||||||
+ HelpExampleCli("z_getbalances", "")
|
+ HelpExampleCli("z_getbalances", "")
|
||||||
|
+ HelpExampleCli("z_getbalances", "0.01")
|
||||||
+ HelpExampleRpc("z_getbalances", "")
|
+ HelpExampleRpc("z_getbalances", "")
|
||||||
|
+ HelpExampleRpc("z_getbalances", "0.42069")
|
||||||
);
|
);
|
||||||
|
|
||||||
RPCTypeCheck(params, boost::assign::list_of(UniValue::VNUM));
|
//RPCTypeCheck(params, boost::assign::list_of(UniValue::VNUM));
|
||||||
|
|
||||||
LOCK2(cs_main, pwalletMain->cs_wallet);
|
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||||||
|
|
||||||
|
// ignore amount=0 zaddrs by default
|
||||||
|
CAmount nMinBal = 1; // puposhis
|
||||||
|
if (params.size() > 0)
|
||||||
|
nMinBal = AmountFromValue(params[0]);
|
||||||
|
|
||||||
std::set<libzcash::PaymentAddress> zaddrs = {};
|
std::set<libzcash::PaymentAddress> zaddrs = {};
|
||||||
std::set<libzcash::SaplingPaymentAddress> saplingzaddrs = {};
|
std::set<libzcash::SaplingPaymentAddress> saplingzaddrs = {};
|
||||||
pwalletMain->GetSaplingPaymentAddresses(saplingzaddrs);
|
pwalletMain->GetSaplingPaymentAddresses(saplingzaddrs);
|
||||||
|
|
||||||
zaddrs.insert(saplingzaddrs.begin(), saplingzaddrs.end());
|
zaddrs.insert(saplingzaddrs.begin(), saplingzaddrs.end());
|
||||||
|
|
||||||
UniValue results(UniValue::VARR);
|
|
||||||
|
|
||||||
int nMinDepth = 1;
|
int nMinDepth = 1;
|
||||||
int nMaxDepth = 9999999;
|
|
||||||
std::vector<SaplingNoteEntry> saplingEntries;
|
std::vector<SaplingNoteEntry> saplingEntries;
|
||||||
pwalletMain->GetFilteredNotes(saplingEntries, zaddrs, nMinDepth);
|
pwalletMain->GetFilteredNotes(saplingEntries, zaddrs, nMinDepth);
|
||||||
|
|
||||||
std::map<std::string, CAmount> mapBalances;
|
std::map<std::string, CAmount> mapBalances;
|
||||||
|
|
||||||
for (auto & entry : saplingEntries) {
|
for (auto & entry : saplingEntries) {
|
||||||
auto zaddr = EncodePaymentAddress(entry.address);
|
auto zaddr = EncodePaymentAddress(entry.address);
|
||||||
CAmount nBalance = CAmount(entry.note.value());
|
CAmount nBalance = CAmount(entry.note.value());
|
||||||
@@ -3698,11 +3701,15 @@ UniValue z_getbalances(const UniValue& params, bool fHelp, const CPubKey& mypk)
|
|||||||
return l.first > r.first;
|
return l.first > r.first;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
UniValue results(UniValue::VARR);
|
||||||
for (auto & entry : vec) {
|
for (auto & entry : vec) {
|
||||||
UniValue obj(UniValue::VOBJ);
|
UniValue obj(UniValue::VOBJ);
|
||||||
obj.push_back(Pair("address", entry.first));
|
obj.push_back(Pair("address", entry.first));
|
||||||
obj.push_back(Pair("balance", (double) entry.second / (uint64_t) 100000000L ));
|
auto balance = (double) entry.second / (uint64_t) 100000000L;
|
||||||
results.push_back(obj);
|
obj.push_back(Pair("balance", balance));
|
||||||
|
if(entry.second >= nMinBal) {
|
||||||
|
results.push_back(obj);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return results;
|
return results;
|
||||||
|
|||||||
Reference in New Issue
Block a user