static void InterpretBatchCommand(string cmd, BlockChainClassLib.CommandProcessor cmdProc) { string[] cmdArgs = cmd.ToLower().Split(' '); switch (cmdArgs[0]) { case "transfer": Transfer(cmdArgs, cmdProc); break; case "history": string txList = cmdProc.history(cmdArgs[1]); Console.Write(txList); break; case "balance": cmdProc.Wallet_Balance(); break; case "test": Test(cmdArgs, cmdProc); break; case "exit": exit = true; break; } }
//command line program entry point public static void Main(string[] args) { //retrieve the BlockChain server host address and port from the app.config file string host = System.Configuration.ConfigurationManager.AppSettings["host"]; string port = System.Configuration.ConfigurationManager.AppSettings["port"]; //Get cryptoProvider library to load (dynamically) from the app.config file string cryptoProvider = System.Configuration.ConfigurationManager.AppSettings["cryptoProvider"]; //create an instance of the command processor in the BlockChain class library BlockChainClassLib.CommandProcessor cmdProc = new BlockChainClassLib.CommandProcessor(cryptoProvider, host, port); System.Console.WriteLine("BlockChain Client initialized"); System.Console.WriteLine(string.Format("host={0}, port={1}, CryptoProvider {2}", host, port, cryptoProvider)); System.Console.WriteLine("enter help for a list of commands"); string cmd = ""; if (args.Length > 1) { if (args[0].ToLower() == "run") { Run(args, cmdProc); } } //main command loop while (!exit) { try { string result = ""; //read command from the command line System.Console.Write("Client>"); cmd = System.Console.ReadLine().Trim().ToLower(); string[] cmdArgs = cmd.ToLower().Split(' '); switch (cmdArgs[0]) { case "help": help(); break; case "transfer": Transfer(cmdArgs, cmdProc); break; case "exit": exit = true; break; case "chain": result = cmdProc.chain(); Console.WriteLine(result); break; case "wallet": Wallet(cmdArgs, cmdProc); break; case "history": result = cmdProc.history(cmdArgs[1]); Console.Write(result); break; case "pending": result = cmdProc.PendingTransactions(); Console.Write(result); break; case "test": Test(cmdArgs, cmdProc); break; case "run": Run(cmdArgs, cmdProc); break; } } catch (Exception ex) { System.Console.WriteLine(ex); } } }