Skip to content

Commit

Permalink
refactor: add a function for determining if a block is pruned or not
Browse files Browse the repository at this point in the history
  • Loading branch information
kallewoof committed May 30, 2018
1 parent f8a29ca commit e9a1881
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/rest.cpp
Expand Up @@ -217,7 +217,7 @@ static bool rest_block(HTTPRequest* req,
return RESTERR(req, HTTP_NOT_FOUND, hashStr + " not found");
}

if (fHavePruned && !(pblockindex->nStatus & BLOCK_HAVE_DATA) && pblockindex->nTx > 0)
if (IsBlockPruned(pblockindex))
return RESTERR(req, HTTP_NOT_FOUND, hashStr + " not available (pruned data)");

if (!ReadBlockFromDisk(block, pblockindex, Params().GetConsensus()))
Expand Down
2 changes: 1 addition & 1 deletion src/rpc/blockchain.cpp
Expand Up @@ -742,7 +742,7 @@ static UniValue getblockheader(const JSONRPCRequest& request)
static CBlock GetBlockChecked(const CBlockIndex* pblockindex)
{
CBlock block;
if (fHavePruned && !(pblockindex->nStatus & BLOCK_HAVE_DATA) && pblockindex->nTx > 0) {
if (IsBlockPruned(pblockindex)) {
throw JSONRPCError(RPC_MISC_ERROR, "Block not available (pruned data)");
}

Expand Down
6 changes: 6 additions & 0 deletions src/validation.h
Expand Up @@ -497,4 +497,10 @@ bool DumpMempool();
/** Load the mempool from disk. */
bool LoadMempool();

//! Check whether the block associated with this index entry is pruned or not.
inline bool IsBlockPruned(const CBlockIndex* pblockindex)
{
return (fHavePruned && !(pblockindex->nStatus & BLOCK_HAVE_DATA) && pblockindex->nTx > 0);
}

#endif // BITCOIN_VALIDATION_H

0 comments on commit e9a1881

Please sign in to comment.