Example #1
0
        static void Main(string[] args)
        {
            Logger = new Logger()
            {
                MinLogLevelToDisplay = Configurations.Config.MinLogLevelToDisplay,
                MinLogLevelToSave    = Configurations.Config.MinLogLevelToSave
            };
            Services.Services.RegisterSingeleton(typeof(ILogger), Logger);

            LoadCommandLineArgs(args);

            Services.Services.RegisterSingeleton(typeof(IWalletService), new WalletService());

            Server = new P2PServer();
            Services.Services.RegisterSingeleton(typeof(IP2PServer), Server);
            Services.Services.RegisterSingeleton(typeof(IMappingService), new MappingService());
            Server.Start();
            Logger.Log("Starting up node...");

            if (true)
            {
                var mck = new MockClient();
                mck.MockTest();
            }

            Console.ReadLine();
        }
Example #2
0
        static void Main(string[] args)
        {
            ConsoleHelper.WriteLine("输入s启动服务器");

            var input = ConsoleHelper.ReadLine();

            if (string.IsNullOrEmpty(input) || input.ToLower() != "s")
            {
                ConsoleHelper.WriteLine("输入服务器地址,例如:180.122.325.21:39654");

                var ipPort = ConsoleHelper.ReadLine();

                Peer peer = new Peer(ipPort);
                peer.OnConnected += Peer_OnConnected;
                peer.OnMessage   += Peer_OnMessage;


                ConsoleHelper.WriteLine("输入PeerB地址,例如:180.122.325.21:21541");

                var pIPPort = ConsoleHelper.ReadLine();

                peer.RequestP2P(pIPPort);
            }
            else
            {
                P2PServer p2pServer = new P2PServer();
                p2pServer.Start();
                ConsoleHelper.WriteLine("回车关闭测试");
            }

            ConsoleHelper.ReadLine();
        }
Example #3
0
 /// <summary>
 /// Entry point for our programme
 ///
 /// (Business logic, code behind, models...
 /// ...whatever you kids are calling it these days)
 /// </summary>
 public Main()
 {
     server = new P2PServer(1000);
     client = new P2PClient();
     server.OnConnectionSuccessful += SetClientFromServer;
     lewCoins = new BlockChainObj(client);
     Task serverConnection = Task.Run(() => server.Start());
 }
Example #4
0
        static void Main(string[] args)
        {
            P2PServer server = new P2PServer(
                hostName: Dns.GetHostName(),
                port: 8900);

            server.OnBlockAccepted       += (sender, eventArgs) => Console.WriteLine($"Accepted block:\n{JsonConvert.SerializeObject(eventArgs.Block, Formatting.Indented)}\n");
            server.OnTransactionAccepted += (sender, eventArgs) => Console.WriteLine($"Accepted transaction:\n{JsonConvert.SerializeObject(eventArgs.Transaction, Formatting.Indented)}\n");

            server.Start();

            Console.ReadKey();

            server.Stop();
        }
Example #5
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());
        }
Example #7
0
        static void Main(string[] args)
        {
            GhostCoin.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 != "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();
                    GhostCoin.CreateTransaction(new Transaction(name, receiverName, int.Parse(amount)));
                    GhostCoin.ProcessPendingTransactions(name);
                    Client.Broadcast(JsonConvert.SerializeObject(GhostCoin));
                    break;

                case 3:
                    Console.WriteLine("Blockchain");
                    Console.WriteLine(JsonConvert.SerializeObject(GhostCoin, Formatting.Indented));
                    break;
                }

                Console.WriteLine("Please select an action");
                string action = Console.ReadLine();
                selection = int.Parse(action);
            }

            Client.Close();
        }