public void Init(string walletpath, string password, string wif)
        {
            Walletpath = walletpath;
            switch (Path.GetExtension(walletpath))
            {
            case ".db3":
            {
                Wallet = UserWallet.Create(walletpath, password);
                WalletAccount account = Wallet.CreateAccount(Wallet.GetPrivateKeyFromWIF(wif));
            }
            break;

            case ".json":
            {
                NEP6Wallet wallet = new NEP6Wallet(walletpath);
                wallet.Unlock(password);
                WalletAccount account = wallet.CreateAccount(Wallet.GetPrivateKeyFromWIF(wif));
                wallet.Save();
                Wallet = wallet;
            }
            break;

            default:
                Console.WriteLine("未知的钱包文件类型");
                break;
            }

            foreach (WalletAccount account in wallet.GetAccounts())
            {
                Address = account.Address;
            }
            Password = password;
        }
Exemple #2
0
        public void CreateWallet(string path, string password)
        {
            switch (Path.GetExtension(path))
            {
            case ".db3":
            {
                UserWallet    wallet  = UserWallet.Create(path, password);
                WalletAccount account = wallet.CreateAccount();
                Console.WriteLine($"   Address: {account.Address}");
                Console.WriteLine($"    Pubkey: {account.GetKey().PublicKey.EncodePoint(true).ToHexString()}");
                Console.WriteLine($"ScriptHash: {account.ScriptHash}");
                CurrentWallet = wallet;
            }
            break;

            case ".json":
            {
                NEP6Wallet wallet = new NEP6Wallet(path);
                wallet.Unlock(password);
                WalletAccount account = wallet.CreateAccount();
                wallet.Save();
                Console.WriteLine($"   Address: {account.Address}");
                Console.WriteLine($"    Pubkey: {account.GetKey().PublicKey.EncodePoint(true).ToHexString()}");
                Console.WriteLine($"ScriptHash: {account.ScriptHash}");
                CurrentWallet = wallet;
            }
            break;

            default:
                Console.WriteLine("Wallet files in that format are not supported, please use a .json or .db3 file extension.");
                break;
            }
        }
Exemple #3
0
        private bool OnCreateWalletCommand(string[] args)
        {
            if (args.Length < 3)
            {
                Console.WriteLine("error");
                return(true);
            }
            string path = args[2];

            if (Path.GetExtension(path) == ".db3")
            {
                Console.WriteLine("The wallet file in the db3 format is not supported.");
                return(true);
            }
            string password  = ReadPassword("password");
            string password2 = ReadPassword("password");

            if (password != password2)
            {
                Console.WriteLine("error");
                return(true);
            }
            NEP6Wallet wallet = new NEP6Wallet(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()}");
            return(true);
        }
Exemple #4
0
        private void 创建钱包数据库NToolStripMenuItem_Click(object sender, EventArgs e)
        {
            using (CreateWalletDialog dialog = new CreateWalletDialog())
            {
                if (dialog.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                LoadingFrm loadingFrm = new LoadingFrm("Creating...");
                SplashScreen.Show(loadingFrm);

                NEP6Wallet wallet = new NEP6Wallet(dialog.WalletPath, null);
                wallet.Unlock(dialog.Password);
                WalletAccount account = wallet.CreateAccount();
                wallet.Save();
                Settings.Default.LastWalletPath = dialog.WalletPath;
                Settings.Default.Save();

                Program.Wallet = wallet;
                //ZoroChainSystem.Singleton.SetWallet(Program.Wallet);

                SplashScreen.Close();
            }
        }
Exemple #5
0
        private bool OnCreateWalletCommand(string[] args)
        {
            if (args.Length < 3)
            {
                Console.WriteLine("error");
                return(true);
            }
            string path     = args[2];
            string password = ReadUserInput("password", true);

            if (password.Length == 0)
            {
                Console.WriteLine("cancelled");
                return(true);
            }
            string password2 = ReadUserInput("password", true);

            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()}");
                if (system.RpcServer != null)
                {
                    system.RpcServer.Wallet = Program.Wallet;
                }
            }
            break;

            case ".json":
            {
                NEP6Wallet wallet = new NEP6Wallet(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()}");
                if (system.RpcServer != null)
                {
                    system.RpcServer.Wallet = Program.Wallet;
                }
            }
            break;

            default:
                Console.WriteLine("Wallet files in that format are not supported, please use a .json or .db3 file extension.");
                break;
            }
            return(true);
        }
