Changeset View
Changeset View
Standalone View
Standalone View
src/rest.cpp
Show First 20 Lines • Show All 540 Lines • ▼ Show 20 Lines | static bool rest_getutxos(Config &config, HTTPRequest *req, | ||||
// check spentness and form a bitmap (as well as a JSON capable | // check spentness and form a bitmap (as well as a JSON capable | ||||
// human-readable string representation) | // human-readable string representation) | ||||
std::vector<uint8_t> bitmap; | std::vector<uint8_t> bitmap; | ||||
std::vector<CCoin> outs; | std::vector<CCoin> outs; | ||||
std::string bitmapStringRepresentation; | std::string bitmapStringRepresentation; | ||||
std::vector<bool> hits; | std::vector<bool> hits; | ||||
bitmap.resize((vOutPoints.size() + 7) / 8); | bitmap.resize((vOutPoints.size() + 7) / 8); | ||||
{ | { | ||||
LOCK2(cs_main, g_mempool.cs); | auto process_utxos = [&vOutPoints, &outs, | ||||
&hits](const CCoinsView &view, | |||||
CCoinsView viewDummy; | const CTxMemPool &mempool) { | ||||
CCoinsViewCache view(&viewDummy); | for (const COutPoint &vOutPoint : vOutPoints) { | ||||
Coin coin; | |||||
bool hit = !mempool.isSpent(vOutPoint) && | |||||
view.GetCoin(vOutPoint, coin); | |||||
hits.push_back(hit); | |||||
if (hit) { | |||||
outs.emplace_back(std::move(coin)); | |||||
} | |||||
} | |||||
}; | |||||
if (fCheckMemPool) { | |||||
// use db+mempool as cache backend in case user likes to query | |||||
// mempool | |||||
LOCK2(cs_main, g_mempool.cs); | |||||
CCoinsViewCache &viewChain = *pcoinsTip; | CCoinsViewCache &viewChain = *pcoinsTip; | ||||
CCoinsViewMemPool viewMempool(&viewChain, g_mempool); | CCoinsViewMemPool viewMempool(&viewChain, g_mempool); | ||||
process_utxos(viewMempool, g_mempool); | |||||
if (fCheckMemPool) { | } else { | ||||
// switch cache backend to db+mempool in case user likes to query | // no need to lock mempool! | ||||
// mempool. | LOCK(cs_main); | ||||
view.SetBackend(viewMempool); | process_utxos(*pcoinsTip, CTxMemPool()); | ||||
} | |||||
for (size_t i = 0; i < vOutPoints.size(); i++) { | |||||
Coin coin; | |||||
bool hit = false; | |||||
if (view.GetCoin(vOutPoints[i], coin) && | |||||
!g_mempool.isSpent(vOutPoints[i])) { | |||||
hit = true; | |||||
outs.emplace_back(std::move(coin)); | |||||
} | } | ||||
hits.push_back(hit); | for (size_t i = 0; i < hits.size(); ++i) { | ||||
const bool hit = hits[i]; | |||||
// form a binary string representation (human-readable for json | // form a binary string representation (human-readable for json | ||||
// output) | // output) | ||||
bitmapStringRepresentation.append(hit ? "1" : "0"); | bitmapStringRepresentation.append(hit ? "1" : "0"); | ||||
bitmap[i / 8] |= ((uint8_t)hit) << (i % 8); | bitmap[i / 8] |= ((uint8_t)hit) << (i % 8); | ||||
} | } | ||||
} | } | ||||
switch (rf) { | switch (rf) { | ||||
▲ Show 20 Lines • Show All 97 Lines • Show Last 20 Lines |