Ejemplo n.º 1
0
        private async void syncBlockchainsThread()
        {
            while (IsSyncing)
            {
                var lastBlock = _blockChain.LastBlock();
                if (lastBlock != null)
                {
                    var localBlockchainHash = _blockChain.BlockchainHash(lastBlock.Height);
                    var notSynnchronChains  = new List <NodeConnection>();
                    foreach (var connection in _connections.ToList())
                    {
                        var blockchainHash = await connection.BlockchainHash(lastBlock.Height);

                        if (blockchainHash != localBlockchainHash)
                        {
                            notSynnchronChains.Add(connection);
                            break;
                        }
                    }
                    if (notSynnchronChains.Count > 0)
                    {
                        IsSynced            = false;
                        _isBlockchainSynced = false;
                        syncBlockchains(notSynnchronChains, lastBlock);
                    }
                    else
                    {
                        _isBlockchainSynced = true;
                        for (int i = 0; i < 20; i++)
                        {
                            await Task.Delay(1000);

                            if (!IsSyncing)
                            {
                                break;
                            }
                        }
                    }
                }
                else
                {
                    _isBlockchainSynced = true;
                }
            }
        }