Exemple #6
0
        public void Export(string filename, string password)
        {
            var nep6Wallet = new NEP6Wallet(filename, ProtocolSettings, Name);

            nep6Wallet.Unlock(password);
            foreach (var account in GetAccounts())
            {
                nep6Wallet.CreateAccount(account.Contract, account.GetKey());
            }
            nep6Wallet.Save();
        }
Exemple #7
0
        /// <summary>
        /// create new wallet
        /// </summary>
        /// <param name="path"></param>
        /// <param name="password"></param>
        /// <param name="privateKey"></param>
        /// <returns></returns>
        public async Task <object> CreateWallet(string path, string password, string privateKey = null)
        {
            var result        = new WalletModel();
            var hexPrivateKey = privateKey.TryGetPrivateKey();

            try
            {
                switch (Path.GetExtension(path))
                {
                case ".db3":
                {
                    UserWallet wallet  = UserWallet.Create(path, password, CliSettings.Default.Protocol);
                    var        account = hexPrivateKey.NotEmpty() ? wallet.CreateAccount(hexPrivateKey) : wallet.CreateAccount();
                    result.Accounts.Add(new AccountModel()
                        {
                            AccountType = AccountType.Standard,
                            Address     = account.Address,
                            ScriptHash  = account.ScriptHash,
                        });
                    Program.Starter.CurrentWallet = wallet;
                }
                break;

                case ".json":
                {
                    NEP6Wallet wallet = new NEP6Wallet(path, CliSettings.Default.Protocol);
                    wallet.Unlock(password);
                    var account = hexPrivateKey.NotEmpty() ? wallet.CreateAccount(hexPrivateKey) : wallet.CreateAccount();
                    wallet.Save();
                    result.Accounts.Add(new AccountModel()
                        {
                            AccountType = AccountType.Standard,
                            ScriptHash  = account.ScriptHash,
                            Address     = account.Address,
                        });
                    Program.Starter.CurrentWallet = wallet;
                }
                break;

                default:
                    throw new Exception("Wallet files in that format are not supported, please use a .json or .db3 file extension.");
                }
            }
            catch (CryptographicException e)
            {
                return(Error(ErrorCode.WrongPassword));
            }


            GetNeoAndGas(result.Accounts);
            return(result);
        }
Exemple #8
0
        /// <summary>
        /// 创建无密码的钱包
        /// Add Code
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        private bool OnCreateWalletsCommand(string[] args)
        {
            if (args.Length < 2)
            {
                Console.WriteLine("error");
                return(true);
            }

            //if (args.Length == 2)
            //{
            //    Console.WriteLine("功能正在开发中...");
            //    return true;
            //}

            string path     = args[2];
            string password = GetDefaultPassword();

            switch (Path.GetExtension(path))
            {
            case ".db3":
            {
                Program.Wallet = UserWallet.Create(path, password);
                WalletAccount account = Program.Wallet.CreateAccount();
                //Console.WriteLine($"address: {account.Address}");
                //Console.WriteLine($" pubkey: {account.GetKey().PublicKey.EncodePoint(true).ToHexString()}");
                PrintAccountInfo(account);
            }
            break;

            case ".json":
            {
                NEP6Wallet wallet = new NEP6Wallet(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()}");
                //Console.WriteLine($"privkey: {account.GetPrivateKey()}");
                PrintAccountInfo(account);
            }
            break;

            default:
                Console.WriteLine("Wallet files in that format are not supported, please use a .json or .db3 file extension.");
                break;
            }
            return(true);
        }
Exemple #9
0
 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);
     }
 }
Exemple #10
0
 private void 创建钱包数据库NToolStripMenuItem_Click(object sender, EventArgs e)
 {
     using (CreateWalletDialog dialog = new CreateWalletDialog())
     {
         if (dialog.ShowDialog() != DialogResult.OK)
         {
             return;
         }
         NEP6Wallet wallet = new NEP6Wallet(GetIndexer(), dialog.WalletPath);
         wallet.Unlock(dialog.Password);
         wallet.CreateAccount();
         wallet.Save();
         ChangeWallet(wallet);
         Settings.Default.LastWalletPath = dialog.WalletPath;
         Settings.Default.Save();
     }
 }
