| 431 | } |
| 432 | |
| 433 | static RPCHelpMan getmininginfo() |
| 434 | { |
| 435 | return RPCHelpMan{"getmininginfo", |
| 436 | "\nReturns a json object containing mining-related information.", |
| 437 | {}, |
| 438 | RPCResult{ |
| 439 | RPCResult::Type::OBJ, "", "", |
| 440 | { |
| 441 | {RPCResult::Type::NUM, "blocks", "The current block"}, |
| 442 | {RPCResult::Type::NUM, "currentblockweight", /*optional=*/true, "The block weight of the last assembled block (only present if a block was ever assembled)"}, |
| 443 | {RPCResult::Type::NUM, "currentblocktx", /*optional=*/true, "The number of block transactions of the last assembled block (only present if a block was ever assembled)"}, |
| 444 | {RPCResult::Type::NUM, "difficulty", "The current difficulty"}, |
| 445 | {RPCResult::Type::NUM, "networkhashps", "The network hashes per second"}, |
| 446 | {RPCResult::Type::NUM, "pooledtx", "The size of the mempool"}, |
| 447 | {RPCResult::Type::STR, "chain", "current network name (main, test, signet, regtest, liquidv1, liquidv1test, liquidtestnet)"}, |
| 448 | {RPCResult::Type::STR, "warnings", "any network and blockchain warnings"}, |
| 449 | }}, |
| 450 | RPCExamples{ |
| 451 | HelpExampleCli("getmininginfo", "") |
| 452 | + HelpExampleRpc("getmininginfo", "") |
| 453 | }, |
| 454 | [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue |
| 455 | { |
| 456 | NodeContext& node = EnsureAnyNodeContext(request.context); |
| 457 | const CTxMemPool& mempool = EnsureMemPool(node); |
| 458 | ChainstateManager& chainman = EnsureChainman(node); |
| 459 | LOCK(cs_main); |
| 460 | const CChain& active_chain = chainman.ActiveChain(); |
| 461 | |
| 462 | UniValue obj(UniValue::VOBJ); |
| 463 | obj.pushKV("blocks", active_chain.Height()); |
| 464 | if (BlockAssembler::m_last_block_weight) obj.pushKV("currentblockweight", *BlockAssembler::m_last_block_weight); |
| 465 | if (BlockAssembler::m_last_block_num_txs) obj.pushKV("currentblocktx", *BlockAssembler::m_last_block_num_txs); |
| 466 | if (!g_signed_blocks) { |
| 467 | obj.pushKV("difficulty", (double)GetDifficulty(active_chain.Tip())); |
| 468 | obj.pushKV("networkhashps", getnetworkhashps().HandleRequest(request)); |
| 469 | } |
| 470 | obj.pushKV("pooledtx", (uint64_t)mempool.size()); |
| 471 | obj.pushKV("chain", Params().NetworkIDString()); |
| 472 | obj.pushKV("warnings", GetWarnings(false).original); |
| 473 | return obj; |
| 474 | }, |
| 475 | }; |
| 476 | } |
| 477 | |
| 478 | |
| 479 | // NOTE: Unlike wallet RPC (which use BTC values), mining RPCs follow GBT (BIP 22) in using satoshi amounts |
nothing calls this directly
no test coverage detected