Skip to content

Commit

Permalink
node: Added vector based coin lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
TomBriar committed Mar 7, 2024
1 parent ebba0f0 commit 593d58d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/node/coin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,23 @@ void FindCoins(const NodeContext& node, std::map<COutPoint, Coin>& coins)
}
}
}

std::vector<Coin> FindCoins(const node::NodeContext& node, const std::vector<COutPoint>& outpoints)
{
assert(node.mempool);
assert(node.chainman);
LOCK2(cs_main, node.mempool->cs);
CCoinsViewCache& chain_view = node.chainman->ActiveChainstate().CoinsTip();
CCoinsViewMemPool mempool_view(&chain_view, *node.mempool);
std::vector<Coin> coins;
for (auto& outpoint : outpoints) {
Coin coin;
if (!mempool_view.GetCoin(outpoint, coin)) {
// Either the coin is not in the CCoinsViewCache or is spent. Clear it.
coin.Clear();
}
coins.push_back(coin);
}
return coins;
}
} // namespace node
13 changes: 13 additions & 0 deletions src/node/coin.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define BITCOIN_NODE_COIN_H

#include <map>
#include <vector>

class COutPoint;
class Coin;
Expand All @@ -22,6 +23,18 @@ struct NodeContext;
* @param[in,out] coins map to fill
*/
void FindCoins(const node::NodeContext& node, std::map<COutPoint, Coin>& coins);

/**
* Look up unspent output information. Returns coins in the mempool and in the
* current chain UTXO set. Iterates through all the outpoints and
* returns the corresponding coins.
*
* @param[in] node The node context to use for lookup
* @param[in] outpoints A Vector containing outpoints
*/
std::vector<Coin> FindCoins(const node::NodeContext& node, const std::vector<COutPoint>& outpoints);
} // namespace node



#endif // BITCOIN_NODE_COIN_H

0 comments on commit 593d58d

Please sign in to comment.