static void RunBlockchainTransaction() { var startTime = DateTime.Now; Blockchain phillyCoin = new Blockchain(); phillyCoin.CreateTransaction(new Transaction("Henry", "MaHesh", 10)); phillyCoin.ProcessPendingTransactions("Bill"); //Console.WriteLine(JsonConvert.SerializeObject(phillyCoin, Formatting.Indented)); phillyCoin.CreateTransaction(new Transaction("MaHesh", "Henry", 5)); phillyCoin.CreateTransaction(new Transaction("MaHesh", "Henry", 5)); phillyCoin.ProcessPendingTransactions("Bill"); phillyCoin.CreateTransaction(new Transaction("João", "Henry", 5)); phillyCoin.ProcessPendingTransactions("Bill"); var endTime = DateTime.Now; Console.WriteLine($"Duration: {endTime - startTime}"); Console.WriteLine("========================="); Console.WriteLine($"Henry' balance: {phillyCoin.GetBalance("Henry")}"); Console.WriteLine($"MaHesh' balance: {phillyCoin.GetBalance("MaHesh")}"); Console.WriteLine($"Bill' balance: {phillyCoin.GetBalance("Bill")}"); Console.WriteLine("========================="); Console.WriteLine($"phillyCoin"); Console.WriteLine(JsonConvert.SerializeObject(phillyCoin, Formatting.Indented)); }
static void Main(string[] args) { try { PhillyCoin.InitializeChain(); if (args.Length >= 1) { Port = int.Parse(args[0]); } if (args.Length >= 2) { name = args[1]; } if (Port > 0) { Console.Write("IP Server: "); string ipServer = Console.ReadLine(); Server = new P2PServer(); Server.Start(ipServer); } if (name != "Unkown") { Console.WriteLine($"Current user is {name}"); } Console.WriteLine("========================="); Console.WriteLine("1. Connect to a server"); Console.WriteLine("2. Add a transaction"); Console.WriteLine("3. Display Blockchain"); Console.WriteLine("4. Exit"); Console.WriteLine("========================="); int selection = 0; while (selection != 4) { switch (selection) { case 1: Console.WriteLine("Please enter the server URL"); string serverURL = Console.ReadLine(); Client.Connect($"{serverURL}/Blockchain"); break; case 2: Console.WriteLine("Please enter the receiver name"); string receiverName = Console.ReadLine(); Console.WriteLine("Please enter the amount"); string amount = Console.ReadLine(); PhillyCoin.CreateTransaction(new Transaction(name, receiverName, int.Parse(amount))); PhillyCoin.ProcessPendingTransactions(name); Client.Broadcast(JsonConvert.SerializeObject(PhillyCoin)); break; case 3: Console.WriteLine("Blockchain"); Console.WriteLine(JsonConvert.SerializeObject(PhillyCoin, Formatting.Indented)); break; } Console.WriteLine("Please select an action"); string action = Console.ReadLine(); selection = int.Parse(action); } Client.Close(); } catch (Exception e) { Console.WriteLine(e.Message); } }