コード例 #1
0
        public void GetBlock(byte[] data)
        {
            try
            {
                string msgdata  = Encoding.Default.GetString(data);
                var    datamine = Serialyze.UnserializeDataMine(msgdata);

                this.BlockToMine = null;
                this.difficulty  = datamine.difficulty;
                if (datamine.block != null)
                {
                    this.BlockToMine = new Block(datamine.block.Index, datamine.block.Timestamp, datamine.block.Data, datamine.block.PreviousHash);
                    this.log.Write("[CM] Block received");
                    Console.WriteLine("[CM] Block received");
                }
            }
            catch
            {
                return;
            }
        }
コード例 #2
0
        private bool AnalyzeMine(byte[] data)
        {
            DataMine dataMine;

            try
            {
                dataMine = Serialyze.UnserializeDataMine(Encoding.Default.GetString(data));
            }
            catch (Exception e)
            {
                return(false);
            }

            //Console.WriteLine("[SM] Analyse bloc mined");
            if (dataMine == null)
            {
                return(false);
            }

            if (dataMine.block == null)
            {
                return(false);
            }

            if (dataMine.block.Data == null)
            {
                return(false);
            }
            if (this.Coin.BlockToMines[0].Index != dataMine.block.Index)
            {
                return(false);
            }

            if (this.Coin.BlockToMines[0].Timestamp != dataMine.block.Timestamp)
            {
                return(false);
            }

            try
            {
                for (int i = 0; i < Block.nb_trans; i++)
                {
                    if (this.Coin.BlockToMines[0].Data[i].Amount != dataMine.block.Data[i].Amount)
                    {
                        return(false);
                    }

                    if (this.Coin.BlockToMines[0].Data[i].FromAddress != dataMine.block.Data[i].FromAddress)
                    {
                        return(false);
                    }

                    if (this.Coin.BlockToMines[0].Data[i].ToAddress != dataMine.block.Data[i].ToAddress)
                    {
                        return(false);
                    }

                    if (this.Coin.BlockToMines[0].Data[i].Timestamp != dataMine.block.Data[i].Timestamp)
                    {
                        return(false);
                    }
                }
            }
            catch (Exception e)
            {
                return(false);
            }


            if (this.Coin.BlockToMines[0].PreviousHash != dataMine.block.PreviousHash)
            {
                return(false);
            }

            return(this.Coin.NetworkMinePendingTransaction(dataMine.address, dataMine.block, dataMine.timemining));
        }