Exemple #11
0
        public void TestSave()
        {
            JObject wallet = new();

            wallet["name"]     = "name";
            wallet["version"]  = new Version("1.0").ToString();
            wallet["scrypt"]   = new ScryptParameters(2, 1, 1).ToJson();
            wallet["accounts"] = new JArray();
            wallet["extra"]    = new JObject();
            File.WriteAllText(wPath, wallet.ToString());
            uut = new NEP6Wallet(wPath, "123", ProtocolSettings.Default);
            uut.CreateAccount(keyPair.PrivateKey);
            bool result = uut.Contains(testScriptHash);

            Assert.AreEqual(true, result);
            uut.Save();
            result = uut.Contains(testScriptHash);
            Assert.AreEqual(true, result);
        }
Exemple #12
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 ".json":
            {
                NEP6Wallet wallet = new NEP6Wallet(path, null);
                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()}");
                ZoroChainSystem.Singleton.SetWallet(Program.Wallet);
            }
            break;

            default:
                Console.WriteLine("Wallet files in that format are not supported, please use a .json or .db3 file extension.");
                break;
            }
            return(true);
        }
Exemple #13
0
        public void TestSave()
        {
            JObject wallet = new JObject();

            wallet["name"]     = "name";
            wallet["version"]  = new System.Version().ToString();
            wallet["scrypt"]   = new ScryptParameters(0, 0, 0).ToJson();
            wallet["accounts"] = new JArray();
            wallet["extra"]    = new JObject();
            File.WriteAllText(wPath, wallet.ToString());
            uut = new NEP6Wallet(wPath);
            uut.Unlock("123");
            uut.CreateAccount(keyPair.PrivateKey);
            bool result = uut.Contains(testScriptHash);

            Assert.AreEqual(true, result);
            uut.Save();
            result = uut.Contains(testScriptHash);
            Assert.AreEqual(true, result);
        }
Exemple #14
0
 public static bool Create(string walletPath, out WalletAccount walletAccount)
 {
     walletAccount = null;
     try
     {
         NEP6Wallet wallet = new NEP6Wallet(walletPath);
         wallet.Unlock(_password);
         walletAccount = wallet.CreateAccount();
         wallet.Save();
         if (ActiveWallet != null)
         {
             ActiveWallet.Dispose();
         }
         ActiveWallet = wallet;
         NeoStudio.Init.ChangeWallet(wallet);
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Exemple #15
0
        private bool OnCreateWalletCommand(string[] args)
        {
            if (args.Length < 3)
            {
                Console.WriteLine("error");
                return(true);
            }
            if (system.RpcServer != null &&
                ReadUserInput("Warning: Opening the wallet with RPC turned on could result in asset loss. Are you sure you want to do this? (yes|no)", false)?.ToLowerInvariant() != "yes")
            {
                return(true);
            }
            string path     = args[2];
            string password = ReadUserInput("password", true);

            if (password.Length == 0)
            {
                Console.WriteLine("cancelled");
                return(true);
            }
            string password2 = ReadUserInput("password", true);

            if (password != password2)
            {
                Console.WriteLine("error");
                return(true);
            }
            switch (Path.GetExtension(path))
            {
            case ".db3":
            {
                Program.Wallet = UserWallet.Create(path, password);
                WalletAccount account = Program.Wallet.CreateAccount();
                Console.WriteLine($"address: {account.Address}");
                Console.WriteLine($" pubkey: {account.GetKey().PublicKey.EncodePoint(true).ToHexString()}");
                if (system.RpcServer != null)
                {
                    system.RpcServer.Wallet = Program.Wallet;
                }
            }
            break;

            case ".json":
            {
                NEP6Wallet wallet = new NEP6Wallet(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()}");
                if (system.RpcServer != null)
                {
                    system.RpcServer.Wallet = Program.Wallet;
                }
            }
            break;

            default:
                Console.WriteLine("Wallet files in that format are not supported, please use a .json or .db3 file extension.");
                break;
            }
            return(true);
        }