Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions src/rpcblockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -691,11 +691,14 @@ struct CompareBlocksByHeight

UniValue getchaintips(const UniValue& params, bool fHelp)
{
if (fHelp || params.size() != 0)
if (fHelp || params.size() > 2)
throw runtime_error(
"getchaintips\n"
"getchaintips ( count branchlen )\n"
"Return information about all known tips in the block tree,"
" including the main chain as well as orphaned branches.\n"
"\nArguments:\n"
"1. count (numeric, optional) only show this much of latest tips\n"
"2. branchlen (numeric, optional) only show tips that have equal or greater length of branch\n"
"\nResult:\n"
"[\n"
" {\n"
Expand Down Expand Up @@ -740,15 +743,27 @@ UniValue getchaintips(const UniValue& params, bool fHelp)
// Always report the currently active tip.
setTips.insert(chainActive.Tip());

int nBranchMin = -1;
int nCountMax = INT_MAX;

if(params.size() >= 1)
nCountMax = params[0].get_int();

if(params.size() == 2)
nBranchMin = params[1].get_int();

/* Construct the output array. */
UniValue res(UniValue::VARR);
BOOST_FOREACH(const CBlockIndex* block, setTips)
{
const int branchLen = block->nHeight - chainActive.FindFork(block)->nHeight;
if(branchLen < nBranchMin) continue;

if(nCountMax-- < 1) break;

UniValue obj(UniValue::VOBJ);
obj.push_back(Pair("height", block->nHeight));
obj.push_back(Pair("hash", block->phashBlock->GetHex()));

const int branchLen = block->nHeight - chainActive.FindFork(block)->nHeight;
obj.push_back(Pair("branchlen", branchLen));

string status;
Expand Down
2 changes: 2 additions & 0 deletions src/rpcclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ static const CRPCConvertParam vRPCConvertParams[] =
{ "listreceivedbyaccount", 2 },
{ "getbalance", 1 },
{ "getbalance", 2 },
{ "getchaintips", 0 },
{ "getchaintips", 1 },
{ "getblockhash", 0 },
{ "move", 2 },
{ "move", 3 },
Expand Down
Loading