Skip to content

Commit

Permalink
include mints metadata in 'listmintedzerocoins' output
Browse files Browse the repository at this point in the history
Signed-off-by: observerdev <dev@obsr.org>
  • Loading branch information
random-zebra authored and observerdev committed Oct 24, 2018
1 parent 5fb6c26 commit b5649eb
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/rpc/client.cpp
Expand Up @@ -123,6 +123,7 @@ static const CRPCConvertParam vRPCConvertParams[] =
{"autocombinerewards", 1},
{"getzerocoinbalance", 0},
{"listmintedzerocoins", 0},
{"listmintedzerocoins", 1},
{"listspentzerocoins", 0},
{"listzerocoinamounts", 0},
{"mintzerocoin", 0},
Expand Down
55 changes: 47 additions & 8 deletions src/rpcwallet.cpp
Expand Up @@ -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<CMintMeta> setMints = pwalletMain->zobsrTracker->ListMints(true, false, true);
set<CMintMeta> 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;
}

Expand Down

0 comments on commit b5649eb

Please sign in to comment.