Beispiel #1
0
        public void RecoverWallet(string path = "")
        {
            var walletFilePath = GetWalletFilePath(path);
            AssertWalletNotExists(walletFilePath);

            WriteLine($"Your software is configured using the Bitcoin {Config.network} network.");
            WriteLine("Provide your mnemonic words, separated by spaces:");
            string mnemonicString = ReadLine();
            AssertCorrectMnemonicFormat(mnemonicString);
            Mnemonic mnemonic = new Mnemonic(mnemonicString);

            WriteLine("Provide your password. Please note the wallet cannot check if your password is correct or not. If you provide a wrong password a wallet will be recovered with your provided mnemonic AND password pair:");
            string password = PasswordConsole.ReadPassword();

            Safe safe = Safe.Recover(mnemonic, password, walletFilePath, Config.network);
            // 若无异常抛出,则成功恢复
            WriteLine();
            WriteLine("Wallet is successfully recovered.");
            WriteLine($"Wallet file: {walletFilePath}");
        }
Beispiel #2
0
        //public static HashSet<string> Commands = new HashSet<string>(){
        //    "help",
        //    "generate-wallet",
        //    "recover-wallet",
        //    "show-balances",
        //    "show-history",
        //    "receive",
        //    "send"
        //};
        #endregion

        
        public void GenerateWallet(string path = "")
        { 
            string walletFilePath = GetWalletFilePath(path);
            AssertWalletNotExists(walletFilePath);

            string pw;
            string pwConf;
            while(true)
            {
                WriteLine("Choose a password:"******"Confirm password:"******"Passwords do not match. Try again!");
            }


            Mnemonic mnemonic;
            Safe safe = Safe.Create(out mnemonic, pw, walletFilePath, Config.network);
            // 若无异常,则成功创建钱包
            WriteLine();
            WriteLine("Wallet is successfully created.");
            WriteLine($"Wallet file: {walletFilePath}");

            WriteLine();
            WriteLine("Write down the following mnemonic words.");
            WriteLine("With the mnemonic words AND your password you can recover this wallet by using the recover-wallet command.");
            WriteLine();
            WriteLine("-------");
            WriteLine(mnemonic);
            WriteLine("-------");
            File.WriteAllText(walletFilePath.Split('.')[0] + "_mnemonic.txt", mnemonic.ToString());
            WriteLine("mnemonic is saved in file " + walletFilePath.Split('.')[0] + "_mnemonic.txt");
        }