Getchaintips error checks
This commit is contained in:
@@ -1055,7 +1055,9 @@ UniValue getchaintips(const UniValue& params, bool fHelp)
|
|||||||
setTips.insert(item.second);
|
setTips.insert(item.second);
|
||||||
BOOST_FOREACH(const PAIRTYPE(const uint256, CBlockIndex*)& item, mapBlockIndex)
|
BOOST_FOREACH(const PAIRTYPE(const uint256, CBlockIndex*)& item, mapBlockIndex)
|
||||||
{
|
{
|
||||||
const CBlockIndex* pprev = item.second->pprev;
|
const CBlockIndex* pprev=0;
|
||||||
|
if ( item.second != 0 )
|
||||||
|
pprev = item.second->pprev;
|
||||||
if (pprev)
|
if (pprev)
|
||||||
setTips.erase(pprev);
|
setTips.erase(pprev);
|
||||||
}
|
}
|
||||||
@@ -1064,14 +1066,16 @@ UniValue getchaintips(const UniValue& params, bool fHelp)
|
|||||||
setTips.insert(chainActive.Tip());
|
setTips.insert(chainActive.Tip());
|
||||||
|
|
||||||
/* Construct the output array. */
|
/* Construct the output array. */
|
||||||
UniValue res(UniValue::VARR);
|
UniValue res(UniValue::VARR); CBlockIndex *forked;
|
||||||
BOOST_FOREACH(const CBlockIndex* block, setTips)
|
BOOST_FOREACH(const CBlockIndex* block, setTips)
|
||||||
{
|
{
|
||||||
UniValue obj(UniValue::VOBJ);
|
UniValue obj(UniValue::VOBJ);
|
||||||
obj.push_back(Pair("height", block->nHeight));
|
obj.push_back(Pair("height", block->nHeight));
|
||||||
obj.push_back(Pair("hash", block->phashBlock->GetHex()));
|
obj.push_back(Pair("hash", block->phashBlock->GetHex()));
|
||||||
|
forked = chainActive.FindFork(block);
|
||||||
const int branchLen = block->nHeight - chainActive.FindFork(block)->nHeight;
|
if ( forked != 0 )
|
||||||
|
{
|
||||||
|
const int branchLen = block->nHeight - forked->nHeight;
|
||||||
obj.push_back(Pair("branchlen", branchLen));
|
obj.push_back(Pair("branchlen", branchLen));
|
||||||
|
|
||||||
string status;
|
string status;
|
||||||
@@ -1095,7 +1099,7 @@ UniValue getchaintips(const UniValue& params, bool fHelp)
|
|||||||
status = "unknown";
|
status = "unknown";
|
||||||
}
|
}
|
||||||
obj.push_back(Pair("status", status));
|
obj.push_back(Pair("status", status));
|
||||||
|
}
|
||||||
res.push_back(obj);
|
res.push_back(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user