Skip to content

Commit

Permalink
Add getaccumulatorvalues RPC.
Browse files Browse the repository at this point in the history
Return the accumulator values associated with a particular block height.
  • Loading branch information
presstab committed May 9, 2018
1 parent abee3d9 commit 8a6d425
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
35 changes: 34 additions & 1 deletion src/rpcblockchain.cpp
Expand Up @@ -15,6 +15,7 @@
#include "util.h"
#include "utilmoneystr.h"
#include "accumulatormap.h"
#include "accumulators.h"

#include <stdint.h>
#include <univalue.h>
Expand Down Expand Up @@ -929,6 +930,38 @@ UniValue findserial(const UniValue& params, bool fHelp)
UniValue ret(UniValue::VOBJ);
ret.push_back(Pair("success", fSuccess));
ret.push_back(Pair("txid", txid.GetHex()));

return ret;
}

UniValue getaccumulatorvalues(const UniValue& params, bool fHelp)
{
if (fHelp || params.size() != 1)
throw runtime_error(
"getaccumulatorvalues \"height\"\n"
"\nReturns the accumulator values associated with a block height\n"

"\nArguments:\n"
"1. height (numeric, required) the height of the checkpoint.\n"

"\nExamples:\n" +
HelpExampleCli("getaccumulatorvalues", "\"height\"") + HelpExampleRpc("getaccumulatorvalues", "\"height\""));

int nHeight = params[0].get_int();

CBlockIndex* pindex = chainActive[nHeight];
if (!pindex)
throw JSONRPCError(RPC_INVALID_PARAMETER, "invalid block height");

UniValue ret(UniValue::VARR);
for (libzerocoin::CoinDenomination denom : libzerocoin::zerocoinDenomList) {
CBigNum bnValue;
if(!GetAccumulatorValueFromDB(pindex->nAccumulatorCheckpoint, denom, bnValue))
throw JSONRPCError(RPC_DATABASE_ERROR, "failed to find value in database");

UniValue obj(UniValue::VOBJ);
obj.push_back(Pair(std::to_string(denom), bnValue.GetHex()));
ret.push_back(obj);
}

return ret;
}
1 change: 1 addition & 0 deletions src/rpcclient.cpp
Expand Up @@ -140,6 +140,7 @@ static const CRPCConvertParam vRPCConvertParams[] =
{"searchdzpiv", 0},
{"searchdzpiv", 1},
{"searchdzpiv", 2},
{"getaccumulatorvalues", 0},
{"getfeeinfo", 0}
};

Expand Down
1 change: 1 addition & 0 deletions src/rpcserver.cpp
Expand Up @@ -298,6 +298,7 @@ static const CRPCCommand vRPCCommands[] =

/* Block chain and UTXO */
{"blockchain", "findserial", &findserial, true, false, false},
{"blockchain", "getaccumulatorvalues", &getaccumulatorvalues, true, false, false},
{"blockchain", "getblockchaininfo", &getblockchaininfo, true, false, false},
{"blockchain", "getbestblockhash", &getbestblockhash, true, false, false},
{"blockchain", "getblockcount", &getblockcount, true, false, false},
Expand Down
1 change: 1 addition & 0 deletions src/rpcserver.h
Expand Up @@ -291,6 +291,7 @@ extern UniValue verifychain(const UniValue& params, bool fHelp);
extern UniValue getchaintips(const UniValue& params, bool fHelp);
extern UniValue invalidateblock(const UniValue& params, bool fHelp);
extern UniValue reconsiderblock(const UniValue& params, bool fHelp);
extern UniValue getaccumulatorvalues(const UniValue& params, bool fHelp);

extern UniValue getpoolinfo(const UniValue& params, bool fHelp); // in rpcmasternode.cpp
extern UniValue masternode(const UniValue& params, bool fHelp);
Expand Down

0 comments on commit 8a6d425

Please sign in to comment.