Exemplo n.º 1
0
        private void OnNewBlock(object obj)
        {
            var block = (Block)obj;

            if (_blockVerifier.Verify(block))
            {
                SaveBlock(block);
                _logger.Log($"Got new verified block {block.Body.Id}");
                _mappingService.Broadcast(block);

                if (block.Body.LastBlockId == Info.EndOfLongestChain)
                {
                    Info.EndOfLongestChain = block.Body.Id;
                    Info.Height++;
                }
                else
                {
                    CalculateLongestChain();
                }
                Info.EditTime = DateTime.UtcNow;
                SaveLocalInfo();
                ClearMemPool(block);
                _minerService.TryRestartingWorkers();
                _eventManager.PassNewTrigger(block, EventTypes.EventType.NewVerifiedBlock);
            }
            else
            {
                _logger.Log($"Got new shit block {block.Body.Id}");
                ClearMemPool(block);
            }
            Task.Run(delegate
            {
                Task.Delay(2000).Wait();
                if (_minerService.MemPool.Count == 0 && Configurations.Config.CM)
                {
                    _minerService.MemPool.Add(_walletService.AssembleTransaction(_walletService.Address, 1, "getme"));
                    _minerService.TryRestartingWorkers();
                }
            });
        }
Exemplo n.º 2
0
        public void OnNewTransaction(object obj)
        {
            var trans = (Transaction)obj;

            if (Verify(trans))
            {
                _logger.Log($"New transaction {trans.Body.TransactionId}");
                if (!_minerService.HasTransactionInMemPool(trans.Body.TransactionId))
                {
                    _minerService.MemPool.Add(trans);
                    _minerService.TryRestartingWorkers();
                    _mappingService.Broadcast(trans);
                }
                else
                {
                    _logger.Log("Already had transaction received", 1);
                }
            }
            else
            {
                _logger.Log($"Bad new transaction {trans.Body.TransactionId}");
            }
        }