Exemple #1
0
        private async Task SendTransaction(byte[] transaction, int iteration)
        {
            string header = "new|" + iteration;

            transaction = AddOperation(header, Transactions.size_suboperation, transaction);
            transaction = AddOperation("transaction", UDPServer.operation_size, transaction);

            await server.SendGlobal(transaction);
        }
Exemple #2
0
        public async Task BlockChainActualize()
        {
            byte[] message    = new byte[0];
            string path       = filesystem.FSConfig.db_blocks_path;
            string actual     = "actualblock";
            Block  temp_block = new Block();

            byte[] temp_array = new byte[0];


            bool trigger1 = true;
            bool trigger2 = true;
            int  tring1   = 0;
            int  tring2   = 0;



            await Task.Run(async() => {
                try
                {
                    message = Encoding.UTF8.GetBytes(actual);
                    message = server.AddOperation(getlogic.request_template, UDPServer.operation_size, message);
                    getlogic.waitingforactual = true;

                    await server.SendGlobal(message);
                    await Task.Delay(5000);

                    while (trigger1)
                    {
                        path = filesystem.FSConfig.db_blocks_path + @"\" + actual;

                        if (!File.Exists(path))
                        {
                            message = Encoding.UTF8.GetBytes(actual);
                            message = server.AddOperation(getlogic.request_template, UDPServer.operation_size, message);
                            getlogic.waitingforactual = true;

                            await server.SendGlobal(message);
                            await Task.Delay(5000);
                            tring1++;
                        }
                        else
                        {
                            actual   = Encoding.UTF8.GetString(await filesystem.GetFromFileAsync(path));
                            trigger1 = false;
                            window.WriteLine("[BlockChainActualize]: actualblock file found on " + tring1 + " try");
                        }

                        if (tring1 > 2)
                        {
                            trigger1 = false;
                            trigger2 = false;
                            window.WriteLine("[BlockChainActualize]: actualblock file not found");
                        }
                    }

                    tring2 = 0;

                    while (trigger2)
                    {
                        path = filesystem.FSConfig.db_blocks_path + @"\" + actual;

                        temp_array = await SearchBlock(actual);

                        if (temp_array.Length == 0)
                        {
                            await Task.Delay(10000);
                            tring2++;
                        }
                        else
                        {
                            temp_block = BlockDeSerialize(temp_array);

                            if (actual.Length == Blocks.block_length)
                            {
                                if (temp_block.previous == Blocks.first_block)
                                {
                                    trigger2 = false;
                                    window.WriteLine("[BlockChainActualize]: Completed");
                                }
                                else
                                {
                                    actual = temp_block.previous;
                                    tring2 = 0;
                                }
                            }
                        }

                        if (tring2 > 0)
                        {
                            trigger2 = false;
                            window.WriteLine("[BlockChainActualize]: block (" + actual + ") not found");
                        }
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("Exception: " + ex.ToString());
                }
            });
        }