used by rest.cpp:rest_chaininfo, so cannot be static
| 1372 | |
| 1373 | // used by rest.cpp:rest_chaininfo, so cannot be static |
| 1374 | RPCMethod getblockchaininfo() |
| 1375 | { |
| 1376 | return RPCMethod{"getblockchaininfo", |
| 1377 | "Returns an object containing various state info regarding blockchain processing.\n", |
| 1378 | {}, |
| 1379 | RPCResult{ |
| 1380 | RPCResult::Type::OBJ, "", "", |
| 1381 | { |
| 1382 | {RPCResult::Type::STR, "chain", "current network name (" LIST_CHAIN_NAMES ")"}, |
| 1383 | {RPCResult::Type::NUM, "blocks", "the height of the most-work fully-validated chain. The genesis block has height 0"}, |
| 1384 | {RPCResult::Type::NUM, "headers", "the current number of headers we have validated"}, |
| 1385 | {RPCResult::Type::STR, "bestblockhash", "the hash of the currently best block"}, |
| 1386 | {RPCResult::Type::STR_HEX, "bits", "nBits: compact representation of the block difficulty target"}, |
| 1387 | {RPCResult::Type::STR_HEX, "target", "the difficulty target"}, |
| 1388 | {RPCResult::Type::NUM, "difficulty", "the current difficulty"}, |
| 1389 | {RPCResult::Type::NUM_TIME, "time", "the block time expressed in " + UNIX_EPOCH_TIME}, |
| 1390 | {RPCResult::Type::NUM_TIME, "mediantime", "the median block time expressed in " + UNIX_EPOCH_TIME}, |
| 1391 | {RPCResult::Type::NUM, "verificationprogress", "estimate of verification progress [0..1]"}, |
| 1392 | {RPCResult::Type::BOOL, "initialblockdownload", "(debug information) estimate of whether this node is in Initial Block Download mode"}, |
| 1393 | {RPCResult::Type::OBJ, "backgroundvalidation", /*optional=*/true, "state info regarding background validation process", |
| 1394 | { |
| 1395 | {RPCResult::Type::NUM, "snapshotheight", "the height of the snapshot block. Background validation verifies the chain from genesis up to this height"}, |
| 1396 | {RPCResult::Type::NUM, "blocks", "the height of the most-work background fully-validated chain. The genesis block has height 0"}, |
| 1397 | {RPCResult::Type::STR, "bestblockhash", "the hash of the currently best block validated in the background"}, |
| 1398 | {RPCResult::Type::NUM_TIME, "mediantime", "the median block time expressed in " + UNIX_EPOCH_TIME}, |
| 1399 | {RPCResult::Type::NUM, "verificationprogress", "estimate of background verification progress [0..1]"}, |
| 1400 | {RPCResult::Type::STR_HEX, "chainwork", "total amount of work in background validated chain, in hexadecimal"}, |
| 1401 | }}, |
| 1402 | {RPCResult::Type::STR_HEX, "chainwork", "total amount of work in active chain, in hexadecimal"}, |
| 1403 | {RPCResult::Type::NUM, "size_on_disk", "the estimated size of the block and undo files on disk"}, |
| 1404 | {RPCResult::Type::BOOL, "pruned", "if the blocks are subject to pruning"}, |
| 1405 | {RPCResult::Type::NUM, "pruneheight", /*optional=*/true, "the first block unpruned, all previous blocks were pruned (only present if pruning is enabled)"}, |
| 1406 | {RPCResult::Type::BOOL, "automatic_pruning", /*optional=*/true, "whether automatic pruning is enabled (only present if pruning is enabled)"}, |
| 1407 | {RPCResult::Type::NUM, "prune_target_size", /*optional=*/true, "the target size used by pruning (only present if automatic pruning is enabled)"}, |
| 1408 | {RPCResult::Type::STR_HEX, "signet_challenge", /*optional=*/true, "the block challenge (aka. block script), in hexadecimal (only present if the current network is a signet)"}, |
| 1409 | (IsDeprecatedRPCEnabled("warnings") ? |
| 1410 | RPCResult{RPCResult::Type::STR, "warnings", "any network and blockchain warnings (DEPRECATED)"} : |
| 1411 | RPCResult{RPCResult::Type::ARR, "warnings", "any network and blockchain warnings (run with `-deprecatedrpc=warnings` to return the latest warning as a single string)", |
| 1412 | { |
| 1413 | {RPCResult::Type::STR, "", "warning"}, |
| 1414 | } |
| 1415 | } |
| 1416 | ), |
| 1417 | }}, |
| 1418 | RPCExamples{ |
| 1419 | HelpExampleCli("getblockchaininfo", "") |
| 1420 | + HelpExampleRpc("getblockchaininfo", "") |
| 1421 | }, |
| 1422 | [](const RPCMethod& self, const JSONRPCRequest& request) -> UniValue |
| 1423 | { |
| 1424 | ChainstateManager& chainman = EnsureAnyChainman(request.context); |
| 1425 | LOCK(cs_main); |
| 1426 | Chainstate& active_chainstate = chainman.ActiveChainstate(); |
| 1427 | |
| 1428 | const CBlockIndex& tip{*CHECK_NONFATAL(active_chainstate.m_chain.Tip())}; |
| 1429 | const int height{tip.nHeight}; |
| 1430 | UniValue obj(UniValue::VOBJ); |
| 1431 | obj.pushKV("chain", chainman.GetParams().GetChainTypeString()); |
no test coverage detected