From b3c7e048ab583556e79bd5651abc49b443227740 Mon Sep 17 00:00:00 2001 From: DenioD <41270280+DenioD@users.noreply.github.com> Date: Sat, 25 Apr 2020 00:30:06 +0200 Subject: [PATCH] add z_getnotescount as rpc call ported for Hush from https://github.com/zcash/zcash/pull/4465 --- src/rpc/client.cpp | 1 + src/wallet/rpcwallet.cpp | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/src/rpc/client.cpp b/src/rpc/client.cpp index 4107ad6f8..79011da34 100644 --- a/src/rpc/client.cpp +++ b/src/rpc/client.cpp @@ -139,6 +139,7 @@ static const CRPCConvertParam vRPCConvertParams[] = { "z_listunspent", 2 }, { "z_listunspent", 3 }, { "z_getbalance", 1}, + { "z_getnotescount", 0}, { "z_gettotalbalance", 0}, { "z_gettotalbalance", 1}, { "z_gettotalbalance", 2}, diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index b8115767a..5afd0c4e8 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4213,6 +4213,42 @@ UniValue z_getbalance(const UniValue& params, bool fHelp, const CPubKey& mypk) return ValueFromAmount(nBalance); } +UniValue z_getnotescount(const UniValue& params, bool fHelp,const CPubKey& mypk) +{ + if (!EnsureWalletIsAvailable(fHelp)) + return NullUniValue; + + if (fHelp || params.size() > 1) + throw runtime_error( + "z_getnotescount\n" + "\nArguments:\n" + "1. minconf (numeric, optional, default=1) Only include notes in transactions confirmed at least this many times.\n" + "\nReturns the number of sprout and sapling notes available in the wallet.\n" + "\nResult:\n" + "{\n" + " \"sapling\" (numeric) the number of sapling notes in the wallet\n" + "}\n" + "\nExamples:\n" + + HelpExampleCli("z_getnotescount", "0") + ); + + LOCK2(cs_main, pwalletMain->cs_wallet); + + int nMinDepth = 1; + if (params.size() > 0) + nMinDepth = params[0].get_int(); + + int sapling = 0; + for (auto& wtx : pwalletMain->mapWallet) { + if (wtx.second.GetDepthInMainChain() >= nMinDepth) { + sapling += wtx.second.mapSaplingNoteData.size(); + } + } + UniValue ret(UniValue::VOBJ); + ret.push_back(Pair("sapling", sapling)); + + return ret; +} UniValue z_gettotalbalance(const UniValue& params, bool fHelp, const CPubKey& mypk) { @@ -8368,6 +8404,7 @@ static const CRPCCommand commands[] = { "wallet", "z_getinfo", &z_getinfo, true }, { "wallet", "z_listsentbyaddress", &z_listsentbyaddress, true }, { "wallet", "z_listreceivedbyaddress", &z_listreceivedbyaddress, true }, + { "wallet", "z_getnotescount", &z_getnotescount, false }, // TODO: rearrange into another category { "disclosure", "z_getpaymentdisclosure", &z_getpaymentdisclosure, true }, { "disclosure", "z_validatepaymentdisclosure", &z_validatepaymentdisclosure, true }