public MainForm() { InitializeComponent(); var pipeId = ProcessPipeHelper.GetCurrentPipeId(); blockchain = Blockchain.CreateNew(); communicator = new Communicator( new PipeServer <List <Block> >(pipeId), new PipeClientFactory <List <Block> >()) { Blockchain = blockchain }; communicator .ConnectTo(ProcessPipeHelper .GetNeighborPipesIds()); senderTextBox.Text = userAccount = AskForAccount(true); UpdateBlocksList(); UpdateTransactionsList(); UpdateUserAmount(); blockchain.BlockchainReplaced += (s, a) => { UpdateBlocksList(); UpdateTransactionsList(); UpdateUserAmount(); }; }
private static void Main(string[] args) { SetConsoleCtrlHandler(arg => { if (arg == 2) { communicator.Close(); } return(false); }, true); var currentPipeId = ProcessPipeHelper.GetCurrentPipeId(); Console.Title = currentPipeId; communicator = new Communicator( new PipeServer <List <Block> >(currentPipeId), new PipeClientFactory <List <Block> >()) { Blockchain = Blockchain.CreateNew() }; communicator.ConnectTo(ProcessPipeHelper.GetNeighborPipesIds()); AskAndSetAccount(); var active = true; while (active) { var parts = Console.ReadLine().Split(' '); if (parts.Length == 0) { continue; } switch (parts[0]) { case "exit": case "e": active = false; break; case "blocks": case "b": PrintBlockchain(); break; case "transactions": case "t": PrintCurrentTransactions(); break; case "mine": case "m": _ = MineAndPrintNewBlock(); break; case "add": case "a": ReadAndAddNewTransaction(parts.Skip(1).ToArray()); break; case "sync": case "s": SyncBlockchain(); break; case "help": case "h": PrintHelp(); break; case "amount": case "am": PrintAccountAmount(parts.Skip(1).FirstOrDefault()); break; case "save": case "sv": SaveBlockChain(parts.Skip(1).FirstOrDefault()); break; case "load": case "ld": LoadBlockChain(parts.Skip(1).FirstOrDefault()); break; case "switch": case "sw": AskAndSetAccount(parts.Skip(1).FirstOrDefault()); break; } } communicator.Close(); }