Changeset View
Changeset View
Standalone View
Standalone View
src/rest.cpp
Show First 20 Lines • Show All 158 Lines • ▼ Show 20 Lines | static bool rest_headers(Config &config, HTTPRequest *req, | ||||
if (!ParseHashStr(hashStr, hash)) { | if (!ParseHashStr(hashStr, hash)) { | ||||
return RESTERR(req, HTTP_BAD_REQUEST, "Invalid hash: " + hashStr); | return RESTERR(req, HTTP_BAD_REQUEST, "Invalid hash: " + hashStr); | ||||
} | } | ||||
std::vector<const CBlockIndex *> headers; | std::vector<const CBlockIndex *> headers; | ||||
headers.reserve(count); | headers.reserve(count); | ||||
{ | { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
BlockMap::const_iterator it = mapBlockIndex.find(hash); | const CBlockIndex *pindex = LookupBlockIndex(hash); | ||||
const CBlockIndex *pindex = | |||||
(it != mapBlockIndex.end()) ? it->second : nullptr; | |||||
while (pindex != nullptr && chainActive.Contains(pindex)) { | while (pindex != nullptr && chainActive.Contains(pindex)) { | ||||
headers.push_back(pindex); | headers.push_back(pindex); | ||||
if (headers.size() == size_t(count)) { | if (headers.size() == size_t(count)) { | ||||
break; | break; | ||||
} | } | ||||
pindex = chainActive.Next(pindex); | pindex = chainActive.Next(pindex); | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 55 Lines • ▼ Show 20 Lines | static bool rest_block(const Config &config, HTTPRequest *req, | ||||
if (!ParseHashStr(hashStr, hash)) { | if (!ParseHashStr(hashStr, hash)) { | ||||
return RESTERR(req, HTTP_BAD_REQUEST, "Invalid hash: " + hashStr); | return RESTERR(req, HTTP_BAD_REQUEST, "Invalid hash: " + hashStr); | ||||
} | } | ||||
CBlock block; | CBlock block; | ||||
CBlockIndex *pblockindex = nullptr; | CBlockIndex *pblockindex = nullptr; | ||||
{ | { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
if (mapBlockIndex.count(hash) == 0) { | pblockindex = LookupBlockIndex(hash); | ||||
if (!pblockindex) { | |||||
return RESTERR(req, HTTP_NOT_FOUND, hashStr + " not found"); | return RESTERR(req, HTTP_NOT_FOUND, hashStr + " not found"); | ||||
} | } | ||||
pblockindex = mapBlockIndex[hash]; | |||||
if (fHavePruned && !pblockindex->nStatus.hasData() && | if (fHavePruned && !pblockindex->nStatus.hasData() && | ||||
pblockindex->nTx > 0) { | pblockindex->nTx > 0) { | ||||
return RESTERR(req, HTTP_NOT_FOUND, | return RESTERR(req, HTTP_NOT_FOUND, | ||||
hashStr + " not available (pruned data)"); | hashStr + " not available (pruned data)"); | ||||
} | } | ||||
if (!ReadBlockFromDisk(block, pblockindex, config)) { | if (!ReadBlockFromDisk(block, pblockindex, config)) { | ||||
return RESTERR(req, HTTP_NOT_FOUND, hashStr + " not found"); | return RESTERR(req, HTTP_NOT_FOUND, hashStr + " not found"); | ||||
▲ Show 20 Lines • Show All 456 Lines • Show Last 20 Lines |