| 445 | } |
| 446 | |
| 447 | static RPCMethod getmininginfo() |
| 448 | { |
| 449 | return RPCMethod{ |
| 450 | "getmininginfo", |
| 451 | "Returns a json object containing mining-related information.", |
| 452 | {}, |
| 453 | RPCResult{ |
| 454 | RPCResult::Type::OBJ, "", "", |
| 455 | { |
| 456 | {RPCResult::Type::NUM, "blocks", "The current block"}, |
| 457 | {RPCResult::Type::NUM, "currentblockweight", /*optional=*/true, "The block weight (including reserved weight for block header, txs count and coinbase tx) of the last assembled block (only present if a block was ever assembled)"}, |
| 458 | {RPCResult::Type::NUM, "currentblocktx", /*optional=*/true, "The number of block transactions (excluding coinbase) of the last assembled block (only present if a block was ever assembled)"}, |
| 459 | {RPCResult::Type::STR_HEX, "bits", "The current nBits, compact representation of the block difficulty target"}, |
| 460 | {RPCResult::Type::NUM, "difficulty", "The current difficulty"}, |
| 461 | {RPCResult::Type::STR_HEX, "target", "The current target"}, |
| 462 | {RPCResult::Type::NUM, "networkhashps", "The network hashes per second"}, |
| 463 | {RPCResult::Type::NUM, "pooledtx", "The size of the mempool"}, |
| 464 | {RPCResult::Type::STR_AMOUNT, "blockmintxfee", "Minimum feerate of packages selected for block inclusion in " + CURRENCY_UNIT + "/kvB"}, |
| 465 | {RPCResult::Type::STR, "chain", "current network name (" LIST_CHAIN_NAMES ")"}, |
| 466 | {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)"}, |
| 467 | {RPCResult::Type::OBJ, "next", "The next block", |
| 468 | { |
| 469 | {RPCResult::Type::NUM, "height", "The next height"}, |
| 470 | {RPCResult::Type::STR_HEX, "bits", "The next target nBits"}, |
| 471 | {RPCResult::Type::NUM, "difficulty", "The next difficulty"}, |
| 472 | {RPCResult::Type::STR_HEX, "target", "The next target"} |
| 473 | }}, |
| 474 | (IsDeprecatedRPCEnabled("warnings") ? |
| 475 | RPCResult{RPCResult::Type::STR, "warnings", "any network and blockchain warnings (DEPRECATED)"} : |
| 476 | RPCResult{RPCResult::Type::ARR, "warnings", "any network and blockchain warnings (run with `-deprecatedrpc=warnings` to return the latest warning as a single string)", |
| 477 | { |
| 478 | {RPCResult::Type::STR, "", "warning"}, |
| 479 | } |
| 480 | } |
| 481 | ), |
| 482 | }}, |
| 483 | RPCExamples{ |
| 484 | HelpExampleCli("getmininginfo", "") |
| 485 | + HelpExampleRpc("getmininginfo", "") |
| 486 | }, |
| 487 | [](const RPCMethod& self, const JSONRPCRequest& request) -> UniValue |
| 488 | { |
| 489 | NodeContext& node = EnsureAnyNodeContext(request.context); |
| 490 | const CTxMemPool& mempool = EnsureMemPool(node); |
| 491 | ChainstateManager& chainman = EnsureChainman(node); |
| 492 | LOCK(cs_main); |
| 493 | const CChain& active_chain = chainman.ActiveChain(); |
| 494 | CBlockIndex& tip{*CHECK_NONFATAL(active_chain.Tip())}; |
| 495 | |
| 496 | UniValue obj(UniValue::VOBJ); |
| 497 | obj.pushKV("blocks", active_chain.Height()); |
| 498 | if (BlockAssembler::m_last_block_weight) obj.pushKV("currentblockweight", *BlockAssembler::m_last_block_weight); |
| 499 | if (BlockAssembler::m_last_block_num_txs) obj.pushKV("currentblocktx", *BlockAssembler::m_last_block_num_txs); |
| 500 | obj.pushKV("bits", strprintf("%08x", tip.nBits)); |
| 501 | obj.pushKV("difficulty", GetDifficulty(tip)); |
| 502 | obj.pushKV("target", GetTarget(tip, chainman.GetConsensus().powLimit).GetHex()); |
| 503 | obj.pushKV("networkhashps", getnetworkhashps().HandleRequest(request)); |
| 504 | obj.pushKV("pooledtx", mempool.size()); |
nothing calls this directly
no test coverage detected