Пример #1
0
        public void BlockVerify(Block block)
        {
            lock (Chain)
            {
                Chain.Add(block);
            }

            lock (TransactionPool)
            {
                var ids = block.Transactions.Select(x => x.Id).ToArray();
                TransactionPool.RemoveTxs(ids);
            }

            lock (Utxos)
            {
                var inEntries = block.Transactions.SelectMany(x => x.Inputs);
                Utxos.RemoveAll(x =>
                                inEntries.Any(inEntry =>
                                              inEntry.OutputIndex == x.OutIndex &&
                                              inEntry.TransactionId.Equals(x.TransactionId)));
                var utxos =
                    block.Transactions
                    .Select(x => (x.Outputs, x.Id))
                    .SelectMany(x => ToTxO(x.Outputs, x.Id));

                Utxos.AddRange(utxos);
            }

            //if(Chain.Count % 100 == 0) Difficulty.CalculateNextDifficulty()

            Applied?.Invoke();
        }
Пример #2
0
        public void UpdateUtxos()
        {
            lock (Utxos)
            {
                var inEntries = Chain.SelectMany(x => x.Transactions.SelectMany(tx => tx.Inputs));
                var txO       =
                    Chain.SelectMany(x => x.Transactions)
                    .Select(x => (x.Outputs, x.Id))
                    .SelectMany((x) => ToTxO(x.Outputs, x.Id));

                var newUtxos = txO
                               .Where(x =>
                                      !inEntries.Any(input =>
                                                     input.TransactionId.Equals(x.TransactionId) &&
                                                     input.OutputIndex == x.OutIndex
                                                     )
                                      );
                Utxos.Clear();
                Utxos.AddRange(newUtxos);
            }
        }