MCPcopy Create free account
hub / github.com/BTCGPU/BTCGPU / finalizeblock

Function finalizeblock

src/rpc/blockchain.cpp:1529–1568  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1527}
1528
1529UniValue finalizeblock(const JSONRPCRequest& request) {
1530 if (request.fHelp || request.params.size() != 1)
1531 throw std::runtime_error(
1532 "finalizeblock \"blockhash\"\n"
1533 "\nTreats a block as final. It cannot be reorged. Any chain\n"
1534 "that does not contain this block is invalid. Used on a less\n"
1535 "work chain, it can effectively PUTS YOU OUT OF CONSENSUS.\n"
1536 "USE WITH CAUTION!\n"
1537 "\nArguments:\n"
1538 "1. \"blockhash\" (string, required) the hash of the block to mark as finalized\n"
1539 "\nResult:\n"
1540 "\nExamples:\n"
1541 + HelpExampleCli("finalizeblock", "\"blockhash\"")
1542 + HelpExampleRpc("finalizeblock", "\"blockhash\"")
1543 );
1544
1545 std::string strHash = request.params[0].get_str();
1546 uint256 hash(uint256S(strHash));
1547 CValidationState state;
1548
1549 {
1550 LOCK(cs_main);
1551 CBlockIndex *pblockindex = LookupBlockIndex(hash);
1552 if (!pblockindex) {
1553 throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
1554 }
1555
1556 FinalizeBlockAndInvalidate(state, pblockindex);
1557 }
1558
1559 if (state.IsValid()) {
1560 ActivateBestChain(state, Params());
1561 }
1562
1563 if (!state.IsValid()) {
1564 throw JSONRPCError(RPC_DATABASE_ERROR, FormatStateMessage(state));
1565 }
1566
1567 return NullUniValue;
1568}
1569
1570static UniValue invalidateblock(const JSONRPCRequest& request)
1571{

Callers

nothing calls this directly

Calls 11

HelpExampleCliFunction · 0.85
HelpExampleRpcFunction · 0.85
uint256SFunction · 0.85
LookupBlockIndexFunction · 0.85
JSONRPCErrorFunction · 0.85
ActivateBestChainFunction · 0.85
FormatStateMessageFunction · 0.85
ParamsClass · 0.50
sizeMethod · 0.45
IsValidMethod · 0.45

Tested by

no test coverage detected