| 172 | } |
| 173 | |
| 174 | bool CCoinsViewCache::SpendCoin(const COutPoint &outpoint, Coin *moveout) { |
| 175 | CCoinsMap::iterator it = FetchCoin(outpoint); |
| 176 | if (it == cacheCoins.end()) { |
| 177 | return false; |
| 178 | } |
| 179 | Assume(TrySub(m_dirty_count, it->second.IsDirty())); |
| 180 | Assume(TrySub(cachedCoinsUsage, it->second.coin.DynamicMemoryUsage())); |
| 181 | TRACE5(utxocache, spent, outpoint.GetTxId().data(), outpoint.GetN(), |
| 182 | it->second.coin.GetHeight(), |
| 183 | it->second.coin.GetTxOut().nValue.ToString().c_str(), |
| 184 | it->second.coin.IsCoinBase()); |
| 185 | if (moveout) { |
| 186 | *moveout = std::move(it->second.coin); |
| 187 | } |
| 188 | if (it->second.IsFresh()) { |
| 189 | cacheCoins.erase(it); |
| 190 | } else { |
| 191 | CCoinsCacheEntry::SetDirty(*it, m_sentinel); |
| 192 | ++m_dirty_count; |
| 193 | it->second.coin.Clear(); |
| 194 | } |
| 195 | return true; |
| 196 | } |
| 197 | |
| 198 | static const Coin coinEmpty; |
| 199 | |