| 130 | } |
| 131 | |
| 132 | bool CCoinsViewCache::SpendCoin(const COutPoint &outpoint, Coin* moveout) { |
| 133 | CCoinsMap::iterator it = FetchCoin(outpoint); |
| 134 | if (it == cacheCoins.end()) return false; |
| 135 | Assume(TrySub(m_dirty_count, it->second.IsDirty())); |
| 136 | Assume(TrySub(cachedCoinsUsage, it->second.coin.DynamicMemoryUsage())); |
| 137 | TRACEPOINT(utxocache, spent, |
| 138 | outpoint.hash.data(), |
| 139 | (uint32_t)outpoint.n, |
| 140 | (uint32_t)it->second.coin.nHeight, |
| 141 | (int64_t)it->second.coin.out.nValue, |
| 142 | (bool)it->second.coin.IsCoinBase()); |
| 143 | if (moveout) { |
| 144 | *moveout = std::move(it->second.coin); |
| 145 | } |
| 146 | if (it->second.IsFresh()) { |
| 147 | cacheCoins.erase(it); |
| 148 | } else { |
| 149 | CCoinsCacheEntry::SetDirty(*it, m_sentinel); |
| 150 | ++m_dirty_count; |
| 151 | it->second.coin.Clear(); |
| 152 | } |
| 153 | return true; |
| 154 | } |
| 155 | |
| 156 | static const Coin coinEmpty; |
| 157 | |