コード例 #1
0
        private void AddNewBlock(Block newBlock)
        {
            try
            {
                _nextBlockValidator.Validate(_index.Blocks, newBlock);
                _index = _index.Add(newBlock);
            }
            catch (BlockDeclinedException ex)
            {
                Log("Block {0} was declieds: {1}", newBlock, ex.Message);
                return;
            }
            catch (Exception ex)
            {
                Log("Block {0} was ignored: {1}", newBlock, ex);
                return;
            }

            Log("Received new block {0}", newBlock);

            UserIndex userIndex;

            if (_index.Users.AllUsers.TryGetValue(User, out userIndex))
            {
                _lastCommitedTransaction = userIndex.LastTransaction;
            }
        }
コード例 #2
0
        public NodeState Add(Block nextBlock)
        {
            var newNodeIndex           = NodeIndex.Add(nextBlock);
            var includedTransactions   = nextBlock.Transactions.Select(t => t.Signature).ToHashSet();
            var notIncludedTransactios = OngoingBlock.Transactions.Where(t => !includedTransactions.Contains(t.Signature)).ToArray();
            var newOngoingBlock        = new OngoingBlock(nextBlock.Index + 1, OngoingBlock.Node, nextBlock.Signature, notIncludedTransactios);

            return(new NodeState(newNodeIndex, newOngoingBlock));
        }