static void Main(string[] args) { ourblockchain.InitializeChain(); if (args.Length >= 1) { Port = int.Parse(args[0]); } if (args.Length >= 2) { name = args[1]; } if (Port > 0) { Server = new P2PServer(); Server.Start(); } if (name != "Unknown") { Console.WriteLine($"Su anki Kullanıcı:{name}"); } Console.WriteLine("========================="); Console.WriteLine("1. Server a Baglan"); Console.WriteLine("2. Transaction Ekle"); Console.WriteLine("3. Blockchain i Goster"); Console.WriteLine("4. Cikis"); Console.WriteLine("========================="); int selection = 0; while (selection != 4) { switch (selection) { case 1: Console.WriteLine("Lütfen Server URL ini Girin:"); string serverURL = Console.ReadLine(); Client.Connect($"{serverURL}/Blockchain"); break; case 2: Console.WriteLine("Lütfen Alici adini Girin"); string receiverName = Console.ReadLine(); Console.WriteLine("Miktari girin"); string amount = Console.ReadLine(); ourblockchain.CreateTransaction(new Transaction(name, receiverName, int.Parse(amount))); ourblockchain.ProcessPendingTransactions(name); Client.Broadcast(JsonConvert.SerializeObject(ourblockchain)); break; case 3: Console.WriteLine("Blockchain"); Console.WriteLine(JsonConvert.SerializeObject(ourblockchain, Formatting.Indented)); break; } Console.WriteLine("Lütfen bir seçenek seçin"); string action = Console.ReadLine(); selection = int.Parse(action); } Client.Close(); }
static void Main(string[] args) { DateTime startTime = DateTime.Now; ourBlockchain.InitializeChain(); if (args.Length >= 1) { Port = int.Parse(args[0]); } if (args.Length >= 2) { name = (args[1]); } if (args.Length > 0) { Server = new P2PServer(); Server.Start(); } if (name != "Unknown") { Console.WriteLine($"Current User: {name}"); } Console.WriteLine("========================="); Console.WriteLine("1. Connect to Server"); Console.WriteLine("2. Add Transaction"); Console.WriteLine("3. Show Blockchain"); Console.WriteLine("4. Quit"); Console.WriteLine("========================="); int selection = 0; while (selection != 4) { switch (selection) { case 1: Console.WriteLine("Please enter a server url: "); string serverURL = Console.ReadLine(); Client.Connect($"{serverURL}/Blockchain"); break; case 2: Console.WriteLine("Please enter a receiver name: "); string receiverName = Console.ReadLine(); Console.WriteLine("Enter Amount"); string amount = Console.ReadLine(); ourBlockchain.CreateTransaction(new Transaction(name, receiverName, int.Parse(amount))); ourBlockchain.ProcessPendingTransaction(name); Client.Broadcast(JsonConvert.SerializeObject(ourBlockchain)); break; case 3: Console.WriteLine("Blockchain"); Console.WriteLine(JsonConvert.SerializeObject(ourBlockchain, Formatting.Indented)); break; } Console.WriteLine("Choose the options."); string action = Console.ReadLine(); selection = int.Parse(action); } Client.Close(); Console.WriteLine(JsonConvert.SerializeObject(ourBlockchain, Formatting.Indented)); DateTime finishTime = DateTime.Now; Console.WriteLine("Creating time: " + (finishTime - startTime)); //ourBlockchain.AddBlock(new Block(DateTime.Now, null, "{sender:Berk,receiver:Mert,amount:5}")); //ourBlockchain.AddBlock(new Block(DateTime.Now, null, "{sender:Berk,receiver:Ahmet,amount:5}")); //ourBlockchain.AddBlock(new Block(DateTime.Now, null, "{sender:Berk,receiver:Mehmet,amount:5}")); //ourBlockchain.CreateTransaction(new Transaction("Romeo", "Juliet",5)); //ourBlockchain.ProcessPendingTransaction("Berk"); //ourBlockchain.CreateTransaction(new Transaction("Juliet", "Romeo", 15)); //ourBlockchain.CreateTransaction(new Transaction("Juliet", "Romeo", 25)); //ourBlockchain.ProcessPendingTransaction("Berk"); //Console.WriteLine("Berk balance: "+ ourBlockchain.GetBalance("Berk")); //Console.WriteLine("Romeo balance: "+ ourBlockchain.GetBalance("Romeo")); //Console.WriteLine("Juliet balance: "+ ourBlockchain.GetBalance("Juliet")); //Console.WriteLine("Is Valid: "+ ourBlockchain.IsValid()); //console.writeline("change data..."); //ourblockchain.chain[1].data = "{sender:changedberk,receiver:mesut,amount:512}"; //console.writeline("changed data is valid: " + ourblockchain.isvalid()); //Console.WriteLine("Update Hash..."); //ourBlockchain.Chain[1].Hash = ourBlockchain.Chain[1].CalculateHash(); //Console.WriteLine("Updated Hash Is Valid: " + ourBlockchain.IsValid()); //ourBlockchain.Chain[2].PreviousHash = ourBlockchain.Chain[1].Hash; //ourBlockchain.Chain[2].Hash = ourBlockchain.Chain[2].CalculateHash(); //ourBlockchain.Chain[3].PreviousHash = ourBlockchain.Chain[2].Hash; //ourBlockchain.Chain[3].Hash = ourBlockchain.Chain[3].CalculateHash(); //Console.WriteLine("Changed All Chain Hash Is Valid: "+ourBlockchain.IsValid()); }