示例#1
0
        public bool ResolveConflicts()
        {
            var          neighbours = this.nodes;
            List <Block> newChain   = null;

            var maxLenght = this.chain.Count;

            foreach (var node in neighbours)
            {
                List <Block> chain;

                var ip   = node.Address.Split(' ')[0];
                var port = int.Parse(node.Address.Split(' ')[1]);

                IPAddress address = IPAddress.Parse(ip);

                chain = AsynchronousClient.GetBlockchain(address, port);

                var length = chain.Count;

                if (length > maxLenght && this.ValidChain(chain))
                {
                    maxLenght = length;
                    newChain  = chain;
                }
            }

            if (newChain != null)
            {
                this.chain = newChain;

                return(true);
            }

            return(false);
        }