Skip to content

Commit 32617a7

Browse files
committed
[RPC] Add getcachedblockhashes function
which can be used for testing the contents of the cycling vector
1 parent 0de6544 commit 32617a7

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

src/masternodeman.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ class CMasternodeMan
173173
void UncacheBlockHash(const CBlockIndex* pindex);
174174
uint256 GetHashAtHeight(int nHeight) const;
175175
bool IsWithinDepth(const uint256& nHash, int depth) const;
176+
std::vector<uint256> GetCachedBlocks() const { return cvLastBlockHashes.GetCache(); }
176177
};
177178

178179
void ThreadCheckMasternodes();

src/rpc/masternode.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,31 @@
1818

1919
#include <boost/tokenizer.hpp>
2020

21+
UniValue getcachedblockhashes(const JSONRPCRequest& request)
22+
{
23+
if (request.fHelp || request.params.size() > 0)
24+
throw std::runtime_error(
25+
"getcachedblockhashes \n"
26+
"\nReturn the block hashes cached in the masternode manager\n"
27+
28+
"\nResult:\n"
29+
"[\n"
30+
" ...\n"
31+
" \"xxxx\", (string) hash at Index d (height modulo max cache size)\n"
32+
" ...\n"
33+
"]\n"
34+
35+
"\nExamples:\n" +
36+
HelpExampleCli("getcachedblockhashes", "") + HelpExampleRpc("getcachedblockhashes", ""));
37+
38+
std::vector<uint256> vCacheCopy = mnodeman.GetCachedBlocks();
39+
UniValue ret(UniValue::VARR);
40+
for (int i = 0; (unsigned) i < vCacheCopy.size(); i++) {
41+
ret.push_back(vCacheCopy[i].ToString());
42+
}
43+
return ret;
44+
}
45+
2146
UniValue listmasternodes(const JSONRPCRequest& request)
2247
{
2348
std::string strFilter = "";

src/rpc/server.cpp

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

362362
/* PIVX features */
363363
{"pivx", "listmasternodes", &listmasternodes, true },
364+
{"pivx", "getcachedblockhashes", &getcachedblockhashes, true },
364365
{"pivx", "getmasternodecount", &getmasternodecount, true },
365366
{"pivx", "createmasternodebroadcast", &createmasternodebroadcast, true },
366367
{"pivx", "decodemasternodebroadcast", &decodemasternodebroadcast, true },

src/rpc/server.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ extern void validaterange(const UniValue& params, int& heightStart, int& heightE
275275

276276
// in rpc/masternode.cpp
277277
extern UniValue listmasternodes(const JSONRPCRequest& request);
278+
extern UniValue getcachedblockhashes(const JSONRPCRequest& request);
278279
extern UniValue getmasternodecount(const JSONRPCRequest& request);
279280
extern UniValue createmasternodebroadcast(const JSONRPCRequest& request);
280281
extern UniValue decodemasternodebroadcast(const JSONRPCRequest& request);

0 commit comments

Comments
 (0)