Add z_listreceivedbyaddress RPC call
This commit is contained in:
parent
1b141933e5
commit
6c41028f7c
|
@ -98,6 +98,7 @@ static const CRPCConvertParam vRPCConvertParams[] =
|
||||||
{ "zcbenchmark", 1 },
|
{ "zcbenchmark", 1 },
|
||||||
{ "zcbenchmark", 2 },
|
{ "zcbenchmark", 2 },
|
||||||
{ "getblocksubsidy", 0},
|
{ "getblocksubsidy", 0},
|
||||||
|
{ "z_listreceivedbyaddress", 1},
|
||||||
{ "z_getbalance", 1},
|
{ "z_getbalance", 1},
|
||||||
{ "z_gettotalbalance", 0},
|
{ "z_gettotalbalance", 0},
|
||||||
{ "z_sendmany", 1},
|
{ "z_sendmany", 1},
|
||||||
|
|
|
@ -385,6 +385,7 @@ static const CRPCCommand vRPCCommands[] =
|
||||||
{ "wallet", "zcrawjoinsplit", &zc_raw_joinsplit, true },
|
{ "wallet", "zcrawjoinsplit", &zc_raw_joinsplit, true },
|
||||||
{ "wallet", "zcrawreceive", &zc_raw_receive, true },
|
{ "wallet", "zcrawreceive", &zc_raw_receive, true },
|
||||||
{ "wallet", "zcsamplejoinsplit", &zc_sample_joinsplit, true },
|
{ "wallet", "zcsamplejoinsplit", &zc_sample_joinsplit, true },
|
||||||
|
{ "wallet", "z_listreceivedbyaddress",&z_listreceivedbyaddress,false },
|
||||||
{ "wallet", "z_getbalance", &z_getbalance, false },
|
{ "wallet", "z_getbalance", &z_getbalance, false },
|
||||||
{ "wallet", "z_gettotalbalance", &z_gettotalbalance, false },
|
{ "wallet", "z_gettotalbalance", &z_gettotalbalance, false },
|
||||||
{ "wallet", "z_sendmany", &z_sendmany, false },
|
{ "wallet", "z_sendmany", &z_sendmany, false },
|
||||||
|
|
|
@ -256,6 +256,7 @@ extern json_spirit::Value z_getnewaddress(const json_spirit::Array& params, bool
|
||||||
extern json_spirit::Value z_listaddresses(const json_spirit::Array& params, bool fHelp); // in rpcwallet.cpp
|
extern json_spirit::Value z_listaddresses(const json_spirit::Array& params, bool fHelp); // in rpcwallet.cpp
|
||||||
extern json_spirit::Value z_exportwallet(const json_spirit::Array& params, bool fHelp); // in rpcdump.cpp
|
extern json_spirit::Value z_exportwallet(const json_spirit::Array& params, bool fHelp); // in rpcdump.cpp
|
||||||
extern json_spirit::Value z_importwallet(const json_spirit::Array& params, bool fHelp); // in rpcdump.cpp
|
extern json_spirit::Value z_importwallet(const json_spirit::Array& params, bool fHelp); // in rpcdump.cpp
|
||||||
|
extern json_spirit::Value z_listreceivedbyaddress(const json_spirit::Array& params, bool fHelp); // in rpcwallet.cpp
|
||||||
extern json_spirit::Value z_getbalance(const json_spirit::Array& params, bool fHelp); // in rpcwallet.cpp
|
extern json_spirit::Value z_getbalance(const json_spirit::Array& params, bool fHelp); // in rpcwallet.cpp
|
||||||
extern json_spirit::Value z_gettotalbalance(const json_spirit::Array& params, bool fHelp); // in rpcwallet.cpp
|
extern json_spirit::Value z_gettotalbalance(const json_spirit::Array& params, bool fHelp); // in rpcwallet.cpp
|
||||||
extern json_spirit::Value z_sendmany(const json_spirit::Array& params, bool fHelp); // in rpcwallet.cpp
|
extern json_spirit::Value z_sendmany(const json_spirit::Array& params, bool fHelp); // in rpcwallet.cpp
|
||||||
|
|
|
@ -2886,6 +2886,67 @@ CAmount getBalanceZaddr(std::string address, size_t minDepth = 1) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Value z_listreceivedbyaddress(const Array& params, bool fHelp)
|
||||||
|
{
|
||||||
|
if (!EnsureWalletIsAvailable(fHelp))
|
||||||
|
return Value::null;
|
||||||
|
|
||||||
|
if (fHelp || params.size()==0 || params.size() >2)
|
||||||
|
throw runtime_error(
|
||||||
|
"z_listreceivedbyaddress \"address\" ( minconf )\n"
|
||||||
|
"\nReturn a list of amounts received by a zaddr belonging to the node’s wallet.\n"
|
||||||
|
"\nArguments:\n"
|
||||||
|
"1. \"address\" (string) The private address.\n"
|
||||||
|
"2. minconf (numeric, optional, default=1) Only include transactions confirmed at least this many times.\n"
|
||||||
|
"\nResult:\n"
|
||||||
|
"{\n"
|
||||||
|
" \"txid\": xxxxx, (string) the transaction id\n"
|
||||||
|
" \"amount\": xxxxx, (numeric) the amount of value in the note\n"
|
||||||
|
" \"memo\": xxxxx, (string) hexademical string representation of memo field\n"
|
||||||
|
"}\n"
|
||||||
|
);
|
||||||
|
|
||||||
|
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||||||
|
|
||||||
|
int nMinDepth = 1;
|
||||||
|
if (params.size() > 1) {
|
||||||
|
nMinDepth = params[1].get_int();
|
||||||
|
}
|
||||||
|
if (nMinDepth < 0) {
|
||||||
|
throw JSONRPCError(RPC_INVALID_PARAMETER, "Minimum number of confirmations cannot be less than 0");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check that the from address is valid.
|
||||||
|
auto fromaddress = params[0].get_str();
|
||||||
|
|
||||||
|
libzcash::PaymentAddress zaddr;
|
||||||
|
CZCPaymentAddress address(fromaddress);
|
||||||
|
try {
|
||||||
|
zaddr = address.Get();
|
||||||
|
} catch (std::runtime_error) {
|
||||||
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid zaddr.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!pwalletMain->HaveSpendingKey(zaddr)) {
|
||||||
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "From address does not belong to this node, zaddr spending key not found.");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Array result;
|
||||||
|
std::vector<CNotePlaintextEntry> entries;
|
||||||
|
pwalletMain->GetFilteredNotes(entries, fromaddress, nMinDepth, false);
|
||||||
|
for (CNotePlaintextEntry & entry : entries) {
|
||||||
|
Object obj;
|
||||||
|
obj.push_back(Pair("txid",entry.jsop.hash.ToString()));
|
||||||
|
obj.push_back(Pair("amount", ValueFromAmount(CAmount(entry.plaintext.value))));
|
||||||
|
std::string data(entry.plaintext.memo.begin(), entry.plaintext.memo.end());
|
||||||
|
obj.push_back(Pair("memo", HexStr(data)));
|
||||||
|
result.push_back(obj);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Value z_getbalance(const Array& params, bool fHelp)
|
Value z_getbalance(const Array& params, bool fHelp)
|
||||||
{
|
{
|
||||||
if (!EnsureWalletIsAvailable(fHelp))
|
if (!EnsureWalletIsAvailable(fHelp))
|
||||||
|
|
Loading…
Reference in New Issue