// Main wallet menu private static void ShowMainMenu() { // Show menu Console.WriteLine("Menu:"); Console.WriteLine(" 1 - Check Balance"); Console.WriteLine(" 2 - Send Transaction"); Console.WriteLine(" 3 - Export Keys"); Console.WriteLine(" 4 - Load Different Wallet"); Console.WriteLine(" 5 - Save and Exit"); // Wait for a menu selection switch (Console.ReadLine().ToLower()) { case "1": // TODO break; case "2": // TODO break; case "3": // TODO break; case "4": WalletBackend = new WalletBackend(AddressPrefix); WalletLoaded = false; break; case "5": SaveAndExit(); break; } }
CreateWallet(PrivateKeys privateKeys) { string walletFilename = GetNewWalletName(); string walletPassword = GetNewWalletPassword(); return(WalletBackend.NewWallet(walletFilename, walletPassword)); }
/* Attempts to open a wallet, and either returns the wallet, or * an Error */ private static IEither <Error, WalletBackend> OpenWallet() { string walletFilename = GetExistingWalletName(); while (true) { string walletPassword = GetWalletPassword(); var maybeWalletBackend = WalletBackend.Load( walletFilename, walletPassword ); if (maybeWalletBackend.IsLeft()) { Error err = maybeWalletBackend.Left(); /* If the password is incorrect, try again. Else, return * the error. */ if (err.errorName == "INCORRECT_PASSWORD") { ConsoleMessage.WriteLine(ConsoleColor.Red, err.errorMessage + "\n"); continue; } } return(maybeWalletBackend); } }
private static void ChangePassword(WalletBackend wallet) { Utilities.ConfirmPassword(wallet); string newPassword; while (true) { ConsoleMessage.Write(ConsoleColor.Yellow, "Enter your new password: "******"Confirm your new password: "******"Passwords do not match! Try again.\n"); continue; } break; } wallet.password = newPassword; wallet.Save(); ConsoleMessage.WriteLine(ConsoleColor.DarkGreen, "\nPassword successfully updated!"); }
CreateWallet(PrivateKey privateViewKey, string address) { string walletFilename = GetNewWalletName(); string walletPassword = GetNewWalletPassword(); return(WalletBackend.NewWallet( walletFilename, walletPassword, privateViewKey, address )); }
private static void Help(WalletBackend wallet) { if (wallet.isViewWallet) { Menu.PrintCommands(DefaultCommands.BasicViewWalletCommands()); } else { Menu.PrintCommands(DefaultCommands.BasicCommands()); } }
private static string GetPrompt(WalletBackend wallet) { int promptLength = 20; /* Remove extension if it exists */ string walletName = Path.ChangeExtension(wallet.filename, null); /* Trim to 20 chars */ walletName = string.Concat(walletName.Take(promptLength)); return($"[{Globals.ticker} {walletName}]: "); }
public static void ConfirmPassword(WalletBackend wallet) { while (true) { ConsoleMessage.Write(ConsoleColor.Yellow, "Confirm your current password: "******"Incorrect password! Try again.\n"); continue; } return; } }
public static void MainLoop(WalletBackend wallet) { /* Show the available commands */ if (wallet.isViewWallet) { PrintCommands(DefaultCommands.BasicViewWalletCommands()); } else { PrintCommands(DefaultCommands.BasicCommands()); } while (true) { string command; if (wallet.isViewWallet) { command = ParseCommand( DefaultCommands.BasicViewWalletCommands(), DefaultCommands.AllViewWalletCommands(), GetPrompt(wallet) ); } else { command = ParseCommand( DefaultCommands.BasicCommands(), DefaultCommands.AllCommands(), GetPrompt(wallet) ); } /* If exit command is given, quit */ if (CommandImplementations.HandleCommand(command, wallet)) { return; } } }
private static void Advanced(WalletBackend wallet) { if (wallet.isViewWallet) { Menu.PrintCommands( DefaultCommands.AdvancedViewWalletCommands(), /* The offset to print the number from, e.g. help is * command numbers 1-7 or whatever, advanced is command * numbers 8-19 */ DefaultCommands.BasicViewWalletCommands().Count() ); } else { Menu.PrintCommands( DefaultCommands.AdvancedCommands(), /* Offset */ DefaultCommands.BasicCommands().Count() ); } }
private static void ExportKeys(WalletBackend wallet) { Utilities.ConfirmPassword(wallet); RedMsg.WriteLine("The below data is PRIVATE and should not be " + "given to anyone!"); RedMsg.WriteLine("If someone else gains access to these, they " + "can steal all your funds!"); Console.WriteLine(); if (wallet.isViewWallet) { GreenMsg.WriteLine("Private view key:"); GreenMsg.WriteLine(wallet.keys.privateViewKey.ToString()); return; } GreenMsg.WriteLine("Private spend key:"); GreenMsg.WriteLine(wallet.keys.privateSpendKey.ToString()); Console.WriteLine(); GreenMsg.WriteLine("Private view key:"); GreenMsg.WriteLine(wallet.keys.privateViewKey.ToString()); if (KeyOps.AreKeysDeterministic(wallet.keys.privateSpendKey, wallet.keys.privateViewKey)) { string mnemonic = Mnemonics.PrivateKeyToMnemonic( wallet.keys.privateSpendKey ); GreenMsg.WriteLine("\nMnemonic seed:"); GreenMsg.WriteLine(mnemonic); } }
private static void Main(string[] Args) { // Add exit command detection Console.CancelKeyPress += (sender, e) => { e.Cancel = true; SaveAndExit(); }; // Initialize a wallet backend instance WalletBackend = new WalletBackend(AddressPrefix); // If there is only one commandline argument, first check if it's an existing wallet if (Args.Length == 1 && File.Exists(Args[0])) { LoadWallet(Args[0]); } // TODO - commandline arguments // Start showing the menu ShowMenu(); }
private static bool Exit(WalletBackend wallet) { YellowMsg.WriteLine("Saving wallet and shutting down..."); wallet.Save(); return(true); }
private static void Save(WalletBackend wallet) { YellowMsg.WriteLine("Saving..."); wallet.Save(); YellowMsg.WriteLine("Saved!"); }
public static bool HandleCommand(string command, WalletBackend wallet) { switch (command) { case "advanced": { Advanced(wallet); break; } case "address": { ConsoleMessage.WriteLine(ConsoleColor.DarkGreen, wallet.addresses[0]); break; } case "balance": { ConsoleMessage.WriteLine(ConsoleColor.Red, "Command not implemented yet..."); break; } case "backup": { ExportKeys(wallet); break; } case "exit": { return(Exit(wallet)); } case "help": { Help(wallet); break; } case "transfer": { ConsoleMessage.WriteLine(ConsoleColor.Red, "Command not implemented yet..."); break; } case "ab_add": { ConsoleMessage.WriteLine(ConsoleColor.Red, "Command not implemented yet..."); break; } case "ab_delete": { ConsoleMessage.WriteLine(ConsoleColor.Red, "Command not implemented yet..."); break; } case "ab_list": { ConsoleMessage.WriteLine(ConsoleColor.Red, "Command not implemented yet..."); break; } case "ab_send": { ConsoleMessage.WriteLine(ConsoleColor.Red, "Command not implemented yet..."); break; } case "change_password": { ChangePassword(wallet); break; } case "make_integrated_address": { ConsoleMessage.WriteLine(ConsoleColor.Red, "Command not implemented yet..."); break; } case "incoming_transfers": { ConsoleMessage.WriteLine(ConsoleColor.Red, "Command not implemented yet..."); break; } case "list_transfers": { ConsoleMessage.WriteLine(ConsoleColor.Red, "Command not implemented yet..."); break; } case "optimize": { ConsoleMessage.WriteLine(ConsoleColor.Red, "Command not implemented yet..."); break; } case "outgoing_transfers": { ConsoleMessage.WriteLine(ConsoleColor.Red, "Command not implemented yet..."); break; } case "reset": { ConsoleMessage.WriteLine(ConsoleColor.Red, "Command not implemented yet..."); break; } case "save": { Save(wallet); break; } case "save_csv": { ConsoleMessage.WriteLine(ConsoleColor.Red, "Command not implemented yet..."); break; } case "send_all": { ConsoleMessage.WriteLine(ConsoleColor.Red, "Command not implemented yet..."); break; } case "status": { ConsoleMessage.WriteLine(ConsoleColor.Red, "Command not implemented yet..."); break; } /* This should never happen */ default: { throw new NotImplementedException( "Command was defined but not hooked up!" ); } } /* Don't exit */ return(false); }
private static bool Exit(WalletBackend wallet) { ConsoleMessage.WriteLine(ConsoleColor.Yellow, "Saving wallet and shutting down..."); wallet.Save(); return(true); }
private static void Save(WalletBackend wallet) { ConsoleMessage.WriteLine(ConsoleColor.Yellow, "Saving..."); wallet.Save(); ConsoleMessage.WriteLine(ConsoleColor.Yellow, "Saved!"); }