Esempio n. 1
0
        static void Main(string[] args)
        {
            var server = new P2PServer();
            var client = new P2PClient();
            var resp   = Console.ReadLine();

            if (Uri.IsWellFormedUriString(resp, UriKind.Absolute))
            {
                blockchain.AddGenesisBlock();
                client.Connect(resp);
            }
            else if (int.TryParse(resp, out var port))
            {
                server.Start(port);
            }
            Console.ReadLine();
        }
        static void Main()
        {
            //if (Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName).Count() <= 3)
            //{
            //    Process.Start("Tesis_Blockchain_VoteSystem.exe");
            //}
            VoteChain.InitializeChain();
            if (Server == null)
            {
                Server = new P2PServer();
                Server.Start(Program.Port);
            }
            else
            {
                Client.Connect(Server.url + "/BlockChain");
            }

            Application.SetHighDpiMode(HighDpiMode.SystemAware);
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Login());
        }
Esempio n. 3
0
        static void TestBlockChain(string[] args)
        {
            if (args.Length >= 1)
            {
                Port = int.Parse(args[0]);
            }
            if (args.Length >= 2)
            {
                name = args[1];
            }

            if (Port > 0)
            {
                Server = new P2PServer(ipAddress, Port, PhillyCoin);
                Server.Start();
                Console.WriteLine($"P2P server is running on {ipAddress}:{Port}......");
            }
            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 = new P2PClient(PhillyCoin);
                    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 = new P2PClient(PhillyCoin);
                    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();
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            P2PClient client = new P2PClient()
            {
                Signer = new ECDSASignatureProvider()
            };

            #region Connection.

            client.Connect("ws://" + Dns.GetHostName() + ":8900/simplecoin");

            Thread.Sleep(4000);

            #endregion

            #region Block sending.

            Block block = new Block(
                new byte[] { randomByte(), randomByte(), randomByte() },
                new byte[] { randomByte(), randomByte(), randomByte() },
                new Transaction[]
            {
                new Transaction
                (
                    new byte[] { randomByte(), randomByte(), randomByte() },
                    new byte[] { randomByte(), randomByte(), randomByte() },
                    random.Next(1, 100),
                    new TransactionHashFactory()
                ),
                new Transaction
                (
                    new byte[] { randomByte(), randomByte(), randomByte() },
                    new byte[] { randomByte(), randomByte(), randomByte() },
                    random.Next(1, 100),
                    new TransactionHashFactory()
                )
            },
                new KeccakFactory(512, 64)
                );

            client.SendBlock(block);

            Thread.Sleep(1000);

            #endregion

            #region Transaction sending.

            Transaction transaction = new Transaction
                                      (
                new byte[] { randomByte(), randomByte(), randomByte() },
                new byte[] { randomByte(), randomByte(), randomByte() },
                random.Next(1, 100),
                new TransactionHashFactory()
                                      );

            client.SendTransaction(transaction);

            Thread.Sleep(1000);

            #endregion

            client.Disconnect();

            client.Connect("ws://" + Dns.GetHostName() + ":8900/simplecoin");

            Thread.Sleep(1000);

            client.SendTransaction(transaction);
        }
Esempio n. 5
0
 public void TestServer(Int32 _port)
 {
     P2PClient.Connect($"ws://127.0.0.1:{_port}/DCL_CORE");
 }