Beispiel #1
0
 private void BlockValidation(object sender, EventArgs e)
 {
     if (File.Exists(@Utility.DATAPATH))
     {
         _StatusTag.Text = "VALID CHAIN";
         string  ___BLOCKDATA = File.ReadAllText(@Utility.DATAPATH);
         JObject BLOCKCHAIN = JObject.Parse(___BLOCKDATA);
         JArray  items = (JArray)BLOCKCHAIN["blocks"];
         string  Currenthash, BlockHash, PrevHash;
         if (items.Count > 1)
         {
             for (int i = 0; i < items.Count - 1; i++)
             {
                 BlockHash = (string)items[i]["blockhash"];
                 PrevHash  = (string)items[i + 1]["previoushash"];
                 if (!BlocksChain.Validation(PrevHash, BlockHash))
                 {
                     Chainflag               = false;
                     _StatusTag.ForeColor    = Color.Red;
                     _StatusTag.Text         = "CHAIN ERROR";
                     _ChainErrorMessage.Text = "Chain error at block :" + (i + 1).ToString();
                     Thread _syncthread = new Thread(SyncRequest);
                     _syncthread.Start();
                     break;
                 }
                 else
                 {
                     Chainflag = true;
                 }
             }
             if (Chainflag)
             {
                 for (int y = 1; y < items.Count; y++)
                 {
                     Currenthash = BlocksChain.GenerateBlockHash((string)items[y]["votehash"], (string)items[y]["timestamp"], (string)items[y]["previoushash"], Configuration.SaltValue);
                     if (BlocksChain.BlockValidation(Currenthash, (string)items[y]["blockhash"]))
                     {
                         _StatusTag.ForeColor    = Color.Red;
                         _ChainErrorMessage.Text = "Block data error at block :" + (y + 1).ToString();
                         _StatusTag.Text         = "BLOCK DATA ERROR";
                         Dataflag = false;
                         Thread _syncthread = new Thread(SyncRequest);
                         _syncthread.Start();
                         break;
                     }
                     else
                     {
                         Dataflag = true;
                     }
                 }
             }
             if (Chainflag && Dataflag)
             {
                 _StatusTag.Text         = "Valid Blockchain";
                 _StatusTag.ForeColor    = Color.Orchid;
                 _ChainErrorMessage.Text = "";
             }
         }
         else
         {
             _StatusTag.Text = "EMPTY CHAIN";
         }
     }
     else
     {
         _StatusTag.Text = "Not Connected";
     }
 }
Beispiel #2
0
        private void CalculateResult()
        {
            ResultText.Text = "";
            if (File.Exists(@Utility.DATAPATH))
            {
                string  ___BLOCKDATA = File.ReadAllText(@Utility.DATAPATH);
                JObject BLOCKCHAIN = JObject.Parse(___BLOCKDATA);
                JArray  items = (JArray)BLOCKCHAIN["blocks"];
                string  Currenthash, BlockHash, PrevHash;
                if (items.Count > 1)
                {
                    for (int i = 0; i < items.Count - 1; i++)
                    {
                        BlockHash = (string)items[i]["blockhash"];
                        PrevHash  = (string)items[i + 1]["previoushash"];
                        if (!BlocksChain.Validation(PrevHash, BlockHash))
                        {
                            Chainflag        = false;
                            ResultText.Text += "\r\n------------------------------------";
                            ResultText.Text += "\r\nCHAIN ERROR AT BLOCK : " + (i + 1).ToString();
                            ResultText.Text += "\r\n------------------------------------";
                            break;
                        }
                        else
                        {
                            Chainflag = true;
                        }
                    }
                    if (Chainflag)
                    {
                        for (int y = 1; y < items.Count; y++)
                        {
                            Currenthash = BlocksChain.GenerateBlockHash((string)items[y]["votehash"], (string)items[y]["timestamp"], (string)items[y]["previoushash"], Configuration.SaltValue);
                            if (BlocksChain.BlockValidation(Currenthash, (string)items[y]["blockhash"]))
                            {
                                ResultText.Text += "\r\n------------------------------------";
                                ResultText.Text += "\r\nCORRUPT DATA IN BLOCK : " + (y + 1).ToString();
                                ResultText.Text += "\r\n------------------------------------";
                                Dataflag         = false;
                                break;
                            }
                            else
                            {
                                Dataflag = true;
                            }
                        }
                    }
                    if (Chainflag && Dataflag)
                    {
                        ResultText.AppendText("\r\n-------------------------------------");
                        ResultText.AppendText("\r\nVALID BLOCK CHAIN -- COMPUTING RESULT");
                        ResultText.AppendText("\r\n-------------------------------------");
                    }

                    for (int z = 0; z < items.Count; z++)
                    {
                        for (int ID = 70001; ID <= 70005; ID++)
                        {
                            Thread.Sleep(500);
                            for (int UID = 10001; UID <= 10005; UID++)
                            {
                                //ResultText.Text += "\r\n";
                                if ((string)items[z]["votehash"] == SILICON64.GenerateHash(ID.ToString() + UID.ToString()))
                                {
                                    Console.Beep(700, 500);
                                    ResultText.AppendText("\r\n\r\nBLOCK - [" + (z + 1).ToString() + "]\r\n");
                                    ResultText.AppendText("\r\nVOTE HASH  >>" + (string)items[z]["votehash"]);
                                    ResultText.AppendText("\r\nBLOCK HASH >>" + (string)items[z]["blockhash"]);
                                    if (ID == 70001)
                                    {
                                        A++;
                                    }
                                    if (ID == 70002)
                                    {
                                        B++;
                                    }
                                    if (ID == 70003)
                                    {
                                        C++;
                                    }
                                    if (ID == 70004)
                                    {
                                        D++;
                                    }
                                    if (ID == 70005)
                                    {
                                        E++;
                                    }
                                    Thread.Sleep(1500);
                                    continue;
                                }
                            }
                        }
                    }

                    ResultText.Text += "\r\n\r\n";
                    Console.Beep(500, 2500);
                    ResultText.Text += "\r\n70001	ALPHA  : "+ A.ToString();
                    ResultText.Text += "\r\n70002	BETA   : "+ B.ToString();
                    ResultText.Text += "\r\n70003	DELTA  : "+ C.ToString();
                    ResultText.Text += "\r\n70004	GAMMA  : "+ D.ToString();
                    ResultText.Text += "\r\n70005	ECHO   : "+ E.ToString();
                }
                else
                {
                    ResultText.Text = "EMPTY CHAIN";
                }
            }
            else
            {
                ResultText.Text = "Blocks not found!!";
            }
        }