public async Task Handle(BlockMessage message, IPeer sender) { var block = message.Payload; await _blockProcessor.AddBlock(block); _broadcaster.Broadcast(message, sender); }
public async Task InitializeBlockchain() { if (Interlocked.Exchange(ref _initialized, 1) != 0) { return; } var blockHeight = await _blockRepository.GetTotalBlockHeight(); var blockHeaderHeight = await _blockRepository.GetTotalBlockHeaderHeight(); _blockchainContext.CurrentBlock = await _blockRepository.GetBlock(blockHeight); _blockchainContext.LastBlockHeader = await _blockRepository.GetBlockHeader(blockHeaderHeight); _blockProcessor.Run(); if (_blockchainContext.CurrentBlock == null || _blockchainContext.LastBlockHeader == null) { await _blockProcessor.AddBlock(_genesisBuilder.Build()); } }
/// <inheritdoc /> public override async Task Handle(BlockMessage message, IPeer sender) { var block = message.Payload; if (block.Hash == null) { _blockOperationsManager.Sign(block); } else { if (!_blockOperationsManager.Verify(block)) { _logger.LogWarning($"Block {block.Hash} with Index {block.Index} verification fail."); return; } } //_logger.LogInformation($"Broadcasting block {block.Hash} with Index {block.Index}."); //_broadcaster.Broadcast(message, sender); await _blockProcessor.AddBlock(block); }