Skip to content

Commit

Permalink
[rest] fix rest/getutxos endpoint for usage without mempool
Browse files Browse the repository at this point in the history
The chain-only view from pcoinsTip was only assigned when the user
queried inclusive of mempool, but when queried without, the view
only contained an empty dummy.
  • Loading branch information
patricklodder committed Apr 6, 2022
1 parent 08d2d51 commit 7e72717
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/rest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -512,15 +512,21 @@ static bool rest_getutxos(HTTPRequest* req, const std::string& strURIPart)
CCoinsViewCache& viewChain = *pcoinsTip;
CCoinsViewMemPool viewMempool(&viewChain, mempool);

if (fCheckMemPool)
view.SetBackend(viewMempool); // switch cache backend to db+mempool in case user likes to query mempool
if (fCheckMemPool) {
view.SetBackend(viewMempool); // set cache backend to db+mempool in case user likes to query mempool
} else {
view.SetBackend(viewChain); // set cache backend to db only otherwise
}

for (size_t i = 0; i < vOutPoints.size(); i++) {
CCoins coins;
uint256 hash = vOutPoints[i].hash;
bool hit = false;
if (view.GetCoins(hash, coins)) {
mempool.pruneSpent(hash, coins);
if (fCheckMemPool) {
mempool.pruneSpent(hash, coins);
}

if (coins.IsAvailable(vOutPoints[i].n)) {
hit = true;
// Safe to index into vout here because IsAvailable checked if it's off the end of the array, or if
Expand Down

0 comments on commit 7e72717

Please sign in to comment.