Пример #1
0
        private void OnCommandAccountsNew(string[] args)
        {
            string name = args.Length > 0 ? args[0] : BConsole.ReadLine("name: ");

            if (string.IsNullOrEmpty(name))
            {
                return;
            }

            if (wallets.Contains(name))
            {
                BConsole.WriteLine("account name already exists");
                return;
            }

            string password = BConsole.ReadPassword("password: "******"confirm: ");

            if (password != confirm)
            {
                BConsole.WriteLine("password mismatch");
                return;
            }

            string token = BConsole.ReadLine("token: ");

            if (string.IsNullOrEmpty(token))
            {
                BConsole.WriteLine("key export token not found");
                return;
            }

            Task.Run(async() =>
            {
                (string key, string error) = await web4b.GetUserKeyAsync(token);
                if (string.IsNullOrEmpty(key))
                {
                    BConsole.WriteLine("error: ", error);
                    return;
                }

                BConsole.WriteLine("key received! wait a while encrypting key...");
                string keystore = KeyStoreService.EncryptKeyStoreV3(key, password);
                var account     = wallets.Add(name, keystore);

                BConsole.WriteLine(name, "(", account.Address, ") imported!");
            });
        }