コード例 #1
0
        public async Task SyncBlocks(IEnumerable <Block> blocks)
        {
            if (HasBiggerWeigth(blocks))
            {
                var newBlockchain = _factory.CreateBlockchain();

                // Skipping Genesis block.
                foreach (var block in blocks.Skip(1))
                {
                    if (!newBlockchain.TryAddBlock(block))
                    {
                        return;
                    }
                }

                foreach (var pendingTransaction in _blockchainInstance.Blockchain.GetPending())
                {
                    newBlockchain.AddPending(pendingTransaction);
                }

                _blockchainInstance.Blockchain = newBlockchain;
                var notifyObject = new ChainNotify(blocks);
                await _mediator.Publish(notifyObject);
            }
        }
コード例 #2
0
 public BlockchainInstanceHolder(IBlockchainFactory blockchainFactory)
 {
     Blockchain = blockchainFactory.CreateBlockchain();
 }