From e709997ff28724dbeb79980ffc0edaf45e287384 Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 10 Aug 2016 15:02:00 -0700 Subject: [PATCH] Implemented z_listaddresses to return all the zaddr in the wallet. --- src/rpcserver.cpp | 1 + src/rpcserver.h | 1 + src/wallet/rpcwallet.cpp | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp index 72d7515aa..3ad88b2e0 100644 --- a/src/rpcserver.cpp +++ b/src/rpcserver.cpp @@ -383,6 +383,7 @@ static const CRPCCommand vRPCCommands[] = { "wallet", "zcrawreceive", &zc_raw_receive, true }, { "wallet", "zcsamplejoinsplit", &zc_sample_joinsplit, true }, { "wallet", "z_getnewaddress", &z_getnewaddress, true }, + { "wallet", "z_listaddresses", &z_listaddresses, true }, { "wallet", "z_exportkey", &z_exportkey, true }, { "wallet", "z_importkey", &z_importkey, true }, { "wallet", "z_exportwallet", &z_exportwallet, true }, diff --git a/src/rpcserver.h b/src/rpcserver.h index 05f12fe1e..0e8b60b7b 100644 --- a/src/rpcserver.h +++ b/src/rpcserver.h @@ -246,6 +246,7 @@ extern json_spirit::Value getblocksubsidy(const json_spirit::Array& params, bool extern json_spirit::Value z_exportkey(const json_spirit::Array& params, bool fHelp); // in rpcdump.cpp extern json_spirit::Value z_importkey(const json_spirit::Array& params, bool fHelp); // in rpcdump.cpp extern json_spirit::Value z_getnewaddress(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_importwallet(const json_spirit::Array& params, bool fHelp); // in rpcdump.cpp diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 7315d7014..e37f56b50 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2795,3 +2795,35 @@ Value z_getnewaddress(const Array& params, bool fHelp) return result; } + +Value z_listaddresses(const Array& params, bool fHelp) +{ + if (!EnsureWalletIsAvailable(fHelp)) + return Value::null; + + if (fHelp || params.size() > 1) + throw runtime_error( + "z_listaddresses\n" + "\nReturns the list of zaddr belonging to the wallet.\n" + "\nArguments:\n" + "\nResult:\n" + "[ (json array of string)\n" + " \"zaddr\" (string) a zaddr belonging to the wallet\n" + " ,...\n" + "]\n" + "\nExamples:\n" + + HelpExampleCli("z_listaddresses", "") + + HelpExampleRpc("z_listaddresses", "") + ); + + LOCK2(cs_main, pwalletMain->cs_wallet); + + Array ret; + std::set addresses; + pwalletMain->GetPaymentAddresses(addresses); + for (auto addr : addresses ) { + ret.push_back(CZCPaymentAddress(addr).ToString()); + } + return ret; +} +