mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-05-04 17:00:52 +02:00
Refactor: RPC: Separate GetBlockChecked() from getblock()
This does not change functionality
This commit is contained in:
parent
66cc47be98
commit
cda8e36f01
@ -737,6 +737,25 @@ static UniValue getblockheader(const JSONRPCRequest& request)
|
|||||||
return blockheaderToJSON(pblockindex);
|
return blockheaderToJSON(pblockindex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static CBlock GetBlockChecked(const CBlockIndex* pblockindex)
|
||||||
|
{
|
||||||
|
CBlock block;
|
||||||
|
if (fHavePruned && !(pblockindex->nStatus & BLOCK_HAVE_DATA) && pblockindex->nTx > 0) {
|
||||||
|
throw JSONRPCError(RPC_MISC_ERROR, "Block not available (pruned data)");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ReadBlockFromDisk(block, pblockindex, Params().GetConsensus())) {
|
||||||
|
// Block not found on disk. This could be because we have the block
|
||||||
|
// header in our index but don't have the block (for example if a
|
||||||
|
// non-whitelisted node sends us an unrequested long chain of valid
|
||||||
|
// blocks, we add the headers to our index, but don't accept the
|
||||||
|
// block).
|
||||||
|
throw JSONRPCError(RPC_MISC_ERROR, "Block not found on disk");
|
||||||
|
}
|
||||||
|
|
||||||
|
return block;
|
||||||
|
}
|
||||||
|
|
||||||
static UniValue getblock(const JSONRPCRequest& request)
|
static UniValue getblock(const JSONRPCRequest& request)
|
||||||
{
|
{
|
||||||
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2)
|
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2)
|
||||||
@ -805,17 +824,7 @@ static UniValue getblock(const JSONRPCRequest& request)
|
|||||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
CBlock block;
|
const CBlock block = GetBlockChecked(pblockindex);
|
||||||
if (fHavePruned && !(pblockindex->nStatus & BLOCK_HAVE_DATA) && pblockindex->nTx > 0)
|
|
||||||
throw JSONRPCError(RPC_MISC_ERROR, "Block not available (pruned data)");
|
|
||||||
|
|
||||||
if (!ReadBlockFromDisk(block, pblockindex, Params().GetConsensus()))
|
|
||||||
// Block not found on disk. This could be because we have the block
|
|
||||||
// header in our index but don't have the block (for example if a
|
|
||||||
// non-whitelisted node sends us an unrequested long chain of valid
|
|
||||||
// blocks, we add the headers to our index, but don't accept the
|
|
||||||
// block).
|
|
||||||
throw JSONRPCError(RPC_MISC_ERROR, "Block not found on disk");
|
|
||||||
|
|
||||||
if (verbosity <= 0)
|
if (verbosity <= 0)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user