Beispiel #1
0
        private bool OnUpgradeWalletCommand(string[] args)
        {
            if (args.Length < 3)
            {
                Console.WriteLine("error");
                return(true);
            }
            string path = args[2];

            if (Path.GetExtension(path) != ".db3")
            {
                Console.WriteLine("Can't upgrade the wallet file.");
                return(true);
            }
            if (!File.Exists(path))
            {
                Console.WriteLine("File does not exist.");
                return(true);
            }
            string password = ReadPassword("password");

            if (password.Length == 0)
            {
                Console.WriteLine("cancelled");
                return(true);
            }
            string path_new = Path.ChangeExtension(path, ".json");

            BRC6Wallet.Migrate(GetIndexer(), path_new, path, password).Save();
            Console.WriteLine($"Wallet file upgrade complete. New wallet file has been auto-saved at: {path_new}");
            return(true);
        }
Beispiel #2
0
 private void 打开钱包数据库OToolStripMenuItem_Click(object sender, EventArgs e)
 {
     using (OpenWalletDialog dialog = new OpenWalletDialog())
     {
         if (dialog.ShowDialog() != DialogResult.OK)
         {
             return;
         }
         string path = dialog.WalletPath;
         Wallet wallet;
         if (Path.GetExtension(path) == ".db3")
         {
             if (MessageBox.Show(Strings.MigrateWalletMessage, Strings.MigrateWalletCaption, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
             {
                 string path_old = path;
                 path = Path.ChangeExtension(path_old, ".json");
                 BRC6Wallet BRC6Wallet;
                 try
                 {
                     BRC6Wallet = BRC6Wallet.Migrate(GetIndexer(), path, path_old, dialog.Password);
                 }
                 catch (CryptographicException)
                 {
                     MessageBox.Show(Strings.PasswordIncorrect);
                     return;
                 }
                 BRC6Wallet.Save();
                 BRC6Wallet.Unlock(dialog.Password);
                 wallet = BRC6Wallet;
                 MessageBox.Show($"{Strings.MigrateWalletSucceedMessage}\n{path}");
             }
             else
             {
                 try
                 {
                     wallet = UserWallet.Open(GetIndexer(), path, dialog.Password);
                 }
                 catch (CryptographicException)
                 {
                     MessageBox.Show(Strings.PasswordIncorrect);
                     return;
                 }
             }
         }
         else
         {
             BRC6Wallet BRC6Wallet = new BRC6Wallet(GetIndexer(), path);
             try
             {
                 BRC6Wallet.Unlock(dialog.Password);
             }
             catch (CryptographicException)
             {
                 MessageBox.Show(Strings.PasswordIncorrect);
                 return;
             }
             wallet = BRC6Wallet;
         }
         ChangeWallet(wallet);
         Settings.Default.LastWalletPath = path;
         Settings.Default.Save();
     }
 }