public ICoinsView Remove(SmartCoin coin) { lock (Lock) { var coinsToRemove = DescendantOfAndSelfNoLock(coin); foreach (var toRemove in coinsToRemove) { if (Coins.Remove(toRemove)) { //Clusters.Remove(toRemove); } } InvalidateSnapshot = true; return(coinsToRemove); } }
public ICoinsView DescendantOf(SmartCoin coin) { IEnumerable <SmartCoin> Generator(SmartCoin scoin) { foreach (var child in ChildrenOf(scoin)) { foreach (var childDescendant in Generator(child)) { yield return(childDescendant); } yield return(child); } } return(new CoinsView(Generator(coin))); }
public bool TryAdd(SmartCoin coin) { var added = false; lock (Lock) { if (!SpentCoins.Contains(coin)) { added = Coins.Add(coin); coin.RegisterToHdPubKey(); if (added) { foreach (var outPoint in coin.Transaction.Transaction.Inputs.Select(x => x.PrevOut)) { var newCoinSet = new HashSet <SmartCoin> { coin }; // If we don't succeed to add a new entry to the dictionary. if (!CoinsByOutPoint.TryAdd(outPoint, newCoinSet)) { var previousCoinTxId = CoinsByOutPoint[outPoint].First().TransactionId; // Then check if we're in the same transaction as the previous coins in the dictionary are. if (coin.TransactionId == previousCoinTxId) { // If we are in the same transaction, then just add it to value set. CoinsByOutPoint[outPoint].Add(coin); } else { // If we aren't in the same transaction, then it's a conflict, so replace the old set with the new one. CoinsByOutPoint[outPoint] = newCoinSet; } } } InvalidateSnapshot = true; } } } return(added); }
public void Spend(SmartCoin spentCoin) { lock (Lock) { if (Coins.Remove(spentCoin)) { InvalidateSnapshot = true; SpentCoins.Add(spentCoin); var createdCoins = CreatedByNoLock(spentCoin.SpenderTransactionId); foreach (var newCoin in createdCoins) { if (newCoin.AnonymitySet < PrivacyLevelThreshold) { spentCoin.Clusters.Merge(newCoin.Clusters); newCoin.Clusters = spentCoin.Clusters; ClustersByScriptPubKey.AddOrReplace(newCoin.ScriptPubKey, newCoin.Clusters); } } } } }
public bool TryAdd(SmartCoin coin) { var added = false; lock (Lock) { if (!SpentCoins.Contains(coin)) { added = Coins.Add(coin); if (added) { if (ClustersByScriptPubKey.TryGetValue(coin.ScriptPubKey, out var cluster)) { coin.Clusters = cluster; } InvalidateSnapshot = true; } } } return(added); }
public ICoinsView DescendantOfAndSelf(SmartCoin coin) => AsCoinsView().DescendantOfAndSelf(coin);
private ICoinsView DescendantOfAndSelfNoLock(SmartCoin coin) => AsCoinsViewNoLock().DescendantOfAndSelf(coin);
public ICoinsView ChildrenOf(SmartCoin coin) => AsCoinsView().ChildrenOf(coin);
public ICoinsView DescendantOfAndSelf(SmartCoin coin) => new CoinsView(DescendantOf(coin) .Concat(new[] { coin }));
public ICoinsView ChildrenOf(SmartCoin coin) => new CoinsView(Coins.Where(x => x.TransactionId == coin.SpenderTransactionId));