Browse Source

Add upgrades field to RPC call getblockchaininfo

Closes #2785.

Co-authored-by: Jack Grigg <jack@z.cash>
pull/4/head
Jay Graber 7 years ago
committed by Jack Grigg
parent
commit
71768555dd
No known key found for this signature in database GPG Key ID: 665DBCD284F7DAFF
  1. 47
      src/rpcblockchain.cpp

47
src/rpcblockchain.cpp

@ -659,6 +659,37 @@ static UniValue SoftForkDesc(const std::string &name, int version, CBlockIndex*
return rv;
}
static UniValue NetworkUpgradeDesc(const Consensus::Params& consensusParams, Consensus::UpgradeIndex idx, int height)
{
UniValue rv(UniValue::VOBJ);
auto upgrade = NetworkUpgradeInfo[idx];
rv.push_back(Pair("name", upgrade.strName));
rv.push_back(Pair("activationheight", consensusParams.vUpgrades[idx].nActivationHeight));
switch (NetworkUpgradeState(height, consensusParams, idx)) {
case UPGRADE_DISABLED: rv.push_back(Pair("status", "disabled")); break;
case UPGRADE_PENDING: rv.push_back(Pair("status", "pending")); break;
case UPGRADE_ACTIVE: rv.push_back(Pair("status", "active")); break;
}
rv.push_back(Pair("info", upgrade.strInfo));
return rv;
}
void NetworkUpgradeDescPushBack(
UniValue& networkUpgrades,
const Consensus::Params& consensusParams,
Consensus::UpgradeIndex idx,
int height)
{
// Network upgrades with an activation height of NO_ACTIVATION_HEIGHT are
// hidden. This is used when network upgrade implementations are merged
// without specifying the activation height.
if (consensusParams.vUpgrades[idx].nActivationHeight != Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT) {
networkUpgrades.push_back(Pair(
HexInt(NetworkUpgradeInfo[idx].nBranchId),
NetworkUpgradeDesc(consensusParams, idx, height)));
}
}
UniValue getblockchaininfo(const UniValue& params, bool fHelp)
{
if (fHelp || params.size() != 0)
@ -687,7 +718,15 @@ UniValue getblockchaininfo(const UniValue& params, bool fHelp)
" },\n"
" \"reject\": { ... } (object) progress toward rejecting pre-softfork blocks (same fields as \"enforce\")\n"
" }, ...\n"
" ]\n"
" ],\n"
" \"upgrades\": { (object) status of network upgrades\n"
" \"xxxx\" : { (string) branch ID of the upgrade\n"
" \"name\": \"xxxx\", (string) name of upgrade\n"
" \"activationheight\": xxxxxx, (numeric) block height of activation\n"
" \"status\": \"xxxx\", (string) status of upgrade\n"
" \"info\": \"xxxx\", (string) additional information about upgrade\n"
" }, ...\n"
" }\n"
"}\n"
"\nExamples:\n"
+ HelpExampleCli("getblockchaininfo", "")
@ -722,6 +761,12 @@ UniValue getblockchaininfo(const UniValue& params, bool fHelp)
softforks.push_back(SoftForkDesc("bip65", 4, tip, consensusParams));
obj.push_back(Pair("softforks", softforks));
UniValue upgrades(UniValue::VOBJ);
for (int i = Consensus::UPGRADE_OVERWINTER; i < Consensus::MAX_NETWORK_UPGRADES; i++) {
NetworkUpgradeDescPushBack(upgrades, consensusParams, Consensus::UpgradeIndex(i), tip->nHeight);
}
obj.push_back(Pair("upgrades", upgrades));
if (fPruneMode)
{
CBlockIndex *block = chainActive.Tip();

Loading…
Cancel
Save