Changeset View
Changeset View
Standalone View
Standalone View
src/rest.cpp
Show First 20 Lines • Show All 147 Lines • ▼ Show 20 Lines | static bool rest_headers(Config &config, HTTPRequest *req, | ||||
long count = strtol(path[0].c_str(), nullptr, 10); | long count = strtol(path[0].c_str(), nullptr, 10); | ||||
if (count < 1 || count > 2000) { | if (count < 1 || count > 2000) { | ||||
return RESTERR(req, HTTP_BAD_REQUEST, | return RESTERR(req, HTTP_BAD_REQUEST, | ||||
"Header count out of range: " + path[0]); | "Header count out of range: " + path[0]); | ||||
} | } | ||||
std::string hashStr = path[1]; | std::string hashStr = path[1]; | ||||
uint256 hash; | uint256 rawHash; | ||||
if (!ParseHashStr(hashStr, hash)) { | if (!ParseHashStr(hashStr, rawHash)) { | ||||
return RESTERR(req, HTTP_BAD_REQUEST, "Invalid hash: " + hashStr); | return RESTERR(req, HTTP_BAD_REQUEST, "Invalid hash: " + hashStr); | ||||
} | } | ||||
const BlockHash hash(rawHash); | |||||
const CBlockIndex *tip = nullptr; | const CBlockIndex *tip = nullptr; | ||||
std::vector<const CBlockIndex *> headers; | std::vector<const CBlockIndex *> headers; | ||||
headers.reserve(count); | headers.reserve(count); | ||||
{ | { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
tip = chainActive.Tip(); | tip = chainActive.Tip(); | ||||
const CBlockIndex *pindex = LookupBlockIndex(hash); | const CBlockIndex *pindex = LookupBlockIndex(hash); | ||||
while (pindex != nullptr && chainActive.Contains(pindex)) { | while (pindex != nullptr && chainActive.Contains(pindex)) { | ||||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | static bool rest_block(const Config &config, HTTPRequest *req, | ||||
const std::string &strURIPart, bool showTxDetails) { | const std::string &strURIPart, bool showTxDetails) { | ||||
if (!CheckWarmup(req)) { | if (!CheckWarmup(req)) { | ||||
return false; | return false; | ||||
} | } | ||||
std::string hashStr; | std::string hashStr; | ||||
const RetFormat rf = ParseDataFormat(hashStr, strURIPart); | const RetFormat rf = ParseDataFormat(hashStr, strURIPart); | ||||
uint256 hash; | uint256 rawHash; | ||||
if (!ParseHashStr(hashStr, hash)) { | if (!ParseHashStr(hashStr, rawHash)) { | ||||
return RESTERR(req, HTTP_BAD_REQUEST, "Invalid hash: " + hashStr); | return RESTERR(req, HTTP_BAD_REQUEST, "Invalid hash: " + hashStr); | ||||
} | } | ||||
const BlockHash hash(rawHash); | |||||
CBlock block; | CBlock block; | ||||
CBlockIndex *pblockindex = nullptr; | CBlockIndex *pblockindex = nullptr; | ||||
CBlockIndex *tip = nullptr; | CBlockIndex *tip = nullptr; | ||||
{ | { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
tip = chainActive.Tip(); | tip = chainActive.Tip(); | ||||
pblockindex = LookupBlockIndex(hash); | pblockindex = LookupBlockIndex(hash); | ||||
if (!pblockindex) { | if (!pblockindex) { | ||||
▲ Show 20 Lines • Show All 450 Lines • Show Last 20 Lines |