From cc27c99ccc4f6f9801f5016d931a943db55e26b4 Mon Sep 17 00:00:00 2001 From: Erik Zhang Date: Tue, 25 Oct 2016 22:27:25 +0800 Subject: [PATCH] fix bug; restore accounts; --- AntSharesUI/AntSharesUI.csproj | 12 + AntSharesUI/UI/MainForm.Designer.cs | 9 + AntSharesUI/UI/MainForm.cs | 29 ++- AntSharesUI/UI/MainForm.resx | 17 +- AntSharesUI/UI/MainForm.zh-Hans.resx | 42 +-- .../UI/RestoreAccountsDialog.Designer.cs | 94 +++++++ AntSharesUI/UI/RestoreAccountsDialog.cs | 37 +++ AntSharesUI/UI/RestoreAccountsDialog.resx | 240 ++++++++++++++++++ .../UI/RestoreAccountsDialog.zh-Hans.resx | 132 ++++++++++ 9 files changed, 585 insertions(+), 27 deletions(-) create mode 100644 AntSharesUI/UI/RestoreAccountsDialog.Designer.cs create mode 100644 AntSharesUI/UI/RestoreAccountsDialog.cs create mode 100644 AntSharesUI/UI/RestoreAccountsDialog.resx create mode 100644 AntSharesUI/UI/RestoreAccountsDialog.zh-Hans.resx diff --git a/AntSharesUI/AntSharesUI.csproj b/AntSharesUI/AntSharesUI.csproj index 2dd30a6a64..18849a8064 100644 --- a/AntSharesUI/AntSharesUI.csproj +++ b/AntSharesUI/AntSharesUI.csproj @@ -125,6 +125,12 @@ OptionsDialog.cs + + Form + + + RestoreAccountsDialog.cs + Form @@ -319,6 +325,12 @@ PayToDialog.cs + + RestoreAccountsDialog.cs + + + RestoreAccountsDialog.cs + SelectCertificateDialog.cs Designer diff --git a/AntSharesUI/UI/MainForm.Designer.cs b/AntSharesUI/UI/MainForm.Designer.cs index 5c88532d94..2a37bb3767 100644 --- a/AntSharesUI/UI/MainForm.Designer.cs +++ b/AntSharesUI/UI/MainForm.Designer.cs @@ -37,6 +37,7 @@ private void InitializeComponent() this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator(); this.修改密码CToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.重建钱包数据库RToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.restoreAccountsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator(); this.退出XToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.交易TToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); @@ -130,6 +131,7 @@ private void InitializeComponent() this.toolStripSeparator1, this.修改密码CToolStripMenuItem, this.重建钱包数据库RToolStripMenuItem, + this.restoreAccountsToolStripMenuItem, this.toolStripSeparator2, this.退出XToolStripMenuItem}); this.钱包WToolStripMenuItem.Name = "钱包WToolStripMenuItem"; @@ -163,6 +165,12 @@ private void InitializeComponent() this.重建钱包数据库RToolStripMenuItem.Name = "重建钱包数据库RToolStripMenuItem"; this.重建钱包数据库RToolStripMenuItem.Click += new System.EventHandler(this.重建钱包数据库RToolStripMenuItem_Click); // + // restoreAccountsToolStripMenuItem + // + resources.ApplyResources(this.restoreAccountsToolStripMenuItem, "restoreAccountsToolStripMenuItem"); + this.restoreAccountsToolStripMenuItem.Name = "restoreAccountsToolStripMenuItem"; + this.restoreAccountsToolStripMenuItem.Click += new System.EventHandler(this.restoreAccountsToolStripMenuItem_Click); + // // toolStripSeparator2 // resources.ApplyResources(this.toolStripSeparator2, "toolStripSeparator2"); @@ -699,6 +707,7 @@ private void InitializeComponent() private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem1; private System.Windows.Forms.ToolStripSeparator toolStripSeparator9; private System.Windows.Forms.ToolStripMenuItem optionsToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem restoreAccountsToolStripMenuItem; } } diff --git a/AntSharesUI/UI/MainForm.cs b/AntSharesUI/UI/MainForm.cs index c6a9438a80..3473b9c1d9 100644 --- a/AntSharesUI/UI/MainForm.cs +++ b/AntSharesUI/UI/MainForm.cs @@ -33,12 +33,17 @@ public MainForm() private void AddContractToListView(Contract contract, bool selected = false) { - ListViewGroup group = contract.IsStandard ? listView1.Groups["standardContractGroup"] : listView1.Groups["nonstandardContractGroup"]; - listView1.Items.Add(new ListViewItem(contract.Address, group) + ListViewItem item = listView1.Items[contract.Address]; + if (item == null) { - Name = contract.Address, - Tag = contract - }).Selected = selected; + ListViewGroup group = contract.IsStandard ? listView1.Groups["standardContractGroup"] : listView1.Groups["nonstandardContractGroup"]; + item = listView1.Items.Add(new ListViewItem(contract.Address, group) + { + Name = contract.Address, + Tag = contract + }); + } + item.Selected = selected; } private void Blockchain_PersistCompleted(object sender, Block block) @@ -67,6 +72,7 @@ private void ChangeWallet(UserWallet wallet) } 修改密码CToolStripMenuItem.Enabled = Program.CurrentWallet != null; 重建钱包数据库RToolStripMenuItem.Enabled = Program.CurrentWallet != null; + restoreAccountsToolStripMenuItem.Enabled = Program.CurrentWallet != null; 交易TToolStripMenuItem.Enabled = Program.CurrentWallet != null; 提取小蚁币CToolStripMenuItem.Enabled = Program.CurrentWallet != null; 注册资产RToolStripMenuItem.Enabled = Program.CurrentWallet != null; @@ -347,6 +353,19 @@ private void 重建钱包数据库RToolStripMenuItem_Click(object sender, EventA Program.CurrentWallet.Rebuild(); } + private void restoreAccountsToolStripMenuItem_Click(object sender, EventArgs e) + { + using (RestoreAccountsDialog dialog = new RestoreAccountsDialog()) + { + if (dialog.ShowDialog() != DialogResult.OK) return; + foreach (Contract contract in dialog.GetContracts()) + { + Program.CurrentWallet.AddContract(contract); + AddContractToListView(contract, true); + } + } + } + private void 退出XToolStripMenuItem_Click(object sender, EventArgs e) { Close(); diff --git a/AntSharesUI/UI/MainForm.resx b/AntSharesUI/UI/MainForm.resx index 884c009bbc..e6f2ba554c 100644 --- a/AntSharesUI/UI/MainForm.resx +++ b/AntSharesUI/UI/MainForm.resx @@ -153,7 +153,16 @@ 216, 22 - &Rebuild Index + Rebuild &Index + + + False + + + 216, 22 + + + &Restore Accounts... 213, 6 @@ -851,6 +860,12 @@ System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + restoreAccountsToolStripMenuItem + + + System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + toolStripSeparator2 diff --git a/AntSharesUI/UI/MainForm.zh-Hans.resx b/AntSharesUI/UI/MainForm.zh-Hans.resx index ab9ccbc4b5..bd83f7b28a 100644 --- a/AntSharesUI/UI/MainForm.zh-Hans.resx +++ b/AntSharesUI/UI/MainForm.zh-Hans.resx @@ -143,7 +143,13 @@ 187, 22 - 重建钱包索引(&R) + 重建钱包索引(&I) + + + 187, 22 + + + 还原账户(&R)... 184, 6 @@ -217,12 +223,6 @@ 选举(&E)... - - 161, 22 - - - 投票(&V)... - 158, 6 @@ -345,23 +345,23 @@ - AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w - LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACJTeXN0 - ZW0uV2luZG93cy5Gb3Jtcy5MaXN0Vmlld0dyb3VwBAAAAAZIZWFkZXIPSGVhZGVyQWxpZ25tZW50A1Rh - ZwROYW1lAQQCAShTeXN0ZW0uV2luZG93cy5Gb3Jtcy5Ib3Jpem9udGFsQWxpZ25tZW50AgAAAAIAAAAG - AwAAAAzmoIflh4botKbmiLcF/P///yhTeXN0ZW0uV2luZG93cy5Gb3Jtcy5Ib3Jpem9udGFsQWxpZ25t - ZW50AQAAAAd2YWx1ZV9fAAgCAAAAAAAAAAoGBQAAABVzdGFuZGFyZENvbnRyYWN0R3JvdXAL - + AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w + LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACJTeXN0 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W1lAQQCAShTeXN0ZW0uV2luZG93cy5Gb3Jtcy5Ib3Jpem9udGFsQWxpZ25tZW50AgAAAAIAAAAG + AwAAAAzlkIjnuqblnLDlnYAF/P///yhTeXN0ZW0uV2luZG93cy5Gb3Jtcy5Ib3Jpem9udGFsQWxpZ25t + ZW50AQAAAAd2YWx1ZV9fAAgCAAAAAAAAAAoGBQAAABhub25zdGFuZGFyZENvbnRyYWN0R3JvdXAL + 35, 17 diff --git a/AntSharesUI/UI/RestoreAccountsDialog.Designer.cs b/AntSharesUI/UI/RestoreAccountsDialog.Designer.cs new file mode 100644 index 0000000000..2182e504f6 --- /dev/null +++ b/AntSharesUI/UI/RestoreAccountsDialog.Designer.cs @@ -0,0 +1,94 @@ +namespace AntShares.UI +{ + partial class RestoreAccountsDialog + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(RestoreAccountsDialog)); + this.listView1 = new System.Windows.Forms.ListView(); + this.columnHeader1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.button1 = new System.Windows.Forms.Button(); + this.button2 = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // listView1 + // + resources.ApplyResources(this.listView1, "listView1"); + this.listView1.CheckBoxes = true; + this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { + this.columnHeader1}); + this.listView1.FullRowSelect = true; + this.listView1.GridLines = true; + this.listView1.Name = "listView1"; + this.listView1.UseCompatibleStateImageBehavior = false; + this.listView1.View = System.Windows.Forms.View.Details; + this.listView1.ItemChecked += new System.Windows.Forms.ItemCheckedEventHandler(this.listView1_ItemChecked); + // + // columnHeader1 + // + resources.ApplyResources(this.columnHeader1, "columnHeader1"); + // + // button1 + // + resources.ApplyResources(this.button1, "button1"); + this.button1.DialogResult = System.Windows.Forms.DialogResult.OK; + this.button1.Name = "button1"; + this.button1.UseVisualStyleBackColor = true; + // + // button2 + // + resources.ApplyResources(this.button2, "button2"); + this.button2.DialogResult = System.Windows.Forms.DialogResult.Cancel; + this.button2.Name = "button2"; + this.button2.UseVisualStyleBackColor = true; + // + // RestoreAccountsDialog + // + this.AcceptButton = this.button1; + resources.ApplyResources(this, "$this"); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.CancelButton = this.button2; + this.Controls.Add(this.button2); + this.Controls.Add(this.button1); + this.Controls.Add(this.listView1); + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "RestoreAccountsDialog"; + this.ShowInTaskbar = false; + this.Load += new System.EventHandler(this.RestoreAccountsDialog_Load); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.ListView listView1; + private System.Windows.Forms.ColumnHeader columnHeader1; + private System.Windows.Forms.Button button1; + private System.Windows.Forms.Button button2; + } +} \ No newline at end of file diff --git a/AntSharesUI/UI/RestoreAccountsDialog.cs b/AntSharesUI/UI/RestoreAccountsDialog.cs new file mode 100644 index 0000000000..db545452b8 --- /dev/null +++ b/AntSharesUI/UI/RestoreAccountsDialog.cs @@ -0,0 +1,37 @@ +using AntShares.Wallets; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Windows.Forms; + +namespace AntShares.UI +{ + public partial class RestoreAccountsDialog : Form + { + public RestoreAccountsDialog() + { + InitializeComponent(); + } + + public IEnumerable GetContracts() + { + return listView1.CheckedItems.OfType().Select(p => (Contract)p.Tag); + } + + private void RestoreAccountsDialog_Load(object sender, EventArgs e) + { + IEnumerable accounts = Program.CurrentWallet.GetAccounts(); + accounts = accounts.Where(account => Program.CurrentWallet.GetContracts(account.PublicKeyHash).All(contract => !contract.IsStandard)); + IEnumerable contracts = accounts.Select(p => Contract.CreateSignatureContract(p.PublicKey)); + listView1.Items.AddRange(contracts.Select(p => new ListViewItem(p.Address) + { + Tag = p + }).ToArray()); + } + + private void listView1_ItemChecked(object sender, ItemCheckedEventArgs e) + { + button1.Enabled = listView1.CheckedItems.Count > 0; + } + } +} diff --git a/AntSharesUI/UI/RestoreAccountsDialog.resx b/AntSharesUI/UI/RestoreAccountsDialog.resx new file mode 100644 index 0000000000..ca78ad0469 --- /dev/null +++ b/AntSharesUI/UI/RestoreAccountsDialog.resx @@ -0,0 +1,240 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + Top, Bottom, Left, Right + + + Address + + + + 400 + + + + 12, 12 + + + 433, 382 + + + 0 + + + listView1 + + + System.Windows.Forms.ListView, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 2 + + + Bottom, Right + + + 289, 400 + + + 75, 23 + + + 1 + + + OK + + + button1 + + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 1 + + + Bottom, Right + + + 370, 400 + + + 75, 23 + + + 2 + + + Cancel + + + button2 + + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 0 + + + True + + + 7, 17 + + + 457, 435 + + + Microsoft YaHei UI, 9pt + + + 3, 5, 3, 5 + + + CenterScreen + + + Restore Accounts + + + columnHeader1 + + + System.Windows.Forms.ColumnHeader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + RestoreAccountsDialog + + + System.Windows.Forms.Form, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/AntSharesUI/UI/RestoreAccountsDialog.zh-Hans.resx b/AntSharesUI/UI/RestoreAccountsDialog.zh-Hans.resx new file mode 100644 index 0000000000..756b805e70 --- /dev/null +++ b/AntSharesUI/UI/RestoreAccountsDialog.zh-Hans.resx @@ -0,0 +1,132 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 地址 + + + 确定 + + + 取消 + + + 还原账户 + + \ No newline at end of file