public static void TestMethod() { Miners.ConnectToNetwork(); //Data data = new Data(); //data.ParentID.Add(12); //data.Product = new Product(); //data.Product.Features.Add(new Feature(DateTime.Now, "buğday asdsa")); //BlockChain.ReceiveNewBlock(data); }
public static void MainMethod() { string title = @" _____ _ _____ _ _ / ____| | | / ____| | (_) | (___ _ _ _ __ _ __ | |_ _| | | |__ __ _ _ _ __ \___ \| | | | '_ \| '_ \| | | | | | | '_ \ / _` | | '_ \ ____) | |_| | |_) | |_) | | |_| | |____| | | | (_| | | | | | |_____/ \__,_| .__/| .__/|_|\__, |\_____|_| |_|\__,_|_|_| |_| | | | | __/ | |_| |_| |___/ "; Console.WriteLine(title); Console.WriteLine( "Command List: \n" + "connect [ip] --> Connect to website and join other miners. [ip] is webserver's ip.\n" + "print [id] --> Print block which given id\n" + "exit --> Leave the network\n" + "quit --> exit application\n"); while (true) { string command = Console.ReadLine(); command = command.ToLower(); if (command.StartsWith("connect")) { if (command.Length > 8) { command = command.Substring(8); } else { Console.WriteLine("Please enter the ip"); continue; } if (!command.Contains(".")) { Console.WriteLine("Please enter the ip"); continue; } TCP.WebServerIp = command; Miners.ConnectToNetwork(); continue; } if (command.StartsWith("print")) { command = command.Substring(6); Console.WriteLine(BlockChain.GetBlock(int.Parse(command)).ToString()); break; } if (command.StartsWith("chain")) { Console.WriteLine("\n--------BLOCKCHAIN--------"); BlockChain.GetChain().ForEach(b => Console.WriteLine(b.ToString())); Console.WriteLine("--------BLOCKCHAIN--------\n"); } if (command.StartsWith("get")) { if (BlockChain.GetChain().Count == 1) { TCP.Send(Miners.minerIPs[0], "getChain"); } else { Console.WriteLine("Already have chain"); } } if (command.StartsWith("read")) { string path = command.Substring(5); string st = File.ReadAllText(path); object ret = TCP.JsonDeserialize(st); var obj = TCP.Cast(ret, new { list = new List <Block>() }); BlockChain.SetChain(obj.list); TCP.SendWebServer("addMeNow"); } if (command.StartsWith("write")) { string path = command.Substring(6); string st = TCP.JsonSerialize(new { list = BlockChain.GetChain() }); File.WriteAllText(path, st); } if (command.Equals("exit")) { Console.WriteLine("Leaving network...\nPlease press a key"); Console.ReadKey(); Console.Clear(); MainMethod(); break; } if (command.Equals("quit")) { Environment.Exit(0); } } }