@@ -737,6 +737,25 @@ static UniValue getblockheader(const JSONRPCRequest& request)
737737 return blockheaderToJSON (pblockindex);
738738}
739739
740+ static CBlock GetBlockChecked (const CBlockIndex* pblockindex)
741+ {
742+ CBlock block;
743+ if (fHavePruned && !(pblockindex->nStatus & BLOCK_HAVE_DATA) && pblockindex->nTx > 0 ) {
744+ throw JSONRPCError (RPC_MISC_ERROR, " Block not available (pruned data)" );
745+ }
746+
747+ if (!ReadBlockFromDisk (block, pblockindex, Params ().GetConsensus ())) {
748+ // Block not found on disk. This could be because we have the block
749+ // header in our index but don't have the block (for example if a
750+ // non-whitelisted node sends us an unrequested long chain of valid
751+ // blocks, we add the headers to our index, but don't accept the
752+ // block).
753+ throw JSONRPCError (RPC_MISC_ERROR, " Block not found on disk" );
754+ }
755+
756+ return block;
757+ }
758+
740759static UniValue getblock (const JSONRPCRequest& request)
741760{
742761 if (request.fHelp || request.params .size () < 1 || request.params .size () > 2 )
@@ -805,17 +824,7 @@ static UniValue getblock(const JSONRPCRequest& request)
805824 throw JSONRPCError (RPC_INVALID_ADDRESS_OR_KEY, " Block not found" );
806825 }
807826
808- CBlock block;
809- if (fHavePruned && !(pblockindex->nStatus & BLOCK_HAVE_DATA) && pblockindex->nTx > 0 )
810- throw JSONRPCError (RPC_MISC_ERROR, " Block not available (pruned data)" );
811-
812- if (!ReadBlockFromDisk (block, pblockindex, Params ().GetConsensus ()))
813- // Block not found on disk. This could be because we have the block
814- // header in our index but don't have the block (for example if a
815- // non-whitelisted node sends us an unrequested long chain of valid
816- // blocks, we add the headers to our index, but don't accept the
817- // block).
818- throw JSONRPCError (RPC_MISC_ERROR, " Block not found on disk" );
827+ const CBlock block = GetBlockChecked (pblockindex);
819828
820829 if (verbosity <= 0 )
821830 {
0 commit comments