Esempio n. 1
0
 public void TestGetKey()
 {
     account.GetKey().Should().BeNull();
     wallet.Unlock("Satoshi");
     account = new TLP6Account(wallet, hash, tlp2);
     account.GetKey().Should().Be(keyPair);
 }
Esempio n. 2
0
 private static Wallet OpenWallet(string path, string password)
 {
     if (Path.GetExtension(path) == ".db3")
     {
         return(UserWallet.Open(path, password));
     }
     else
     {
         var nep6wallet = new TLP6Wallet(path);
         nep6wallet.Unlock(password);
         return(nep6wallet);
     }
 }
Esempio n. 3
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);
        }
Esempio n. 4
0
        public void TestAddCount()
        {
            uut.CreateAccount(testScriptHash);
            Assert.IsTrue(uut.Contains(testScriptHash));
            WalletAccount account = uut.GetAccount(testScriptHash);

            Assert.IsTrue(account.WatchOnly);
            Assert.IsFalse(account.HasKey);
            uut.Unlock("123");
            uut.CreateAccount(keyPair.PrivateKey);
            account = uut.GetAccount(testScriptHash);
            Assert.IsFalse(account.WatchOnly);
            Assert.IsTrue(account.HasKey);
            uut.CreateAccount(testScriptHash);
            account = uut.GetAccount(testScriptHash);
            Assert.IsFalse(account.WatchOnly);
            Assert.IsFalse(account.HasKey);
            uut.CreateAccount(keyPair.PrivateKey);
            account = uut.GetAccount(testScriptHash);
            Assert.IsFalse(account.WatchOnly);
            Assert.IsTrue(account.HasKey);
        }
Esempio n. 5
0
        private bool OnCreateWalletCommand(string[] args)
        {
            if (args.Length < 3)
            {
                Console.WriteLine("error");
                return(true);
            }
            if (system.RpcServer != null)
            {
                if (!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).IsYes())
                {
                    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":
            {
                var wallet = new TLP6Wallet(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);
        }