MCPcopy Create free account
hub / github.com/LUX-Core/lux / getblock

Function getblock

src/rpcblockchain.cpp:350–410  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

348}
349
350UniValue getblock(const UniValue& params, bool fHelp)
351{
352 if (fHelp || params.size() < 1 || params.size() > 2)
353 throw runtime_error(
354 "getblock \"hash\" ( verbose )\n"
355 "\nIf verbose is false, returns a string that is serialized, hex-encoded data for block 'hash'.\n"
356 "If verbose is true, returns an Object with information about block <hash>.\n"
357 "\nArguments:\n"
358 "1. \"hash\" (string, required) The block hash\n"
359 "2. verbose (boolean, optional, default=true) true for a json object, false for the hex encoded data\n"
360 "\nResult (for verbose = true):\n"
361 "{\n"
362 " \"hash\" : \"hash\", (string) the block hash (same as provided)\n"
363 " \"confirmations\" : n, (numeric) The number of confirmations, or -1 if the block is not on the main chain\n"
364 " \"size\" : n, (numeric) The block size\n"
365 " \"height\" : n, (numeric) The block height or index\n"
366 " \"version\" : n, (numeric) The block version\n"
367 " \"merkleroot\" : \"xxxx\", (string) The merkle root\n"
368 " \"tx\" : [ (array of string) The transaction ids\n"
369 " \"transactionid\" (string) The transaction id\n"
370 " ,...\n"
371 " ],\n"
372 " \"time\" : ttt, (numeric) The block time in seconds since epoch (Jan 1 1970 GMT)\n"
373 " \"nonce\" : n, (numeric) The nonce\n"
374 " \"bits\" : \"1d00ffff\", (string) The bits\n"
375 " \"difficulty\" : x.xxx, (numeric) The difficulty\n"
376 " \"previousblockhash\" : \"hash\", (string) The hash of the previous block\n"
377 " \"nextblockhash\" : \"hash\" (string) The hash of the next block\n"
378 "}\n"
379 "\nResult (for verbose=false):\n"
380 "\"data\" (string) A string that is serialized, hex-encoded data for block 'hash'.\n"
381 "\nExamples:\n" +
382 HelpExampleCli("getblock", "\"00000000000fd08c2fb661d2fcb0d49abb3a91e5f27082ce64feed3b4dede2e2\"") + HelpExampleRpc("getblock", "\"00000000000fd08c2fb661d2fcb0d49abb3a91e5f27082ce64feed3b4dede2e2\""));
383
384 LOCK(cs_main);
385
386 std::string strHash = params[0].get_str();
387 uint256 hash(strHash);
388
389 bool fVerbose = true;
390 if (params.size() > 1)
391 fVerbose = params[1].get_bool();
392
393 if (mapBlockIndex.count(hash) == 0)
394 throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
395
396 CBlock block;
397 CBlockIndex* pblockindex = mapBlockIndex[hash];
398
399 if (!ReadBlockFromDisk(block, pblockindex, Params().GetConsensus(),false)) // check proof of work not required here
400 throw JSONRPCError(RPC_INTERNAL_ERROR, "Can't read block from disk");
401
402 if (!fVerbose) {
403 CDataStream ssBlock(SER_NETWORK, PROTOCOL_VERSION);
404 ssBlock << block;
405 std::string strHex = HexStr(ssBlock.begin(), ssBlock.end());
406 return strHex;
407 }

Callers

nothing calls this directly

Calls 13

HelpExampleCliFunction · 0.85
HelpExampleRpcFunction · 0.85
JSONRPCErrorFunction · 0.85
ReadBlockFromDiskFunction · 0.85
HexStrFunction · 0.85
blockToJSONFunction · 0.85
get_strMethod · 0.80
ParamsClass · 0.70
sizeMethod · 0.45
get_boolMethod · 0.45
countMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected