message: [RPC] Show BIP65 soft-fork progress in getblockchaininfo
diff: @@ -578,6 +578,34 @@ UniValue verifychain(const UniValue& params, bool fHelp)
  return fVerified;
  }
  +/** Implementation of IsSuperMajority with better feedback */
  +static UniValue SoftForkMajorityDesc(int minVersion, CBlockIndex* pindex, int nRequired)
  +{
  + int nFound = 0;
  + CBlockIndex* pstart = pindex;
  + for (int i = 0; i < Params().ToCheckBlockUpgradeMajority() && pstart != NULL; i++)
  + {
  + if (pstart->nVersion >= minVersion)
  + ++nFound;
  + pstart = pstart->pprev;
  + }
  + UniValue rv(UniValue::VOBJ);
  + rv.push_back(Pair("status", nFound >= nRequired));
  + rv.push_back(Pair("found", nFound));
  + rv.push_back(Pair("required", nRequired));
  + rv.push_back(Pair("window", Params().ToCheckBlockUpgradeMajority()));
  + return rv;
  +}
  +static UniValue SoftForkDesc(const std::string &name, int version, CBlockIndex* pindex)
  +{
  + UniValue rv(UniValue::VOBJ);
  + rv.push_back(Pair("id", name));
  + rv.push_back(Pair("version", version));
  + rv.push_back(Pair("enforce", SoftForkMajorityDesc(version, pindex, Params().EnforceBlockUpgradeMajority())));
  + rv.push_back(Pair("reject", SoftForkMajorityDesc(version, pindex, Params().RejectBlockOutdatedMajority())));
  + return rv;
  +}
  +
  UniValue getblockchaininfo(const UniValue& params, bool fHelp)
  {
  if (fHelp || params.size() != 0)
  @@ -594,6 +622,19 @@ UniValue getblockchaininfo(const UniValue& params, bool fHelp)
  " \"difficulty\": xxxxxx, (numeric) the current difficulty\n"
  " \"verificationprogress\": xxxx, (numeric) estimate of verification progress [0..1]\n"
  " \"chainwork\": \"xxxx\" (string) total amount of work in active chain, in hexadecimal\n"
  + " \"softforks\": [ (array) status of softforks in progress\n"
  + " {\n"
  + " \"id\": \"xxxx\", (string) name of softfork\n"
  + " \"version\": xx, (numeric) block version\n"
  + " \"enforce\": { (object) progress toward enforcing the softfork rules for new-version blocks\n"
  + " \"status\": xx, (boolean) true if threshold reached\n"
  + " \"found\": xx, (numeric) number of blocks with the new version found\n"
  + " \"required\": xx, (numeric) number of blocks required to trigger\n"
  + " \"window\": xx, (numeric) maximum size of examined window of recent blocks\n"
  + " },\n"
  + " \"reject\": { ... } (object) progress toward rejecting pre-softfork blocks (same fields as \"enforce\")\n"
  + " }, ...\n"
  + " ]\n"
  "}\n"
  "\nExamples:\n" +
  @@ -609,6 +650,10 @@ UniValue getblockchaininfo(const UniValue& params, bool fHelp)
  obj.push_back(Pair("difficulty", (double)GetDifficulty()));
  obj.push_back(Pair("verificationprogress", Checkpoints::GuessVerificationProgress(chainActive.Tip())));
  obj.push_back(Pair("chainwork", chainActive.Tip()->nChainWork.GetHex()));
  + CBlockIndex* tip = chainActive.Tip();
  + UniValue softforks(UniValue::VARR);
  + softforks.push_back(SoftForkDesc("bip65", 5, tip));
  + obj.push_back(Pair("softforks", softforks));
  return obj;
  }
  