private bool OnCreateWalletCommand(string[] args) { if (args.Length < 3) { Console.WriteLine("error"); return(true); } string path = args[2]; string password = ReadPassword("password"); if (password.Length == 0) { Console.WriteLine("cancelled"); return(true); } string password2 = ReadPassword("password"); if (password != password2) { Console.WriteLine("error"); return(true); } switch (Path.GetExtension(path)) { case ".db3": { Program.Wallet = UserWallet.Create(GetIndexer(), path, password); WalletAccount account = Program.Wallet.CreateAccount(); Console.WriteLine($"address: {account.Address}"); Console.WriteLine($" pubkey: {account.GetKey().PublicKey.EncodePoint(true).ToHexString()}"); } break; case ".json": { BRC6Wallet wallet = new BRC6Wallet(GetIndexer(), path); wallet.Unlock(password); WalletAccount account = wallet.CreateAccount(); wallet.Save(); Program.Wallet = wallet; Console.WriteLine($"address: {account.Address}"); Console.WriteLine($" pubkey: {account.GetKey().PublicKey.EncodePoint(true).ToHexString()}"); } break; default: Console.WriteLine("Wallet files in that format are not supported, please use a .json or .db3 file extension."); break; } return(true); }
private void 创建钱包数据库NToolStripMenuItem_Click(object sender, EventArgs e) { using (CreateWalletDialog dialog = new CreateWalletDialog()) { if (dialog.ShowDialog() != DialogResult.OK) { return; } BRC6Wallet wallet = new BRC6Wallet(GetIndexer(), dialog.WalletPath); wallet.Unlock(dialog.Password); wallet.CreateAccount(); wallet.Save(); ChangeWallet(wallet); Settings.Default.LastWalletPath = dialog.WalletPath; Settings.Default.Save(); } }
/// <summary> /// create wallets /// </summary> /// <param name="num"></param> private void CreateWallets(int num) { List <WalletSnapshot> wss = new List <WalletSnapshot>(); for (int i = 0; i < num; i++) { string walletName = $"wallet{i}.json"; string spath = Path.Combine(path, walletName); if (File.Exists(spath)) { continue; } BRC6Wallet wallet = new BRC6Wallet(GetIndexer(), spath); wallet.Unlock(password); wallet.CreateAccount(); wallet.Save(); WalletSnapshot ws = new WalletSnapshot(); ws.walletName = walletName; ws.address = wallet.GetAccounts().ToArray()[0].Address; ws.priKey = wallet.GetAccount(ws.address.ToScriptHash()).GetKey().PrivateKey.ToHexString(); ws.pubKey = wallet.GetAccount(ws.address.ToScriptHash()).GetKey().PublicKey.ToString(); ws.script = wallet.GetAccounts().ToArray()[0].Contract.ScriptHash.ToString(); wss.Add(ws); this.Invoke(new Action(() => { listBox1.Items.Add($"{i} : {spath}"); })); } JObject json = new JObject(); json = new JArray(wss.Select(p => { JObject jobj = new JObject(); jobj["walletName"] = p.walletName; jobj["address"] = p.address; jobj["privKye"] = p.priKey; jobj["pubKye"] = p.pubKey; jobj["script"] = p.script; return(jobj); })); File.WriteAllLines(Path.Combine(path, "walletsnapshot.txt"), new string[] { json.ToString() }); }
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(); } }