Skip to content

Commit 8a6d425

Browse files
committed
Add getaccumulatorvalues RPC.
Return the accumulator values associated with a particular block height.
1 parent abee3d9 commit 8a6d425

File tree

4 files changed

+37
-1
lines changed

4 files changed

+37
-1
lines changed

src/rpcblockchain.cpp

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "util.h"
1616
#include "utilmoneystr.h"
1717
#include "accumulatormap.h"
18+
#include "accumulators.h"
1819

1920
#include <stdint.h>
2021
#include <univalue.h>
@@ -929,6 +930,38 @@ UniValue findserial(const UniValue& params, bool fHelp)
929930
UniValue ret(UniValue::VOBJ);
930931
ret.push_back(Pair("success", fSuccess));
931932
ret.push_back(Pair("txid", txid.GetHex()));
932-
933933
return ret;
934934
}
935+
936+
UniValue getaccumulatorvalues(const UniValue& params, bool fHelp)
937+
{
938+
if (fHelp || params.size() != 1)
939+
throw runtime_error(
940+
"getaccumulatorvalues \"height\"\n"
941+
"\nReturns the accumulator values associated with a block height\n"
942+
943+
"\nArguments:\n"
944+
"1. height (numeric, required) the height of the checkpoint.\n"
945+
946+
"\nExamples:\n" +
947+
HelpExampleCli("getaccumulatorvalues", "\"height\"") + HelpExampleRpc("getaccumulatorvalues", "\"height\""));
948+
949+
int nHeight = params[0].get_int();
950+
951+
CBlockIndex* pindex = chainActive[nHeight];
952+
if (!pindex)
953+
throw JSONRPCError(RPC_INVALID_PARAMETER, "invalid block height");
954+
955+
UniValue ret(UniValue::VARR);
956+
for (libzerocoin::CoinDenomination denom : libzerocoin::zerocoinDenomList) {
957+
CBigNum bnValue;
958+
if(!GetAccumulatorValueFromDB(pindex->nAccumulatorCheckpoint, denom, bnValue))
959+
throw JSONRPCError(RPC_DATABASE_ERROR, "failed to find value in database");
960+
961+
UniValue obj(UniValue::VOBJ);
962+
obj.push_back(Pair(std::to_string(denom), bnValue.GetHex()));
963+
ret.push_back(obj);
964+
}
965+
966+
return ret;
967+
}

src/rpcclient.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ static const CRPCConvertParam vRPCConvertParams[] =
140140
{"searchdzpiv", 0},
141141
{"searchdzpiv", 1},
142142
{"searchdzpiv", 2},
143+
{"getaccumulatorvalues", 0},
143144
{"getfeeinfo", 0}
144145
};
145146

src/rpcserver.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ static const CRPCCommand vRPCCommands[] =
298298

299299
/* Block chain and UTXO */
300300
{"blockchain", "findserial", &findserial, true, false, false},
301+
{"blockchain", "getaccumulatorvalues", &getaccumulatorvalues, true, false, false},
301302
{"blockchain", "getblockchaininfo", &getblockchaininfo, true, false, false},
302303
{"blockchain", "getbestblockhash", &getbestblockhash, true, false, false},
303304
{"blockchain", "getblockcount", &getblockcount, true, false, false},

src/rpcserver.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ extern UniValue verifychain(const UniValue& params, bool fHelp);
291291
extern UniValue getchaintips(const UniValue& params, bool fHelp);
292292
extern UniValue invalidateblock(const UniValue& params, bool fHelp);
293293
extern UniValue reconsiderblock(const UniValue& params, bool fHelp);
294+
extern UniValue getaccumulatorvalues(const UniValue& params, bool fHelp);
294295

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

0 commit comments

Comments
 (0)