diff --git a/AntSharesCore/Core/RegisterTransaction.cs b/AntSharesCore/Core/RegisterTransaction.cs index 7b2c689211..f89582a3ac 100644 --- a/AntSharesCore/Core/RegisterTransaction.cs +++ b/AntSharesCore/Core/RegisterTransaction.cs @@ -79,12 +79,12 @@ protected override void DeserializeExclusiveData(BinaryReader reader) Name = reader.ReadVarString(); Amount = reader.ReadSerializable(); if (Amount == Fixed8.Zero || Amount < -Fixed8.Satoshi) throw new FormatException(); - if (AssetType == AssetType.Share && Amount <= Fixed8.Zero) - throw new FormatException(); if (AssetType == AssetType.Invoice && Amount != -Fixed8.Satoshi) throw new FormatException(); Precision = reader.ReadByte(); if (Precision > 8) throw new FormatException(); + if (AssetType == AssetType.Share && Precision != 0) + throw new FormatException(); Issuer = ECPoint.DeserializeFrom(reader, ECCurve.Secp256r1); Admin = reader.ReadSerializable(); } diff --git a/AntSharesDaemon/Shell/MainService.cs b/AntSharesDaemon/Shell/MainService.cs index a2705a921f..6e8aaa5337 100644 --- a/AntSharesDaemon/Shell/MainService.cs +++ b/AntSharesDaemon/Shell/MainService.cs @@ -30,6 +30,8 @@ protected override bool OnCommand(string[] args) { case "create": return OnCreateCommand(args); + case "export": + return OnExportCommand(args); case "help": return OnHelpCommand(args); case "import": @@ -119,6 +121,73 @@ private bool OnCreateWalletCommand(string[] args) return true; } + private bool OnExportCommand(string[] args) + { + switch (args[1].ToLower()) + { + case "key": + return OnExportKeyCommand(args); + default: + return base.OnCommand(args); + } + } + + private bool OnExportKeyCommand(string[] args) + { + if (Program.Wallet == null) + { + Console.WriteLine("You have to open the wallet first."); + return true; + } + if (args.Length < 2 || args.Length > 4) + { + Console.WriteLine("error"); + return true; + } + UInt160 scriptHash = null; + string path = null; + if (args.Length == 3) + { + try + { + scriptHash = Wallet.ToScriptHash(args[2]); + } + catch (FormatException) + { + path = args[2]; + } + } + else if (args.Length == 4) + { + scriptHash = Wallet.ToScriptHash(args[2]); + path = args[3]; + } + using (SecureString password = ReadSecureString("password")) + { + if (password.Length == 0) + { + Console.WriteLine("cancelled"); + return true; + } + if (!Program.Wallet.VerifyPassword(password)) + { + Console.WriteLine("Incorrect password"); + return true; + } + } + IEnumerable accounts; + if (scriptHash == null) + accounts = Program.Wallet.GetAccounts(); + else + accounts = new[] { Program.Wallet.GetAccountByScriptHash(scriptHash) }; + if (path == null) + foreach (Account account in accounts) + Console.WriteLine(account.Export()); + else + File.WriteAllLines(path, accounts.Select(p => p.Export())); + return true; + } + private bool OnHelpCommand(string[] args) { Console.Write( @@ -136,6 +205,7 @@ private bool OnHelpCommand(string[] args) "\tlist asset\n" + "\tcreate address [n=1]\n" + "\timport key \n" + + "\texport key [address] [path]\n" + "\tsend
[fee=0]\n" + "Node Commands:\n" + "\tshow state\n" + diff --git a/AntSharesUI/UI/AssetRegisterDialog.cs b/AntSharesUI/UI/AssetRegisterDialog.cs index 9e3e78aca2..d8a8d7c501 100644 --- a/AntSharesUI/UI/AssetRegisterDialog.cs +++ b/AntSharesUI/UI/AssetRegisterDialog.cs @@ -22,7 +22,7 @@ public RegisterTransaction GetTransaction() AssetType = (AssetType)comboBox1.SelectedItem, Name = (AssetType)comboBox1.SelectedItem == AssetType.Share ? string.Empty : $"[{{\"lang\":\"{CultureInfo.CurrentCulture.Name}\",\"name\":\"{textBox1.Text}\"}}]", Amount = checkBox1.Checked ? Fixed8.Parse(textBox2.Text) : -Fixed8.Satoshi, - Precision = 8, + Precision = (AssetType)comboBox1.SelectedItem == AssetType.Share ? (byte)0 : (byte)8, Issuer = (ECPoint)comboBox2.SelectedItem, Admin = Wallet.ToScriptHash(comboBox3.Text), Outputs = new TransactionOutput[0] @@ -39,8 +39,6 @@ private void AssetRegisterDialog_Load(object sender, EventArgs e) private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { textBox1.Enabled = (AssetType)comboBox1.SelectedItem != AssetType.Share; - checkBox1.Enabled = (AssetType)comboBox1.SelectedItem == AssetType.Token; - if ((AssetType)comboBox1.SelectedItem == AssetType.Share) checkBox1.Checked = true; } private void checkBox1_CheckedChanged(object sender, EventArgs e)