2021-11-01 12:24:34 +01:00
|
|
|
// Copyright (c) 2019 The Bitcoin Core developers
|
|
|
|
// Distributed under the MIT software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
|
|
|
#include <node/coin.h>
|
|
|
|
|
2022-04-23 07:48:10 +02:00
|
|
|
#include <node/context.h>
|
2021-11-01 12:24:34 +01:00
|
|
|
#include <txmempool.h>
|
|
|
|
#include <validation.h>
|
|
|
|
|
2022-04-23 07:48:10 +02:00
|
|
|
void FindCoins(const NodeContext& node, std::map<COutPoint, Coin>& coins)
|
2021-11-01 12:24:34 +01:00
|
|
|
{
|
2022-04-23 07:48:10 +02:00
|
|
|
assert(node.mempool);
|
2023-06-01 09:32:41 +02:00
|
|
|
assert(node.chainman);
|
2022-04-23 07:48:10 +02:00
|
|
|
LOCK2(cs_main, node.mempool->cs);
|
2023-06-01 08:33:04 +02:00
|
|
|
assert(std::addressof(::ChainstateActive()) == std::addressof(node.chainman->ActiveChainstate()));
|
|
|
|
CCoinsViewCache& chain_view = node.chainman->ActiveChainstate().CoinsTip();
|
2022-04-23 07:48:10 +02:00
|
|
|
CCoinsViewMemPool mempool_view(&chain_view, *node.mempool);
|
2021-11-01 12:24:34 +01:00
|
|
|
for (auto& coin : coins) {
|
|
|
|
if (!mempool_view.GetCoin(coin.first, coin.second)) {
|
|
|
|
// Either the coin is not in the CCoinsViewCache or is spent. Clear it.
|
|
|
|
coin.second.Clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|