Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/blockchain.cpp
Show First 20 Lines • Show All 914 Lines • ▼ Show 20 Lines | if (!ReadBlockFromDisk(block, pblockindex, | ||||
// blocks, we add the headers to our index, but don't accept the block). | // blocks, we add the headers to our index, but don't accept the block). | ||||
throw JSONRPCError(RPC_MISC_ERROR, "Block not found on disk"); | throw JSONRPCError(RPC_MISC_ERROR, "Block not found on disk"); | ||||
} | } | ||||
return block; | return block; | ||||
} | } | ||||
static UniValue getblock(const Config &config, const JSONRPCRequest &request) { | static UniValue getblock(const Config &config, const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() < 1 || | const RPCHelpMan help{ | ||||
request.params.size() > 2) { | |||||
throw std::runtime_error(RPCHelpMan{ | |||||
"getblock", | "getblock", | ||||
"\nIf verbosity is 0 or false, returns a string that is " | "\nIf verbosity is 0 or false, returns a string that is " | ||||
"serialized, hex-encoded data for block 'hash'.\n" | "serialized, hex-encoded data for block 'hash'.\n" | ||||
"If verbosity is 1 or true, returns an Object with information " | "If verbosity is 1 or true, returns an Object with information " | ||||
"about block <hash>.\n" | "about block <hash>.\n" | ||||
"If verbosity is 2, returns an Object with information about " | "If verbosity is 2, returns an Object with information about " | ||||
"block <hash> and information about each transaction.\n", | "block <hash> and information about each transaction.\n", | ||||
{ | { | ||||
{"blockhash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, | {"blockhash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, | ||||
"The block hash"}, | "The block hash"}, | ||||
{"verbosity", RPCArg::Type::NUM, /* default */ "1", | {"verbosity", RPCArg::Type::NUM, /* default */ "1", | ||||
"0 for hex-encoded data, 1 for a json object, and 2 for " | "0 for hex-encoded data, 1 for a json object, and 2 for " | ||||
"json object with transaction data"}, | "json object with transaction data"}, | ||||
}, | }, | ||||
{ | { | ||||
RPCResult{ | RPCResult{"for verbosity = 0", | ||||
"for verbosity = 0", | |||||
"\"data\" (string) A string that is " | "\"data\" (string) A string that is " | ||||
"serialized, hex-encoded data for block 'hash'.\n"}, | "serialized, hex-encoded data for block 'hash'.\n"}, | ||||
RPCResult{ | RPCResult{ | ||||
"for verbosity = 1", | "for verbosity = 1", | ||||
"{\n" | "{\n" | ||||
" \"hash\" : \"hash\", (string) The block hash " | " \"hash\" : \"hash\", (string) The block hash " | ||||
"(same as provided)\n" | "(same as provided)\n" | ||||
" \"confirmations\" : n, (numeric) The number of " | " \"confirmations\" : n, (numeric) The number of " | ||||
"confirmations, or -1 if the block is not on the main " | "confirmations, or -1 if the block is not on the main " | ||||
"chain\n" | "chain\n" | ||||
" \"size\" : n, (numeric) The block size\n" | " \"size\" : n, (numeric) The block size\n" | ||||
" \"height\" : n, (numeric) The block height or " | " \"height\" : n, (numeric) The block height or " | ||||
"index\n" | "index\n" | ||||
" \"version\" : n, (numeric) The block version\n" | " \"version\" : n, (numeric) The block version\n" | ||||
" \"versionHex\" : \"00000000\", (string) The block " | " \"versionHex\" : \"00000000\", (string) The block " | ||||
"version formatted in hexadecimal\n" | "version formatted in hexadecimal\n" | ||||
" \"merkleroot\" : \"xxxx\", (string) The merkle root\n" | " \"merkleroot\" : \"xxxx\", (string) The merkle root\n" | ||||
" \"tx\" : [ (array of string) The " | " \"tx\" : [ (array of string) The " | ||||
"transaction ids\n" | "transaction ids\n" | ||||
" \"transactionid\" (string) The transaction id\n" | " \"transactionid\" (string) The transaction id\n" | ||||
" ,...\n" | " ,...\n" | ||||
" ],\n" | " ],\n" | ||||
" \"time\" : ttt, (numeric) The block time in " | " \"time\" : ttt, (numeric) The block time in " | ||||
"seconds since epoch (Jan 1 1970 GMT)\n" | "seconds since epoch (Jan 1 1970 GMT)\n" | ||||
" \"mediantime\" : ttt, (numeric) The median block " | " \"mediantime\" : ttt, (numeric) The median block " | ||||
"time in seconds since epoch (Jan 1 1970 GMT)\n" | "time in seconds since epoch (Jan 1 1970 GMT)\n" | ||||
" \"nonce\" : n, (numeric) The nonce\n" | " \"nonce\" : n, (numeric) The nonce\n" | ||||
" \"bits\" : \"1d00ffff\", (string) The bits\n" | " \"bits\" : \"1d00ffff\", (string) The bits\n" | ||||
" \"difficulty\" : x.xxx, (numeric) The difficulty\n" | " \"difficulty\" : x.xxx, (numeric) The difficulty\n" | ||||
" \"chainwork\" : \"xxxx\", (string) Expected number of " | " \"chainwork\" : \"xxxx\", (string) Expected number of " | ||||
"hashes required to produce the chain up to this block (in " | "hashes required to produce the chain up to this block (in " | ||||
"hex)\n" | "hex)\n" | ||||
" \"nTx\" : n, (numeric) The number of " | " \"nTx\" : n, (numeric) The number of " | ||||
"transactions in the block.\n" | "transactions in the block.\n" | ||||
" \"previousblockhash\" : \"hash\", (string) The hash of " | " \"previousblockhash\" : \"hash\", (string) The hash of " | ||||
"the previous block\n" | "the previous block\n" | ||||
" \"nextblockhash\" : \"hash\" (string) The hash of " | " \"nextblockhash\" : \"hash\" (string) The hash of " | ||||
"the next block\n" | "the next block\n" | ||||
"}\n"}, | "}\n"}, | ||||
RPCResult{ | RPCResult{ | ||||
"for verbosity = 2", | "for verbosity = 2", | ||||
"{\n" | "{\n" | ||||
" ..., Same output as verbosity = 1\n" | " ..., Same output as verbosity = 1\n" | ||||
" \"tx\" : [ (array of Objects) The " | " \"tx\" : [ (array of Objects) The " | ||||
"transactions in the format of the getrawtransaction RPC; " | "transactions in the format of the getrawtransaction RPC; " | ||||
"different from verbosity = 1 \"tx\" result\n" | "different from verbosity = 1 \"tx\" result\n" | ||||
" ...\n" | " ...\n" | ||||
" ],\n" | " ],\n" | ||||
" ... Same output as verbosity = 1\n" | " ... Same output as verbosity = 1\n" | ||||
"}\n"}, | "}\n"}, | ||||
}, | }, | ||||
RPCExamples{HelpExampleCli("getblock", | RPCExamples{ | ||||
"\"00000000c937983704a73af28acdec37b049d" | HelpExampleCli("getblock", "\"00000000c937983704a73af28acdec37b049d" | ||||
"214adbda81d7e2a3dd146f6ed09\"") + | "214adbda81d7e2a3dd146f6ed09\"") + | ||||
HelpExampleRpc("getblock", | HelpExampleRpc("getblock", "\"00000000c937983704a73af28acdec37b049d" | ||||
"\"00000000c937983704a73af28acdec37b049d" | |||||
"214adbda81d7e2a3dd146f6ed09\"")}, | "214adbda81d7e2a3dd146f6ed09\"")}, | ||||
} | }; | ||||
.ToString()); | |||||
if (request.fHelp || !help.IsValidNumArgs(request.params.size())) { | |||||
throw std::runtime_error(help.ToString()); | |||||
} | } | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
BlockHash hash(ParseHashV(request.params[0], "blockhash")); | BlockHash hash(ParseHashV(request.params[0], "blockhash")); | ||||
int verbosity = 1; | int verbosity = 1; | ||||
if (!request.params[1].isNull()) { | if (!request.params[1].isNull()) { | ||||
▲ Show 20 Lines • Show All 1,712 Lines • Show Last 20 Lines |