示例#1
0
 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);
     }
 }
示例#2
0
        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)));
        }
示例#3
0
        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);
        }
示例#4
0
 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);
                 }
             }
         }
     }
 }
示例#5
0
        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);
        }
示例#6
0
 public ICoinsView DescendantOfAndSelf(SmartCoin coin) => AsCoinsView().DescendantOfAndSelf(coin);
示例#7
0
 private ICoinsView DescendantOfAndSelfNoLock(SmartCoin coin) => AsCoinsViewNoLock().DescendantOfAndSelf(coin);
示例#8
0
 public ICoinsView ChildrenOf(SmartCoin coin) => AsCoinsView().ChildrenOf(coin);
示例#9
0
 public ICoinsView DescendantOfAndSelf(SmartCoin coin) => new CoinsView(DescendantOf(coin)
                                                                        .Concat(new[]
 {
     coin
 }));
示例#10
0
 public ICoinsView ChildrenOf(SmartCoin coin) => new CoinsView(Coins.Where(x => x.TransactionId == coin.SpenderTransactionId));