@@ -737,6 +737,25 @@ static UniValue getblockheader(const JSONRPCRequest& request)
737
737
return blockheaderToJSON (pblockindex);
738
738
}
739
739
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
+
740
759
static UniValue getblock (const JSONRPCRequest& request)
741
760
{
742
761
if (request.fHelp || request.params .size () < 1 || request.params .size () > 2 )
@@ -805,17 +824,7 @@ static UniValue getblock(const JSONRPCRequest& request)
805
824
throw JSONRPCError (RPC_INVALID_ADDRESS_OR_KEY, " Block not found" );
806
825
}
807
826
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);
819
828
820
829
if (verbosity <= 0 )
821
830
{
0 commit comments