Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/blockchain.cpp
Show First 20 Lines • Show All 812 Lines • ▼ Show 20 Lines | if (request.fHelp || request.params.size() < 1 || | ||||
HelpExampleCli("getblockheader", "\"00000000c937983704a73af28acdec3" | HelpExampleCli("getblockheader", "\"00000000c937983704a73af28acdec3" | ||||
"7b049d214adbda81d7e2a3dd146f6ed09" | "7b049d214adbda81d7e2a3dd146f6ed09" | ||||
"\"") + | "\"") + | ||||
HelpExampleRpc("getblockheader", "\"00000000c937983704a73af28acdec3" | HelpExampleRpc("getblockheader", "\"00000000c937983704a73af28acdec3" | ||||
"7b049d214adbda81d7e2a3dd146f6ed09" | "7b049d214adbda81d7e2a3dd146f6ed09" | ||||
"\"")); | "\"")); | ||||
} | } | ||||
LOCK(cs_main); | |||||
std::string strHash = request.params[0].get_str(); | std::string strHash = request.params[0].get_str(); | ||||
BlockHash hash(uint256S(strHash)); | BlockHash hash(uint256S(strHash)); | ||||
bool fVerbose = true; | bool fVerbose = true; | ||||
if (!request.params[1].isNull()) { | if (!request.params[1].isNull()) { | ||||
fVerbose = request.params[1].get_bool(); | fVerbose = request.params[1].get_bool(); | ||||
} | } | ||||
const CBlockIndex *pblockindex = LookupBlockIndex(hash); | const CBlockIndex *pblockindex; | ||||
const CBlockIndex *tip; | |||||
{ | |||||
LOCK(cs_main); | |||||
pblockindex = LookupBlockIndex(hash); | |||||
tip = chainActive.Tip(); | |||||
} | |||||
if (!pblockindex) { | if (!pblockindex) { | ||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found"); | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found"); | ||||
} | } | ||||
if (!fVerbose) { | if (!fVerbose) { | ||||
CDataStream ssBlock(SER_NETWORK, PROTOCOL_VERSION); | CDataStream ssBlock(SER_NETWORK, PROTOCOL_VERSION); | ||||
ssBlock << pblockindex->GetBlockHeader(); | ssBlock << pblockindex->GetBlockHeader(); | ||||
std::string strHex = HexStr(ssBlock.begin(), ssBlock.end()); | std::string strHex = HexStr(ssBlock.begin(), ssBlock.end()); | ||||
return strHex; | return strHex; | ||||
} | } | ||||
return blockheaderToJSON(chainActive.Tip(), pblockindex); | return blockheaderToJSON(tip, pblockindex); | ||||
} | } | ||||
static CBlock GetBlockChecked(const Config &config, | static CBlock GetBlockChecked(const Config &config, | ||||
const CBlockIndex *pblockindex) { | const CBlockIndex *pblockindex) { | ||||
CBlock block; | CBlock block; | ||||
if (IsBlockPruned(pblockindex)) { | if (IsBlockPruned(pblockindex)) { | ||||
throw JSONRPCError(RPC_MISC_ERROR, "Block not available (pruned data)"); | throw JSONRPCError(RPC_MISC_ERROR, "Block not available (pruned data)"); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 1,752 Lines • Show Last 20 Lines |