MCPcopy Create free account
hub / github.com/WaykiChain/WaykiChain / getblock

Function getblock

src/rpc/rpcblockchain.cpp:177–271  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

175}
176
177Value getblock(const Array& params, bool fHelp) {
178 if (fHelp || params.size() < 1 || params.size() > 3) {
179 throw runtime_error(
180 "getblock \"hash or height\" [\"list_txs\"] [\"verbose\"]\n"
181 "\nIf verbose is false, returns a string that is serialized, hex-encoded data for block 'hash'.\n"
182 "If verbose is true, returns an Object with information about block <hash>.\n"
183 "\nArguments:\n"
184 "1.\"hash or height\" (string or numeric, required) string for the block hash, or numeric for the block "
185 "height\n"
186 "2.\"list_txs\" (boolean, optional, default=false) true: return a detailed list of txes from the block\n"
187 "3.\"verbose\" (boolean, optional, default=true) true: return a json object; false: return hex only\n"
188 "encoded data\n"
189 "\nResult (for verbose = true):\n"
190 "{\n"
191 " \"hash\" : \"hash\", (string) the block hash (same as provided)\n"
192 " \"confirmations\" : n, (numeric) The number of confirmations\n"
193 " \"size\" : n, (numeric) The block size\n"
194 " \"height\" : n, (numeric) The block height or index\n"
195 " \"version\" : n, (numeric) The block version\n"
196 " \"merkleroot\" : \"xxxx\", (string) The merkle root\n"
197 " \"tx\" : [ (array of string) The transaction ids\n"
198 " \"txid\" (string) The transaction id\n"
199 " ,...\n"
200 " ],\n"
201 " \"time\" : n, (numeric) The block time in seconds since epoch (Jan 1 1970 GMT)\n"
202 " \"nonce\" : n, (numeric) The nonce\n"
203 " \"previousblockhash\" : \"hash\", (string) The hash of the previous block\n"
204 " \"nextblockhash\" : \"hash\" (string) The hash of the next block\n"
205 " \"median_price\" : \"array\" (array) The median price info\n"
206 "}\n"
207 "\nResult (for verbose=false):\n"
208 "\"data\" (string) A string that is serialized, hex-encoded data for block 'hash'.\n"
209 "\nExamples:\n" +
210 HelpExampleCli("getblock", "\"d640d051704155b1fd3ec8d0331497448c259b0ab0499e109da7ae2bc7423bc2\"") +
211 "\nAs json rpc\n" +
212 HelpExampleRpc("getblock", "\"d640d051704155b1fd3ec8d0331497448c259b0ab0499e109da7ae2bc7423bc2\""));
213 }
214
215 // RPCTypeCheck(params, boost::assign::list_of(str_type)(bool_type)); disable this to allow either string or int argument
216
217 std::string strHash;
218 if (int_type == params[0].type()) {
219 int height = params[0].get_int();
220 if (height < 0 || height > chainActive.Height())
221 throw JSONRPCError(RPC_INVALID_PARAMETER, "Block height out of range.");
222
223 CBlockIndex* pBlockIndex = chainActive[height];
224 strHash = pBlockIndex->GetBlockHash().GetHex();
225 } else {
226 strHash = params[0].get_str();
227 }
228 uint256 hash(uint256S(strHash));
229
230 bool fListTxs = false;
231 if (params.size() > 1)
232 fListTxs = params[1].get_bool();
233
234 bool fVerbose = true;

Callers

nothing calls this directly

Calls 15

HelpExampleCliFunction · 0.85
HelpExampleRpcFunction · 0.85
JSONRPCErrorFunction · 0.85
uint256SFunction · 0.85
ReadBlockFromDiskFunction · 0.85
HexStrFunction · 0.85
BlockToJSONFunction · 0.85
GetTxDetailJSONFunction · 0.85
PairClass · 0.85
typeMethod · 0.80
get_intMethod · 0.80
HeightMethod · 0.80

Tested by

no test coverage detected