| 64 | } |
| 65 | |
| 66 | void CCoinsViewCache::AddCoin(const COutPoint &outpoint, Coin&& coin, bool possible_overwrite) { |
| 67 | assert(!coin.IsSpent()); |
| 68 | if (coin.out.scriptPubKey.IsUnspendable()) return; |
| 69 | CCoinsMap::iterator it; |
| 70 | bool inserted; |
| 71 | std::tie(it, inserted) = cacheCoins.emplace(std::piecewise_construct, std::forward_as_tuple(outpoint), std::tuple<>()); |
| 72 | bool fresh = false; |
| 73 | if (!inserted) { |
| 74 | cachedCoinsUsage -= it->second.coin.DynamicMemoryUsage(); |
| 75 | } |
| 76 | if (!possible_overwrite) { |
| 77 | if (!it->second.coin.IsSpent()) { |
| 78 | throw std::logic_error("Adding new coin that replaces non-pruned entry"); |
| 79 | } |
| 80 | fresh = !(it->second.flags & CCoinsCacheEntry::DIRTY); |
| 81 | } |
| 82 | it->second.coin = std::move(coin); |
| 83 | it->second.flags |= CCoinsCacheEntry::DIRTY | (fresh ? CCoinsCacheEntry::FRESH : 0); |
| 84 | cachedCoinsUsage += it->second.coin.DynamicMemoryUsage(); |
| 85 | } |
| 86 | |
| 87 | void AddCoins(CCoinsViewCache& cache, const CTransaction &tx, int nHeight, bool check) { |
| 88 | bool fCoinbase = tx.IsCoinBase(); |