Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/blockchain.cpp
Show First 20 Lines • Show All 170 Lines • ▼ Show 20 Lines | if (request.fHelp || request.params.size() != 0) { | ||||
HelpExampleCli("getbestblockhash", "") + | HelpExampleCli("getbestblockhash", "") + | ||||
HelpExampleRpc("getbestblockhash", "")); | HelpExampleRpc("getbestblockhash", "")); | ||||
} | } | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
return chainActive.Tip()->GetBlockHash().GetHex(); | return chainActive.Tip()->GetBlockHash().GetHex(); | ||||
} | } | ||||
UniValue getfinalizedblockhash(const Config &config, | |||||
const JSONRPCRequest &request) { | |||||
if (request.fHelp || request.params.size() != 0) { | |||||
throw std::runtime_error( | |||||
"getfinalizedblockhash\n" | |||||
"\nReturns the hash of the currently finalized block\n" | |||||
"\nResult:\n" | |||||
"\"hex\" (string) the block hash hex encoded\n"); | |||||
} | |||||
LOCK(cs_main); | |||||
const CBlockIndex *blockIndexFinalized = GetFinalizedBlock(); | |||||
if (blockIndexFinalized) { | |||||
return blockIndexFinalized->GetBlockHash().GetHex(); | |||||
} | |||||
return UniValue(UniValue::VSTR); | |||||
} | |||||
void RPCNotifyBlockChange(bool ibd, const CBlockIndex *pindex) { | void RPCNotifyBlockChange(bool ibd, const CBlockIndex *pindex) { | ||||
if (pindex) { | if (pindex) { | ||||
std::lock_guard<std::mutex> lock(cs_blockchange); | std::lock_guard<std::mutex> lock(cs_blockchange); | ||||
latestblock.hash = pindex->GetBlockHash(); | latestblock.hash = pindex->GetBlockHash(); | ||||
latestblock.height = pindex->nHeight; | latestblock.height = pindex->nHeight; | ||||
} | } | ||||
cond_blockchange.notify_all(); | cond_blockchange.notify_all(); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 1,623 Lines • ▼ Show 20 Lines | static const ContextFreeRPCCommand commands[] = { | ||||
{ "blockchain", "getrawmempool", getrawmempool, {"verbose"} }, | { "blockchain", "getrawmempool", getrawmempool, {"verbose"} }, | ||||
{ "blockchain", "gettxout", gettxout, {"txid","n","include_mempool"} }, | { "blockchain", "gettxout", gettxout, {"txid","n","include_mempool"} }, | ||||
{ "blockchain", "gettxoutsetinfo", gettxoutsetinfo, {} }, | { "blockchain", "gettxoutsetinfo", gettxoutsetinfo, {} }, | ||||
{ "blockchain", "pruneblockchain", pruneblockchain, {"height"} }, | { "blockchain", "pruneblockchain", pruneblockchain, {"height"} }, | ||||
{ "blockchain", "verifychain", verifychain, {"checklevel","nblocks"} }, | { "blockchain", "verifychain", verifychain, {"checklevel","nblocks"} }, | ||||
{ "blockchain", "preciousblock", preciousblock, {"blockhash"} }, | { "blockchain", "preciousblock", preciousblock, {"blockhash"} }, | ||||
/* Not shown in help */ | /* Not shown in help */ | ||||
{ "hidden", "getfinalizedblockhash", getfinalizedblockhash, {} }, | |||||
{ "hidden", "finalizeblock", finalizeblock, {"blockhash"} }, | { "hidden", "finalizeblock", finalizeblock, {"blockhash"} }, | ||||
{ "hidden", "invalidateblock", invalidateblock, {"blockhash"} }, | { "hidden", "invalidateblock", invalidateblock, {"blockhash"} }, | ||||
{ "hidden", "parkblock", parkblock, {"blockhash"} }, | { "hidden", "parkblock", parkblock, {"blockhash"} }, | ||||
{ "hidden", "reconsiderblock", reconsiderblock, {"blockhash"} }, | { "hidden", "reconsiderblock", reconsiderblock, {"blockhash"} }, | ||||
{ "hidden", "unparkblock", unparkblock, {"blockhash"} }, | { "hidden", "unparkblock", unparkblock, {"blockhash"} }, | ||||
{ "hidden", "waitfornewblock", waitfornewblock, {"timeout"} }, | { "hidden", "waitfornewblock", waitfornewblock, {"timeout"} }, | ||||
{ "hidden", "waitforblock", waitforblock, {"blockhash","timeout"} }, | { "hidden", "waitforblock", waitforblock, {"blockhash","timeout"} }, | ||||
{ "hidden", "waitforblockheight", waitforblockheight, {"height","timeout"} }, | { "hidden", "waitforblockheight", waitforblockheight, {"height","timeout"} }, | ||||
}; | }; | ||||
// clang-format on | // clang-format on | ||||
void RegisterBlockchainRPCCommands(CRPCTable &t) { | void RegisterBlockchainRPCCommands(CRPCTable &t) { | ||||
for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++) { | for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++) { | ||||
t.appendCommand(commands[vcidx].name, &commands[vcidx]); | t.appendCommand(commands[vcidx].name, &commands[vcidx]); | ||||
} | } | ||||
} | } |