Changeset View
Changeset View
Standalone View
Standalone View
src/rest.cpp
Show First 20 Lines • Show All 150 Lines • ▼ Show 20 Lines | static bool rest_headers(Config &config, HTTPRequest *req, | ||||
const BlockHash hash(rawHash); | 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)) { | ||||
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); | ||||
} | } | ||||
} | } | ||||
CDataStream ssHeader(SER_NETWORK, PROTOCOL_VERSION); | CDataStream ssHeader(SER_NETWORK, PROTOCOL_VERSION); | ||||
for (const CBlockIndex *pindex : headers) { | for (const CBlockIndex *pindex : headers) { | ||||
ssHeader << pindex->GetBlockHeader(); | ssHeader << pindex->GetBlockHeader(); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | static bool rest_block(const Config &config, HTTPRequest *req, | ||||
const BlockHash hash(rawHash); | 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) { | ||||
return RESTERR(req, HTTP_NOT_FOUND, hashStr + " not found"); | return RESTERR(req, HTTP_NOT_FOUND, hashStr + " not found"); | ||||
} | } | ||||
if (IsBlockPruned(pblockindex)) { | if (IsBlockPruned(pblockindex)) { | ||||
return RESTERR(req, HTTP_NOT_FOUND, | return RESTERR(req, HTTP_NOT_FOUND, | ||||
hashStr + " not available (pruned data)"); | hashStr + " not available (pruned data)"); | ||||
▲ Show 20 Lines • Show All 342 Lines • ▼ Show 20 Lines | bitmap.resize((vOutPoints.size() + 7) / 8); | ||||
} | } | ||||
} | } | ||||
switch (rf) { | switch (rf) { | ||||
case RetFormat::BINARY: { | case RetFormat::BINARY: { | ||||
// serialize data | // serialize data | ||||
// use exact same output as mentioned in Bip64 | // use exact same output as mentioned in Bip64 | ||||
CDataStream ssGetUTXOResponse(SER_NETWORK, PROTOCOL_VERSION); | CDataStream ssGetUTXOResponse(SER_NETWORK, PROTOCOL_VERSION); | ||||
ssGetUTXOResponse << chainActive.Height() | ssGetUTXOResponse << ::ChainActive().Height() | ||||
<< chainActive.Tip()->GetBlockHash() << bitmap | << ::ChainActive().Tip()->GetBlockHash() << bitmap | ||||
<< outs; | << outs; | ||||
std::string ssGetUTXOResponseString = ssGetUTXOResponse.str(); | std::string ssGetUTXOResponseString = ssGetUTXOResponse.str(); | ||||
req->WriteHeader("Content-Type", "application/octet-stream"); | req->WriteHeader("Content-Type", "application/octet-stream"); | ||||
req->WriteReply(HTTP_OK, ssGetUTXOResponseString); | req->WriteReply(HTTP_OK, ssGetUTXOResponseString); | ||||
return true; | return true; | ||||
} | } | ||||
case RetFormat::HEX: { | case RetFormat::HEX: { | ||||
CDataStream ssGetUTXOResponse(SER_NETWORK, PROTOCOL_VERSION); | CDataStream ssGetUTXOResponse(SER_NETWORK, PROTOCOL_VERSION); | ||||
ssGetUTXOResponse << chainActive.Height() | ssGetUTXOResponse << ::ChainActive().Height() | ||||
<< chainActive.Tip()->GetBlockHash() << bitmap | << ::ChainActive().Tip()->GetBlockHash() << bitmap | ||||
<< outs; | << outs; | ||||
std::string strHex = | std::string strHex = | ||||
HexStr(ssGetUTXOResponse.begin(), ssGetUTXOResponse.end()) + | HexStr(ssGetUTXOResponse.begin(), ssGetUTXOResponse.end()) + | ||||
"\n"; | "\n"; | ||||
req->WriteHeader("Content-Type", "text/plain"); | req->WriteHeader("Content-Type", "text/plain"); | ||||
req->WriteReply(HTTP_OK, strHex); | req->WriteReply(HTTP_OK, strHex); | ||||
return true; | return true; | ||||
} | } | ||||
case RetFormat::JSON: { | case RetFormat::JSON: { | ||||
UniValue objGetUTXOResponse(UniValue::VOBJ); | UniValue objGetUTXOResponse(UniValue::VOBJ); | ||||
// pack in some essentials | // pack in some essentials | ||||
// use more or less the same output as mentioned in Bip64 | // use more or less the same output as mentioned in Bip64 | ||||
objGetUTXOResponse.pushKV("chainHeight", chainActive.Height()); | objGetUTXOResponse.pushKV("chainHeight", ::ChainActive().Height()); | ||||
objGetUTXOResponse.pushKV( | objGetUTXOResponse.pushKV( | ||||
"chaintipHash", chainActive.Tip()->GetBlockHash().GetHex()); | "chaintipHash", ::ChainActive().Tip()->GetBlockHash().GetHex()); | ||||
objGetUTXOResponse.pushKV("bitmap", bitmapStringRepresentation); | objGetUTXOResponse.pushKV("bitmap", bitmapStringRepresentation); | ||||
UniValue utxos(UniValue::VARR); | UniValue utxos(UniValue::VARR); | ||||
for (const CCoin &coin : outs) { | for (const CCoin &coin : outs) { | ||||
UniValue utxo(UniValue::VOBJ); | UniValue utxo(UniValue::VOBJ); | ||||
utxo.pushKV("height", int32_t(coin.nHeight)); | utxo.pushKV("height", int32_t(coin.nHeight)); | ||||
utxo.pushKV("value", ValueFromAmount(coin.out.nValue)); | utxo.pushKV("value", ValueFromAmount(coin.out.nValue)); | ||||
▲ Show 20 Lines • Show All 51 Lines • Show Last 20 Lines |