message: Add get staking info RPC method
diff: @@ -282,6 +282,47 @@ UniValue getmininginfo(const JSONRPCRequest& request)
  return obj;
  }
  +UniValue getstakinginfo(const JSONRPCRequest& request)
  +{
  + if (request.fHelp || request.params.size() != 0)
  + throw runtime_error(
  + "getstakinginfo\n"
  + "Returns an object containing staking-related information.");
  +
  + LOCK(cs_main);
  +
  + uint64_t nWeight = 0;
  +#ifdef ENABLE_WALLET
  + if (pwalletMain)
  + nWeight = pwalletMain->GetStakeWeight();
  +#endif
  +
  + uint64_t nNetworkWeight = GetPoSKernelPS();
  + bool staking = nLastCoinStakeSearchInterval && nWeight;
  + const Consensus::Params& consensusParams = Params().GetConsensus();
  + int64_t nTargetSpacing = consensusParams.nPowTargetSpacing;
  + uint64_t nExpectedTime = staking ? (nTargetSpacing * nNetworkWeight / nWeight) : 0;
  +
  + UniValue obj(UniValue::VOBJ);
  +
  + obj.push_back(Pair("enabled", GetBoolArg("-staking", true)));
  + obj.push_back(Pair("staking", staking));
  + obj.push_back(Pair("errors", GetWarnings("statusbar")));
  +
  + obj.push_back(Pair("currentblocksize", (uint64_t)nLastBlockSize));
  + obj.push_back(Pair("currentblocktx", (uint64_t)nLastBlockTx));
  + obj.push_back(Pair("pooledtx", (uint64_t)mempool.size()));
  +
  + obj.push_back(Pair("difficulty", GetDifficulty(GetLastBlockIndex(pindexBestHeader, true))));
  + obj.push_back(Pair("search-interval", (int)nLastCoinStakeSearchInterval));
  +
  + obj.push_back(Pair("weight", (uint64_t)nWeight));
  + obj.push_back(Pair("netstakeweight", (uint64_t)nNetworkWeight));
  +
  + obj.push_back(Pair("expectedtime", nExpectedTime));
  +
  + return obj;
  +}
  // NOTE: Unlike wallet RPC (which use BTC values), mining RPCs follow GBT (BIP 22) in using satoshi amounts
  UniValue prioritisetransaction(const JSONRPCRequest& request)
  @@ -947,6 +988,7 @@ static const CRPCCommand commands[] =
  { "mining", "prioritisetransaction", &prioritisetransaction, true, {"txid","priority_delta","fee_delta"} },
  { "mining", "getblocktemplate", &getblocktemplate, true, {"template_request"} },
  { "mining", "submitblock", &submitblock, true, {"hexdata","parameters"} },
  + { "mining", "getstakinginfo", &getstakinginfo, true, {} },
  { "generating", "generate", &generate, true, {"nblocks","maxtries"} },
  { "generating", "generatetoaddress", &generatetoaddress, true, {"nblocks","address","maxtries"} },
  