| 1241 | } |
| 1242 | |
| 1243 | UniValue getblockchaininfo(const UniValue& params, bool fHelp) |
| 1244 | { |
| 1245 | if (fHelp || params.size() != 0) |
| 1246 | throw runtime_error( |
| 1247 | "getblockchaininfo\n" |
| 1248 | "Returns an object containing various state info regarding block chain processing.\n" |
| 1249 | "\nResult:\n" |
| 1250 | "{\n" |
| 1251 | " \"chain\": \"xxxx\", (string) current network name as defined in BIP70 (main, test, regtest)\n" |
| 1252 | " \"blocks\": xxxxxx, (numeric) the current number of blocks processed in the server\n" |
| 1253 | " \"headers\": xxxxxx, (numeric) the current number of headers we have validated\n" |
| 1254 | " \"bestblockhash\": \"...\", (string) the hash of the currently best block\n" |
| 1255 | " \"difficulty\": xxxxxx, (numeric) the current difficulty\n" |
| 1256 | " \"mediantime\": xxxxxx, (numeric) median time for the current best block\n" |
| 1257 | " \"verificationprogress\": x, (number) estimate of verification progress [0..1]\n" |
| 1258 | " \"chainwork\": \"xxxx\", (string) total amount of work in active chain, in hexadecimal\n" |
| 1259 | " \"pruned\": xx, (boolean) if the blocks are subject to pruning\n" |
| 1260 | " \"pruneheight\": xxxxxx, (numeric) lowest-height complete block stored\n" |
| 1261 | " \"logevents\": true|false, (boolean) show the current -logevents setting\n" |
| 1262 | " \"addressindex\": false, (boolean) show the current -addressindex setting\n" |
| 1263 | " \"spentindex\": true|false, (boolean) show the current -spentindex setting\n" |
| 1264 | " \"txindex\": true|false, (boolean) show the current -txindex setting\n" |
| 1265 | " \"bip9_softforks\": { (object) status of BIP9 softforks in progress\n" |
| 1266 | " \"xxxx\" : { (string) name of the softfork\n" |
| 1267 | " \"status\": \"xxxx\", (string) one of \"defined\", \"started\", \"lockedin\", \"active\", \"failed\"\n" |
| 1268 | " \"bit\": xx, (numeric) the bit, 0-28, in the block version field used to signal this soft fork\n" |
| 1269 | " \"startTime\": xx, (numeric) the minimum median time past of a block at which the bit gains its meaning\n" |
| 1270 | " \"timeout\": xx (numeric) the median time past of a block at which the deployment is considered failed if not yet locked in\n" |
| 1271 | " }\n" |
| 1272 | " }\n" |
| 1273 | "}\n" |
| 1274 | "\nExamples:\n" |
| 1275 | + HelpExampleCli("getblockchaininfo", "") |
| 1276 | + HelpExampleRpc("getblockchaininfo", "") |
| 1277 | ); |
| 1278 | |
| 1279 | LOCK(cs_main); |
| 1280 | CBlockIndex* powTip = GetLastBlockOfType(0); |
| 1281 | CBlockIndex* posTip = GetLastBlockOfType(1); |
| 1282 | UniValue obj(UniValue::VOBJ); |
| 1283 | UniValue diff(UniValue::VOBJ); |
| 1284 | obj.push_back(Pair("chain", Params().NetworkIDString())); |
| 1285 | obj.push_back(Pair("blocks", chainActive.Height())); |
| 1286 | obj.push_back(Pair("headers", pindexBestHeader ? pindexBestHeader->nHeight : -1)); |
| 1287 | obj.push_back(Pair("bestblockhash", chainActive.Tip()->GetBlockHash().GetHex())); |
| 1288 | diff.push_back(Pair("proof-of-work", (double)GetDifficulty(powTip))); |
| 1289 | diff.push_back(Pair("proof-of-stake", (double)GetDifficulty(posTip))); |
| 1290 | obj.push_back(Pair("difficulty", diff)); |
| 1291 | obj.push_back(Pair("mediantime", (int64_t)chainActive.Tip()->GetMedianTimePast())); |
| 1292 | obj.push_back(Pair("verificationprogress", Checkpoints::GuessVerificationProgress(Params().Checkpoints(), chainActive.Tip()))); |
| 1293 | obj.push_back(Pair("chainwork", chainActive.Tip()->nChainWork.GetHex())); |
| 1294 | obj.push_back(Pair("pruned", fPruneMode)); |
| 1295 | if (fPruneMode) { |
| 1296 | CBlockIndex *block = chainActive.Tip(); while (block && block->pprev && (block->pprev->nStatus & BLOCK_HAVE_DATA))block = block->pprev; |
| 1297 | obj.push_back(Pair("pruneheight", block->nHeight)); |
| 1298 | } |
| 1299 | obj.push_back(Pair("logevents", fLogEvents)); |
| 1300 | obj.push_back(Pair("addressindex", fAddressIndex)); |
no test coverage detected