Example #1
0
        static void Main(string[] args)
        {
            for (int i = 0; i < args.Length; i++)
            {
                switch (args[i].ToLower())
                {
                case "--help":
                case "-h":
                    Console.WriteLine($"{Config.CurrencyName} - C# Wallet - v{ Config.Version }");
                    Console.WriteLine("=====   Commands   =====");
                    Console.WriteLine("--walletfile          : specifies the name of the wallet to open");
                    Console.WriteLine("--password            : the password to decrypt the wallet");
                    Console.WriteLine("--debug               : enables debugging output");
                    Console.WriteLine();
                    return;

                case "--walletfile":
                    if (i + 1 < args.Length)
                    {
                        currentFileName = args[++i];
                    }
                    break;

                case "--password":
                    if (i + 1 < args.Length)
                    {
                        currentPassword = args[++i];
                    }
                    break;
                }
            }

            Console.WriteLine("==============================");
            Console.WriteLine($"{Config.CurrencyName} - C# Wallet - v{ Config.Version }");
            Console.WriteLine("==============================");

            if (String.IsNullOrEmpty(currentPassword) || String.IsNullOrEmpty(currentFileName))
            {
                char responseChar = DisplayMenu(new Dictionary <char, string>
                {
                    { 'O', "Open Existing Wallet" },
                    { 'N', "Create new wallet" },
                    { 'R', "Restore Wallet" },
                    { 'X', "Exit" }
                });

                switch (Char.ToUpperInvariant(responseChar))
                {
                case 'O':
                    GetWalletAndPassword(false);
                    currentWallet = WalletContainer.Read(currentFileName, currentPassword);
                    Console.WriteLine($"Opened wallet: {currentFileName}");
                    break;

                case 'N':
                    GetWalletAndPassword(true);
                    currentWallet = new WalletContainer();
                    CreateNewWallet();
                    break;

                case 'R':
                    GetWalletAndPassword(true);
                    currentWallet = new WalletContainer();
                    CreateNewWalletFromSeed();
                    break;

                case 'X':
                    return;
                }
            }
            else
            {
                currentWallet = WalletContainer.Read(currentFileName, currentPassword);
            }

            new WalletSyncService(currentWallet, currentFileName, currentPassword).Start();

            while (true)
            {
                char mainResponseChar = DisplayMenu(new Dictionary <Char, String>
                {
                    { 'P', "Show pending transactions" },
                    { 'L', "List transfers" },
                    { 'B', "Balance" },
                    { 'T', "Transfer" },
                    { 'S', "Show seed" },
                    { 'R', "Rebuild wallet" },
                    { 'C', "Create new wallet" },
                    { 'A', "Add existing wallet" },
                    { 'D', "Delete wallet" },
                    { 'W', "List wallets" },
                    { 'N', "Name a wallet" },
                    { 'X', "Exit" }
                });

                switch (Char.ToUpperInvariant(mainResponseChar))
                {
                case 'P':
                case 'L':
                case 'T':
                    Console.WriteLine("Feature not yet implemented");
                    break;

                case 'B':
                    Console.WriteLine($"Current balance: { currentWallet.GetBalance() }");
                    break;

                case 'S':
                    Console.WriteLine("Addresses and seeds - DO NOT SHARE:");
                    foreach (Wallet wallet in currentWallet.Wallets)
                    {
                        Console.WriteLine("-------------------------------------------------------------------------------------------------");
                        Console.WriteLine($"Address: {wallet.Address}");
                        Console.WriteLine($"Seed: {wallet.Seed}");
                    }
                    Console.WriteLine("-------------------------------------------------------------------------------------------------");
                    break;

                case 'R':
                    foreach (Wallet wallet in currentWallet.Wallets)
                    {
                        wallet.Height = 0;
                        wallet.tokens.Clear();
                        wallet.Transactions.Clear();
                    }

                    currentWallet.Write(currentFileName, currentPassword);
                    break;

                case 'C':
                    CreateNewWallet();
                    break;

                case 'A':
                    CreateNewWalletFromSeed();
                    break;

                case 'D':
                    for (var i = 0; i < currentWallet.Wallets.Count; i++)
                    {
                        Console.WriteLine($"{i}: {currentWallet.Wallets[i].Address}");
                    }

                    Console.Write("Please choose a wallet number to delete: ");
                    string readString = Console.ReadLine();
                    if (!String.IsNullOrWhiteSpace(readString) && readString.All(Char.IsDigit))
                    {
                        int readInt = Convert.ToInt32(readString);
                        if (readInt < currentWallet.Wallets.Count)
                        {
                            Console.WriteLine($"Wallet number {readInt} was removed!");
                            currentWallet.Wallets.RemoveAt(readInt);
                        }
                    }
                    else
                    {
                        Console.WriteLine("You did not enter a valid wallet number to delete!");
                    }

                    break;

                case 'W':
                    for (var i = 0; i < currentWallet.Wallets.Count; i++)
                    {
                        Console.WriteLine($"{i}: {currentWallet.Wallets[i].Address}");
                    }
                    break;

                case 'N':
                    for (var i = 0; i < currentWallet.Wallets.Count; i++)
                    {
                        Console.WriteLine($"{i}: {currentWallet.Wallets[i].Address}");
                    }

                    Console.Write("Please choose a wallet number to rename: ");
                    string readNameString = Console.ReadLine();
                    if (!String.IsNullOrWhiteSpace(readNameString) && readNameString.All(Char.IsDigit))
                    {
                        int readInt = Convert.ToInt32(readNameString);
                        if (readInt < currentWallet.Wallets.Count)
                        {
                            Console.Write("Please enter the new name for the wallet: ");
                            readNameString = Console.ReadLine();

                            if (!String.IsNullOrWhiteSpace(readNameString))
                            {
                                currentWallet.Wallets[readInt].Name = readNameString;
                                currentWallet.Write(currentFileName, currentPassword);
                            }
                            else
                            {
                                Console.WriteLine("You did not enter a valid name!");
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine("You did not enter a valid wallet number to rename!");
                    }
                    break;

                case 'X':
                    return;
                }
            }
        }
 public WalletSyncService(WalletContainer wallet, String filePath, String password)
 {
     this.walletContainer = wallet;
     this.filePath        = filePath;
     this.password        = password;
 }