Exemplo n.º 1
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("Wallet files in db3 format are not supported, please use a .json file extension.");
                return(true);
            }
            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);
            }
            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);
        }
Exemplo n.º 2
0
        public void CreateMintTx()
        {
            if (!InitWallet())
            {
                return;
            }

            UInt160 to = Wallet.GetAccounts().First().ScriptHash;

            // Import all CN keys

            var wallet = new NEP6Wallet("");

            using var unlock = wallet.Unlock(WALLET_PASS);

            var cnWallets = Settings.Default.Wifs.Select(wif => wallet.Import(wif)).ToArray();

            // Get CN contract

            using var snapshot = Blockchain.Singleton.GetSnapshot();
            var validators = NativeContract.NEO.GetValidators(snapshot);
            var CNContract = Contract.CreateMultiSigContract(validators.Length - (validators.Length - 1) / 3, validators);

            wallet.CreateAccount(CNContract);

            Console.WriteLine($"Generated mint tx: from={CNContract.ScriptHash.ToAddress()} to={to.ToAddress()}");

            // Create TX

            var mintTx = wallet.MakeTransaction
                         (
                new TransferOutput[]
            {
                new TransferOutput()
                {
                    AssetId    = NEO.AssetId,
                    ScriptHash = to,
                    Value      = new BigDecimal(50_000_000, 0),
                },
Exemplo n.º 3
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);
     }
 }
Exemplo n.º 4
0
        private bool OnCreateWalletCommand(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 = "";
            // 创建账号去掉密码 2018-04-11 TNT
            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(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()}");
                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);
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
0
        public void TestContains()
        {
            bool result = uut.Contains(testScriptHash);

            Assert.AreEqual(false, result);
            uut.CreateAccount(testScriptHash);
            result = uut.Contains(testScriptHash);
            Assert.AreEqual(true, result);
        }