internal (ICoinsView toRemove, ICoinsView toAdd) Undo(uint256 txId) { lock (Lock) { var allCoins = AsAllCoinsViewNoLock(); var toRemove = new List <SmartCoin>(); var toAdd = new List <SmartCoin>(); // remove recursively the coins created by the transaction foreach (SmartCoin createdCoin in allCoins.CreatedBy(txId)) { toRemove.AddRange(Remove(createdCoin)); } // destroyed (spent) coins are now (unspent) foreach (SmartCoin destroyedCoin in allCoins.SpentBy(txId)) { if (SpentCoins.Remove(destroyedCoin)) { Coins.Add(destroyedCoin); toAdd.Add(destroyedCoin); } } InvalidateSnapshot = true; return(new CoinsView(toRemove), new CoinsView(toAdd)); } }
public void RemoveFromBlock(Height blockHeight) { lock (Lock) { var allCoins = AsAllCoinsViewNoLock(); foreach (var toRemove in allCoins.AtBlockHeight(blockHeight).ToList()) { var coinsToRemove = allCoins.DescendantOfAndSelf(toRemove).ToList(); foreach (var coin in coinsToRemove) { if (coin.Unspent) { if (Coins.Remove(coin)) { InvalidateSnapshot = true; } } else { SpentCoins.Remove(toRemove); } } } } }
private ICoinsView RemoveNoLock(SmartCoin coin) { var coinsToRemove = DescendantOfAndSelfNoLock(coin); foreach (var toRemove in coinsToRemove) { if (!Coins.Remove(toRemove)) { SpentCoins.Remove(toRemove); } var removedCoinOutPoint = toRemove.OutPoint; // If we can find it in our outpoint to coins cache. if (TryGetSpenderSmartCoinsByOutPointNoLock(removedCoinOutPoint, out var coinsByOutPoint)) { // Go through all the coins of that cache where the coin is the coin we are wishing to remove. foreach (var coinByOutPoint in coinsByOutPoint.Where(x => x == toRemove)) { // Remove the coin from the set, and if the set becomes empty as a consequence remove the key too. if (CoinsByOutPoint[removedCoinOutPoint].Remove(coinByOutPoint) && !CoinsByOutPoint[removedCoinOutPoint].Any()) { CoinsByOutPoint.Remove(removedCoinOutPoint); } } } } InvalidateSnapshot = true; return(coinsToRemove); }
public ICoinsView Remove(SmartCoin coin) { lock (Lock) { var coinsToRemove = DescendantOfAndSelfNoLock(coin); foreach (var toRemove in coinsToRemove) { if (!Coins.Remove(toRemove)) { if (SpentCoins.Remove(toRemove)) { // Clusters.Remove(toRemove); } } } InvalidateSnapshot = true; return(coinsToRemove); } }