diff --git a/src/rest.cpp b/src/rest.cpp --- a/src/rest.cpp +++ b/src/rest.cpp @@ -240,8 +240,7 @@ return RESTERR(req, HTTP_NOT_FOUND, hashStr + " not found"); } - if (fHavePruned && !pblockindex->nStatus.hasData() && - pblockindex->nTx > 0) { + if (IsBlockPruned(pblockindex)) { return RESTERR(req, HTTP_NOT_FOUND, hashStr + " not available (pruned data)"); } diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -848,8 +848,7 @@ static CBlock GetBlockChecked(const Config &config, const CBlockIndex *pblockindex) { CBlock block; - if (fHavePruned && !pblockindex->nStatus.hasData() && - pblockindex->nTx > 0) { + if (IsBlockPruned(pblockindex)) { throw JSONRPCError(RPC_MISC_ERROR, "Block not available (pruned data)"); } diff --git a/src/validation.h b/src/validation.h --- a/src/validation.h +++ b/src/validation.h @@ -742,4 +742,7 @@ /** Load the mempool from disk. */ bool LoadMempool(const Config &config, CTxMemPool &pool); +//! Check whether the block associated with this index entry is pruned or not. +bool IsBlockPruned(const CBlockIndex *pblockindex); + #endif // BITCOIN_VALIDATION_H diff --git a/src/validation.cpp b/src/validation.cpp --- a/src/validation.cpp +++ b/src/validation.cpp @@ -5754,6 +5754,11 @@ return true; } +bool IsBlockPruned(const CBlockIndex *pblockindex) { + return (fHavePruned && !pblockindex->nStatus.hasData() && + pblockindex->nTx > 0); +} + //! Guess how far we are in the verification process at the given block index //! require cs_main if pindex has not been validated yet (because nChainTx might //! be unset)