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

Function getblockheader

src/rpc/blockchain.cpp:721–785  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

719}
720
721static UniValue getblockheader(const JSONRPCRequest& request)
722{
723 if (request.fHelp || request.params.size() < 1 || request.params.size() > 2)
724 throw std::runtime_error(
725 "getblockheader \"hash\" ( verbose legacy )\n"
726 "\nIf verbose is false, returns a string that is serialized, hex-encoded data for blockheader 'hash'.\n"
727 "If verbose is true, returns an Object with information about blockheader <hash>.\n"
728 "\nArguments:\n"
729 "1. \"hash\" (string, required) The block hash\n"
730 "2. \"verbose\" (boolean, optional, default=true) true for a json object, false for the hex encoded data\n"
731 "3. \"legacy\" (boolean, optional, default=false) indicates if the block should be in legacy format\n"
732 "\nResult (for verbose = true):\n"
733 "{\n"
734 " \"hash\" : \"hash\", (string) the block hash (same as provided)\n"
735 " \"confirmations\" : n, (numeric) The number of confirmations, or -1 if the block is not on the main chain\n"
736 " \"height\" : n, (numeric) The block height or index\n"
737 " \"version\" : n, (numeric) The block version\n"
738 " \"versionHex\" : \"00000000\", (string) The block version formatted in hexadecimal\n"
739 " \"merkleroot\" : \"xxxx\", (string) The merkle root\n"
740 " \"time\" : ttt, (numeric) The block time in seconds since epoch (Jan 1 1970 GMT)\n"
741 " \"mediantime\" : ttt, (numeric) The median block time in seconds since epoch (Jan 1 1970 GMT)\n"
742 " \"nonce\" : n, (numeric) The nonce\n"
743 " \"bits\" : \"1d00ffff\", (string) The bits\n"
744 " \"difficulty\" : x.xxx, (numeric) The difficulty\n"
745 " \"chainwork\" : \"0000...1f3\" (string) Expected number of hashes required to produce the current chain (in hex)\n"
746 " \"nTx\" : n, (numeric) The number of transactions in the block.\n"
747 " \"previousblockhash\" : \"hash\", (string) The hash of the previous block\n"
748 " \"nextblockhash\" : \"hash\", (string) The hash of the next block\n"
749 "}\n"
750 "\nResult (for verbose=false):\n"
751 "\"data\" (string) A string that is serialized, hex-encoded data for block 'hash'.\n"
752 "\nExamples:\n"
753 + HelpExampleCli("getblockheader", "\"00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09\"")
754 + HelpExampleRpc("getblockheader", "\"00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09\"")
755 );
756
757 LOCK(cs_main);
758
759 std::string strHash = request.params[0].get_str();
760 uint256 hash(uint256S(strHash));
761
762 bool fVerbose = true;
763 if (!request.params[1].isNull())
764 fVerbose = request.params[1].get_bool();
765
766 bool legacy_format = false;
767 if (request.params.size() == 3 && request.params[2].get_bool() == true) {
768 legacy_format = true;
769 }
770 const CBlockIndex* pblockindex = LookupBlockIndex(hash);
771 if (!pblockindex) {
772 throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
773 }
774
775 if (!fVerbose)
776 {
777 int ser_flags = legacy_format ? SERIALIZE_BLOCK_LEGACY : 0;
778 CDataStream ssBlock(SER_NETWORK, PROTOCOL_VERSION | ser_flags);

Callers

nothing calls this directly

Calls 13

HelpExampleCliFunction · 0.85
HelpExampleRpcFunction · 0.85
uint256SFunction · 0.85
LookupBlockIndexFunction · 0.85
JSONRPCErrorFunction · 0.85
HexStrFunction · 0.85
blockheaderToJSONFunction · 0.85
isNullMethod · 0.80
get_boolMethod · 0.80
sizeMethod · 0.45
GetBlockHeaderMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected