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"); NEP6Wallet.Migrate(path_new, path, password).Save(); Console.WriteLine($"Wallet file upgrade complete. New wallet file has been auto-saved at: {path_new}"); return(true); }
private void OnUpgradeWalletCommand(string path) { if (Path.GetExtension(path).ToLowerInvariant() != ".db3") { Console.WriteLine("Can't upgrade the wallet file."); return; } if (!File.Exists(path)) { Console.WriteLine("File does not exist."); return; } string password = ReadUserInput("password", true); if (password.Length == 0) { Console.WriteLine("Cancelled"); return; } string path_new = Path.ChangeExtension(path, ".json"); if (File.Exists(path_new)) { Console.WriteLine($"File '{path_new}' already exists"); return; } NEP6Wallet.Migrate(path_new, path, password).Save(); Console.WriteLine($"Wallet file upgrade complete. New wallet file has been auto-saved at: {path_new}"); }
public string MigrateWallet(string walletPath, string password, string newWalletPath = null) { if (string.IsNullOrEmpty(newWalletPath)) { newWalletPath = Path.ChangeExtension(walletPath, ".json"); newWalletPath = FileManager.GetAvailableFilePath(newWalletPath); } NEP6Wallet nep6Wallet; try { nep6Wallet = NEP6Wallet.Migrate(newWalletPath, walletPath, password); } catch (CryptographicException) { this.notificationService.ShowErrorNotification(Strings.PasswordIncorrect); return(null); } // Migration successful nep6Wallet.Save(); nep6Wallet.Dispose(); this.notificationService.ShowInformationNotification(Strings.MigrateWalletSucceedMessage + newWalletPath); return(newWalletPath); }
private void OnUpgradeWalletCommand(string path) { if (Path.GetExtension(path).ToLowerInvariant() != ".db3") { ConsoleHelper.Warning("Can't upgrade the wallet file. Check if your wallet is in db3 format."); return; } if (!File.Exists(path)) { ConsoleHelper.Error("File does not exist."); return; } string password = ReadUserInput("password", true); if (password.Length == 0) { ConsoleHelper.Info("Cancelled"); return; } string pathNew = Path.ChangeExtension(path, ".json"); if (File.Exists(pathNew)) { ConsoleHelper.Warning($"File '{pathNew}' already exists"); return; } NEP6Wallet.Migrate(pathNew, path, password, NeoSystem.Settings).Save(); Console.WriteLine($"Wallet file upgrade complete. New wallet file has been auto-saved at: {pathNew}"); }
public void TestMigrate() { string path = GetRandomPath(); UserWallet uw = UserWallet.Create(path, "123"); uw.CreateAccount(keyPair.PrivateKey); string npath = Path.Combine(path, "w.json"); NEP6Wallet nw = NEP6Wallet.Migrate(npath, path, "123"); bool result = nw.Contains(testScriptHash); Assert.AreEqual(true, result); }
public void TestMigrate() { string path = GetRandomPath(); UserWallet uw = UserWallet.Create(path, "123", ProtocolSettings.Default); uw.CreateAccount(keyPair.PrivateKey); string npath = CreateWalletFile(); // Scrypt test values NEP6Wallet nw = NEP6Wallet.Migrate(npath, path, "123", ProtocolSettings.Default); bool result = nw.Contains(testScriptHash); Assert.AreEqual(true, result); uw.Delete(); nw.Delete(); }
private static Wallet OpenWallet(string path, string password) { if (Path.GetExtension(path) == ".db3") { string path_new = Path.ChangeExtension(path, ".json"); NEP6Wallet nep6wallet = NEP6Wallet.Migrate(path_new, path, password); nep6wallet.Save(); return(nep6wallet); } else //.json { NEP6Wallet nep6wallet = new NEP6Wallet(path); nep6wallet.Unlock(password); return(nep6wallet); } }
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"); NEP6Wallet nep6wallet; try { nep6wallet = NEP6Wallet.Migrate(GetIndexer(), path, path_old, dialog.Password); } catch (CryptographicException) { MessageBox.Show(Strings.PasswordIncorrect); return; } nep6wallet.Save(); nep6wallet.Unlock(dialog.Password); wallet = nep6wallet; MessageBox.Show($"{Strings.MigrateWalletSucceedMessage}\n{path}"); } else { try { wallet = UserWallet.Open(GetIndexer(), path, dialog.Password); } catch (CryptographicException) { MessageBox.Show(Strings.PasswordIncorrect); return; } } } else { NEP6Wallet nep6wallet = new NEP6Wallet(GetIndexer(), path); try { nep6wallet.Unlock(dialog.Password); } catch (CryptographicException) { MessageBox.Show(Strings.PasswordIncorrect); return; } wallet = nep6wallet; } ChangeWallet(wallet); Settings.Default.LastWalletPath = path; Settings.Default.Save(); } }
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(LanHelper.LocalLanguage("Opening wallet files in older versions, update to newest format?Note: updated files cannot be openned by clients in older versions!"), LanHelper.LocalLanguage("Migrate Wallet"), MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes) { string path_old = path; path = Path.ChangeExtension(path_old, ".json"); NEP6Wallet nep6wallet; try { nep6wallet = NEP6Wallet.Migrate(GetIndexer(), path, path_old, dialog.Password); } catch (CryptographicException) { MessageBox.Show(LanHelper.LocalLanguage("Password Incorrect")); return; } nep6wallet.Save(); nep6wallet.Unlock(dialog.Password); wallet = nep6wallet; MessageBox.Show($"{LanHelper.LocalLanguage("Wallet file relocated. New wallet file has been saved at: ")}\n{path}"); } else { try { wallet = UserWallet.Open(GetIndexer(), path, dialog.Password); } catch (CryptographicException) { MessageBox.Show(LanHelper.LocalLanguage("Password Incorrect")); return; } } } else { NEP6Wallet nep6wallet = new NEP6Wallet(GetIndexer(), path); try { nep6wallet.Unlock(dialog.Password); } catch (CryptographicException) { MessageBox.Show(LanHelper.LocalLanguage("Password Incorrect")); return; } wallet = nep6wallet; } ChangeWallet(wallet); Settings.Default.LastWalletPath = path; Settings.Default.Save(); } }