Beispiel #1
0
        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);
        }
Beispiel #2
0
 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() });
        }