From b5649ebef43a41340d143e461976f74ed6af5157 Mon Sep 17 00:00:00 2001 From: random-zebra Date: Sun, 7 Oct 2018 10:31:27 +0200 Subject: [PATCH] include mints metadata in 'listmintedzerocoins' output Signed-off-by: observerdev --- src/rpc/client.cpp | 1 + src/rpcwallet.cpp | 55 +++++++++++++++++++++++++++++++++++++++------- 2 files changed, 48 insertions(+), 8 deletions(-) diff --git a/src/rpc/client.cpp b/src/rpc/client.cpp index 427081e..648f7c5 100644 --- a/src/rpc/client.cpp +++ b/src/rpc/client.cpp @@ -123,6 +123,7 @@ static const CRPCConvertParam vRPCConvertParams[] = {"autocombinerewards", 1}, {"getzerocoinbalance", 0}, {"listmintedzerocoins", 0}, + {"listmintedzerocoins", 1}, {"listspentzerocoins", 0}, {"listzerocoinamounts", 0}, {"mintzerocoin", 0}, diff --git a/src/rpcwallet.cpp b/src/rpcwallet.cpp index a4fe8d2..929108f 100644 --- a/src/rpcwallet.cpp +++ b/src/rpcwallet.cpp @@ -2562,32 +2562,71 @@ UniValue getzerocoinbalance(const UniValue& params, bool fHelp) UniValue listmintedzerocoins(const UniValue& params, bool fHelp) { - if (fHelp || params.size() != 0) + if (fHelp || params.size() > 2) throw runtime_error( - "listmintedzerocoins\n" + "listmintedzerocoins (fVerbose) (fMatureOnly)\n" "\nList all zOBSR mints in the wallet.\n" + HelpRequiringPassphrase() + "\n" - "\nResult:\n" + "\nArguments:\n" + "1. fVerbose (boolean, optional, default=false) Output mints metadata.\n" + "2. fMatureOnly (boolean, optional, default=false) List only mature mints. (Set only if fVerbose is specified)\n" + + "\nResult (with fVerbose=false):\n" "[\n" " \"xxx\" (string) Pubcoin in hex format.\n" " ,...\n" "]\n" + "\nResult (with fVerbose=true):\n" + "[\n" + " {\n" + " \"serial hash\": \"xxx\", (string) Mint serial hash in hex format.\n" + " \"version\": n, (numeric) Zerocoin version number.\n" + " \"zOBSR ID\": \"xxx\", (string) Pubcoin in hex format.\n" + " \"denomination\": n, (numeric) Coin denomination.\n" + " \"confirmations\": n (numeric) Number of confirmations.\n" + " }\n" + " ,..." + "]\n" + "\nExamples:\n" + - HelpExampleCli("listmintedzerocoins", "") + HelpExampleRpc("listmintedzerocoins", "")); + HelpExampleCli("listmintedzerocoins", "") + HelpExampleRpc("listmintedzerocoins", "") + + HelpExampleCli("listmintedzerocoins", "true") + HelpExampleRpc("listmintedzerocoins", "true") + + HelpExampleCli("listmintedzerocoins", "true true") + HelpExampleRpc("listmintedzerocoins", "true, true")); + + bool fVerbose = (params.size() > 0) ? params[0].get_bool() : false; + bool fMatureOnly = (params.size() > 1) ? params[1].get_bool() : false; LOCK2(cs_main, pwalletMain->cs_wallet); EnsureWalletIsUnlocked(true); CWalletDB walletdb(pwalletMain->strWalletFile); - set setMints = pwalletMain->zobsrTracker->ListMints(true, false, true); + set setMints = pwalletMain->zobsrTracker->ListMints(true, fMatureOnly, true); - UniValue jsonList(UniValue::VARR); - for (const CMintMeta& meta : setMints) - jsonList.push_back(meta.hashPubcoin.GetHex()); + int nBestHeight = chainActive.Height(); + UniValue jsonList(UniValue::VARR); + if (fVerbose) { + for (const CMintMeta& m : setMints) { + // Construct mint object + UniValue objMint(UniValue::VOBJ); + objMint.push_back(Pair("serial hash", m.hashSerial.GetHex())); // Serial hash + objMint.push_back(Pair("version", m.nVersion)); // Zerocoin version + objMint.push_back(Pair("zOBSR ID", m.hashPubcoin.GetHex())); // PubCoin + int denom = libzerocoin::ZerocoinDenominationToInt(m.denom); + objMint.push_back(Pair("denomination", denom)); // Denomination + int nConfirmations = (m.nHeight && nBestHeight > m.nHeight) ? nBestHeight - m.nHeight : 0; + objMint.push_back(Pair("confirmations", nConfirmations)); // Confirmations + // Push back mint object + jsonList.push_back(objMint); + } + } else { + for (const CMintMeta& m : setMints) + // Push back PubCoin + jsonList.push_back(m.hashPubcoin.GetHex()); + } return jsonList; }