示例#1
0
 public UnprocessedBlockTreeWrapper(IBlockTree blockTree)
 {
     _blockTree = blockTree;
     _blockTree.NewHeadBlock          += (sender, args) => NewHeadBlock?.Invoke(sender, args);
     _blockTree.NewBestSuggestedBlock += (sender, args) => NewBestSuggestedBlock?.Invoke(sender, args);
     _blockTree.BlockAddedToMain      += (sender, args) => BlockAddedToMain?.Invoke(sender, args);
 }
示例#2
0
文件: Program.cs 项目: orousset/Block
        /// <summary>
        /// Move the Train on the network according to its current DoT, by Distance (in meter)
        /// </summary>
        /// <param name="Distance"></param>
        /// <returns> false if an issue occured, e.g. chaining breaking, true otherwise </returns>
        public bool MoveTrain(double Distance)
        {
            double RemainingDistance;

            RemainingDistance = Distance;
            Block  NewHeadBlock;
            double NewLoc;

            NewHeadBlock = BlockHead;
            NewLoc       = LocHead;

            while (RemainingDistance > 0)
            {
                if (BlockHead.Length - LocHead > RemainingDistance)
                {
                    NewLoc            = NewLoc + RemainingDistance;
                    RemainingDistance = 0;
                }
                else
                {
                    RemainingDistance = NewHeadBlock.Length - NewLoc;
                    NewLoc            = 0;
                    NewHeadBlock      = NewHeadBlock.GetNextBlock(DoT);
                    if (NewHeadBlock == null)
                    {
                        return(false);
                    }
                }
            }
            return(SetTrainLocation(NewHeadBlock, NewLoc, DoT));
        }
示例#3
0
        private void UpdateHeadBlock(Block block)
        {
            if (block.IsGenesis)
            {
                Genesis = block.Header;
            }

            Head = block.Header;
            _blockInfoDb.Set(HeadAddressInDb, Head.Hash.Bytes);
            NewHeadBlock?.Invoke(this, new BlockEventArgs(block));
            if (_dbBatchProcessed != null)
            {
                if (block.Number == _currentDbLoadBatchEnd)
                {
                    TaskCompletionSource <object> completionSource = _dbBatchProcessed;
                    _dbBatchProcessed = null;
                    completionSource.SetResult(null);
                }
            }
        }
示例#4
0
        private void UpdateHeadBlock(Block block)
        {
            if (block.IsGenesis)
            {
                Genesis = block.Header;
            }

            Head = block.Header;
            _blockDb.Set(Keccak.Zero, Rlp.Encode(Head).Bytes);
            NewHeadBlock?.Invoke(this, new BlockEventArgs(block));
            if (_dbBatchProcessed != null)
            {
                if (block.Number == _currentDbLoadBatchEnd)
                {
                    TaskCompletionSource <object> completionSoruce = _dbBatchProcessed;
                    _dbBatchProcessed = null;
                    completionSoruce.SetResult(null);
                }
            }
        }