| 1518 | } // anon namespace |
| 1519 | |
| 1520 | RPCMethod getdeploymentinfo() |
| 1521 | { |
| 1522 | return RPCMethod{"getdeploymentinfo", |
| 1523 | "Returns an object containing various state info regarding deployments of consensus changes.\n" |
| 1524 | "Consensus changes for which the new rules are enforced from genesis are not listed in \"deployments\".", |
| 1525 | { |
| 1526 | {"blockhash", RPCArg::Type::STR_HEX, RPCArg::Default{"hash of current chain tip"}, "The block hash at which to query deployment state"}, |
| 1527 | }, |
| 1528 | RPCResult{ |
| 1529 | RPCResult::Type::OBJ, "", "", { |
| 1530 | {RPCResult::Type::STR, "hash", "requested block hash (or tip)"}, |
| 1531 | {RPCResult::Type::NUM, "height", "requested block height (or tip)"}, |
| 1532 | {RPCResult::Type::ARR, "script_flags", "script verify flags for the block", { |
| 1533 | {RPCResult::Type::STR, "flag", "a script verify flag"}, |
| 1534 | }}, |
| 1535 | {RPCResult::Type::OBJ_DYN, "deployments", "", { |
| 1536 | {RPCResult::Type::OBJ, "xxxx", "name of the deployment", RPCHelpForDeployment} |
| 1537 | }}, |
| 1538 | } |
| 1539 | }, |
| 1540 | RPCExamples{ HelpExampleCli("getdeploymentinfo", "") + HelpExampleRpc("getdeploymentinfo", "") }, |
| 1541 | [](const RPCMethod& self, const JSONRPCRequest& request) -> UniValue |
| 1542 | { |
| 1543 | const ChainstateManager& chainman = EnsureAnyChainman(request.context); |
| 1544 | LOCK(cs_main); |
| 1545 | const Chainstate& active_chainstate = chainman.ActiveChainstate(); |
| 1546 | |
| 1547 | const CBlockIndex* blockindex; |
| 1548 | if (request.params[0].isNull()) { |
| 1549 | blockindex = CHECK_NONFATAL(active_chainstate.m_chain.Tip()); |
| 1550 | } else { |
| 1551 | const uint256 hash(ParseHashV(request.params[0], "blockhash")); |
| 1552 | blockindex = chainman.m_blockman.LookupBlockIndex(hash); |
| 1553 | if (!blockindex) { |
| 1554 | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found"); |
| 1555 | } |
| 1556 | } |
| 1557 | |
| 1558 | UniValue deploymentinfo(UniValue::VOBJ); |
| 1559 | deploymentinfo.pushKV("hash", blockindex->GetBlockHash().ToString()); |
| 1560 | deploymentinfo.pushKV("height", blockindex->nHeight); |
| 1561 | { |
| 1562 | const auto flagnames = GetScriptFlagNames(GetBlockScriptFlags(*blockindex, chainman)); |
| 1563 | UniValue uv_flagnames(UniValue::VARR); |
| 1564 | uv_flagnames.push_backV(flagnames.begin(), flagnames.end()); |
| 1565 | deploymentinfo.pushKV("script_flags", uv_flagnames); |
| 1566 | } |
| 1567 | deploymentinfo.pushKV("deployments", DeploymentInfo(blockindex, chainman)); |
| 1568 | return deploymentinfo; |
| 1569 | }, |
| 1570 | }; |
| 1571 | } |
| 1572 | |
| 1573 | /** Comparison function for sorting the getchaintips heads. */ |
| 1574 | struct CompareBlocksByHeight |
no test coverage detected