44 CCoinsMap::iterator it =
cacheCoins.find(outpoint);
50 CCoinsMap::iterator ret =
cacheCoins.emplace(std::piecewise_construct, std::forward_as_tuple(outpoint), std::forward_as_tuple(std::move(tmp))).first;
51 if (ret->second.coin.IsSpent()) {
61 CCoinsMap::const_iterator it =
FetchCoin(outpoint);
63 coin = it->second.coin;
71 if (coin.out.scriptPubKey.IsUnspendable())
return;
72 CCoinsMap::iterator it;
74 std::tie(it, inserted) =
cacheCoins.emplace(std::piecewise_construct, std::forward_as_tuple(outpoint), std::tuple<>());
79 if (!possible_overwrite) {
80 if (!it->second.coin.IsSpent()) {
81 throw std::logic_error(
"Adding new coin that replaces non-pruned entry");
85 it->second.coin = std::move(coin);
93 for (
size_t i = 0; i < tx.
vout.size(); ++i) {
102 CCoinsMap::iterator it =
FetchCoin(outpoint);
106 *moveout = std::move(it->second.coin);
112 it->second.coin.Clear();
117 static const Coin coinEmpty;
120 CCoinsMap::const_iterator it =
FetchCoin(outpoint);
124 return it->second.coin;
129 CCoinsMap::const_iterator it =
FetchCoin(outpoint);
130 return (it !=
cacheCoins.end() && !it->second.coin.IsSpent());
134 CCoinsMap::const_iterator it =
cacheCoins.find(outpoint);
135 return (it !=
cacheCoins.end() && !it->second.coin.IsSpent());
149 for (CCoinsMap::iterator it = mapCoins.begin(); it != mapCoins.end();) {
151 CCoinsMap::iterator itUs =
cacheCoins.find(it->first);
159 entry.
coin = std::move(it->second.coin);
174 throw std::logic_error(
"FRESH flag misapplied to cache entry for base transaction with spendable outputs");
186 itUs->second.coin = std::move(it->second.coin);
197 CCoinsMap::iterator itOld = it++;
198 mapCoins.erase(itOld);
213 CCoinsMap::iterator it =
cacheCoins.find(hash);
214 if (it !=
cacheCoins.end() && it->second.flags == 0) {
230 for (
unsigned int i = 0; i < tx.
vin.size(); i++)
239 for (
unsigned int i = 0; i < tx.
vin.size(); i++) {
249 static const size_t MAX_OUTPUTS_PER_BLOCK =
dgpMaxBlockWeight / MIN_TRANSACTION_OUTPUT_WEIGHT;
255 while (iter.
n < MAX_OUTPUTS_PER_BLOCK) {
257 if (!alternate.
IsSpent())
return alternate;
uint256 GetBestBlock() const override
Retrieve the block hash whose state this CCoinsView currently represents.
const Coin & AccessByTxid(const CCoinsViewCache &view, const uint256 &txid)
Utility function to find any unspent output with a given txid.
void AddCoin(const COutPoint &outpoint, Coin &&coin, bool potential_overwrite)
Add a coin.
CCoinsViewCache(CCoinsView *baseIn)
bool HaveCoinInCache(const COutPoint &outpoint) const
Check if we have the given utxo already loaded in this cache.
bool Flush()
Push the modifications applied to this cache to its base.
void SetBackend(CCoinsView &viewIn)
size_t GetSerializeSize(const T &t, int nType, int nVersion=0)
bool HaveInputs(const CTransaction &tx) const
Check whether all prevouts of the transaction are present in the UTXO set represented by this view...
CTxOut out
unspent transaction output
std::vector< uint256 > GetHeadBlocks() const override
Retrieve the range of blocks that may have been only partially written.
virtual bool BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock)
Do a bulk modification (multiple Coin changes + BestBlock change).
unsigned int GetCacheSize() const
Calculate the size of the cache (in number of transaction outputs)
void AddCoins(CCoinsViewCache &cache, const CTransaction &tx, int nHeight, bool check)
Utility function to add all of a transaction's outputs to a cache.
std::hash for asio::adress
assert(len-trim+(2 *lenIndices)<=WIDTH)
CCoinsViewCursor * Cursor() const override
Get a cursor to iterate over the whole state.
bool BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock) override
Do a bulk modification (multiple Coin changes + BestBlock change).
virtual CCoinsViewCursor * Cursor() const
Get a cursor to iterate over the whole state.
bool SpendCoin(const COutPoint &outpoint, Coin *moveto=nullptr)
Spend a coin.
const std::vector< CTxIn > vin
virtual bool GetCoin(const COutPoint &outpoint, Coin &coin) const
Retrieve the Coin (unspent transaction output) for a given outpoint.
int64_t CAmount
Amount in lius (Can be negative)
void SetBestBlock(const uint256 &hashBlock)
virtual std::vector< uint256 > GetHeadBlocks() const
Retrieve the range of blocks that may have been only partially written.
bool BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock) override
Do a bulk modification (multiple Coin changes + BestBlock change).
virtual uint256 GetBestBlock() const
Retrieve the block hash whose state this CCoinsView currently represents.
Abstract view on the open txout dataset.
std::unordered_map< COutPoint, CCoinsCacheEntry, SaltedOutpointHasher > CCoinsMap
const std::vector< CTxOut > vout
const Coin & AccessCoin(const COutPoint &output) const
Return a reference to Coin in the cache, or a pruned one if not found.
An output of a transaction.
An outpoint - a combination of a transaction hash and an index n into its vout.
CCoinsViewBacked(CCoinsView *viewIn)
CCoinsMap::iterator FetchCoin(const COutPoint &outpoint) const
size_t DynamicMemoryUsage() const
uint256 GetBestBlock() const override
Retrieve the block hash whose state this CCoinsView currently represents.
bool HaveCoin(const COutPoint &outpoint) const override
Just check whether a given outpoint is unspent.
uint256 hashBlock
Make mutable so that we can "fill the cache" even from Get-methods declared as "const".
virtual bool HaveCoin(const COutPoint &outpoint) const
Just check whether a given outpoint is unspent.
virtual size_t EstimateSize() const
Estimate database size (0 if not implemented)
bool GetCoin(const COutPoint &outpoint, Coin &coin) const override
Retrieve the Coin (unspent transaction output) for a given outpoint.
CAmount GetValueIn(const CTransaction &tx) const
Amount of fabcoins coming in to a transaction Note that lightweight clients may not know anything bes...
void Uncache(const COutPoint &outpoint)
Removes the UTXO with the given outpoint from the cache, if it is not modified.
bool GetCoin(const COutPoint &outpoint, Coin &coin) const override
Retrieve the Coin (unspent transaction output) for a given outpoint.
const uint256 & GetHash() const
The basic transaction that is broadcasted on the network and contained in blocks. ...
CCoinsView backed by another CCoinsView.
size_t EstimateSize() const override
Estimate database size (0 if not implemented)
CCoinsView that adds a memory cache for transactions to another CCoinsView.
uint64_t GetRand(uint64_t nMax)
unsigned int dgpMaxBlockWeight
The maximum allowed weight for a block, see BIP 141 (network rule)
size_t DynamicMemoryUsage() const
Calculate the size of the cache (in bytes)
bool HaveCoin(const COutPoint &outpoint) const override
Just check whether a given outpoint is unspent.
Cursor for iterating over CoinsView state.