Beispiel #1
0
        // RECEIVE P2P Blockchain
        private static void ReceiveTransaction()
        {
            while (is_Active)
            {
                var recvBuffer = udpClient.Receive(ref from);
                var message    = Encoding.UTF8.GetString(recvBuffer);

                BlockChain chain = JsonConvert.DeserializeObject <BlockChain>(message);
                if (chain.isValid() && chain.Chain.Count > yosaCoin.Chain.Count)
                {
                    List <Transaction> newTransactions = new List <Transaction>();
                    newTransactions.AddRange(chain.PendingTransactions);
                    newTransactions.AddRange(yosaCoin.PendingTransactions);

                    chain.PendingTransactions = newTransactions;
                    yosaCoin = chain;
                }
            }
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            Draw.draw_logo();

            Console.Write("Enter your username: "******"Option: ");
                int choice;
                try
                {
                    choice = int.Parse(Console.ReadLine());
                }
                catch
                {
                    Console.Write("Press ENTER to continue...");
                    Console.ReadKey();
                    Console.Clear();
                    Draw.draw_menu();
                    continue;
                }

                if (choice == 1)
                {
                    Console.WriteLine(JsonConvert.SerializeObject(yosaCoin, Formatting.Indented));
                }
                else if (choice == 2)
                {
                    // Console.Write("Enter the remote host: ");
                    // string serverhost = Console.ReadLine();
                    // Console.Write("Enter the remote port: ");
                    // int serverport = int.Parse(Console.ReadLine());
                    Console.Write("Enter Amount: ");
                    uint amount = uint.Parse(Console.ReadLine());
                    Console.Write("Enter the receiver username: "******"Coins count: ");
                    int coinscount = int.Parse(Console.ReadLine());
                    for (int i = 0; i < coinscount; i++)
                    {
                        yosaCoin.MineBlock(username);
                        SendTransaction(yosaCoin);
                    }
                }
                else if (choice == 4)
                {
                    is_Active = false;
                    break;
                }

                Console.Write("Press ENTER to continue...");
                Console.ReadKey();
                Console.Clear();
                Draw.draw_menu();
            }
        }
Beispiel #3
0
        // SEND P2P Transaction Blockchain
        private static void SendTransaction(BlockChain obj)
        {
            var data = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(obj));

            udpClient.Send(data, data.Length, BROADCASTIP, PORT);
        }