Skip to content

Commit

Permalink
fix bug; restore accounts;
Browse files Browse the repository at this point in the history
  • Loading branch information
Erik Zhang committed Oct 25, 2016
1 parent ea6d76f commit cc27c99
Show file tree
Hide file tree
Showing 9 changed files with 585 additions and 27 deletions.
12 changes: 12 additions & 0 deletions AntSharesUI/AntSharesUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@
<Compile Include="UI\OptionsDialog.Designer.cs">
<DependentUpon>OptionsDialog.cs</DependentUpon>
</Compile>
<Compile Include="UI\RestoreAccountsDialog.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="UI\RestoreAccountsDialog.Designer.cs">
<DependentUpon>RestoreAccountsDialog.cs</DependentUpon>
</Compile>
<Compile Include="UI\TradeForm.cs">
<SubType>Form</SubType>
</Compile>
Expand Down Expand Up @@ -319,6 +325,12 @@
<EmbeddedResource Include="UI\PayToDialog.zh-Hans.resx">
<DependentUpon>PayToDialog.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="UI\RestoreAccountsDialog.resx">
<DependentUpon>RestoreAccountsDialog.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="UI\RestoreAccountsDialog.zh-Hans.resx">
<DependentUpon>RestoreAccountsDialog.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="UI\SelectCertificateDialog.zh-Hans.resx">
<DependentUpon>SelectCertificateDialog.cs</DependentUpon>
<SubType>Designer</SubType>
Expand Down
9 changes: 9 additions & 0 deletions AntSharesUI/UI/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 24 additions & 5 deletions AntSharesUI/UI/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
17 changes: 16 additions & 1 deletion AntSharesUI/UI/MainForm.resx
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,16 @@
<value>216, 22</value>
</data>
<data name="重建钱包数据库RToolStripMenuItem.Text" xml:space="preserve">
<value>&amp;Rebuild Index</value>
<value>Rebuild &amp;Index</value>
</data>
<data name="restoreAccountsToolStripMenuItem.Enabled" type="System.Boolean, mscorlib">
<value>False</value>
</data>
<data name="restoreAccountsToolStripMenuItem.Size" type="System.Drawing.Size, System.Drawing">
<value>216, 22</value>
</data>
<data name="restoreAccountsToolStripMenuItem.Text" xml:space="preserve">
<value>&amp;Restore Accounts...</value>
</data>
<data name="toolStripSeparator2.Size" type="System.Drawing.Size, System.Drawing">
<value>213, 6</value>
Expand Down Expand Up @@ -851,6 +860,12 @@
<data name="&gt;&gt;重建钱包数据库RToolStripMenuItem.Type" xml:space="preserve">
<value>System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;restoreAccountsToolStripMenuItem.Name" xml:space="preserve">
<value>restoreAccountsToolStripMenuItem</value>
</data>
<data name="&gt;&gt;restoreAccountsToolStripMenuItem.Type" xml:space="preserve">
<value>System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;toolStripSeparator2.Name" xml:space="preserve">
<value>toolStripSeparator2</value>
</data>
Expand Down
42 changes: 21 additions & 21 deletions AntSharesUI/UI/MainForm.zh-Hans.resx
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,13 @@
<value>187, 22</value>
</data>
<data name="重建钱包数据库RToolStripMenuItem.Text" xml:space="preserve">
<value>重建钱包索引(&amp;R)</value>
<value>重建钱包索引(&amp;I)</value>
</data>
<data name="restoreAccountsToolStripMenuItem.Size" type="System.Drawing.Size, System.Drawing">
<value>187, 22</value>
</data>
<data name="restoreAccountsToolStripMenuItem.Text" xml:space="preserve">
<value>还原账户(&amp;R)...</value>
</data>
<data name="toolStripSeparator2.Size" type="System.Drawing.Size, System.Drawing">
<value>184, 6</value>
Expand Down Expand Up @@ -217,12 +223,6 @@
<data name="选举EToolStripMenuItem.Text" xml:space="preserve">
<value>选举(&amp;E)...</value>
</data>
<data name="投票VToolStripMenuItem.Size" type="System.Drawing.Size, System.Drawing">
<value>161, 22</value>
</data>
<data name="投票VToolStripMenuItem.Text" xml:space="preserve">
<value>投票(&amp;V)...</value>
</data>
<data name="toolStripSeparator9.Size" type="System.Drawing.Size, System.Drawing">
<value>158, 6</value>
</data>
Expand Down Expand Up @@ -345,23 +345,23 @@
</data>
<data name="listView1.Groups" mimetype="application/x-microsoft.net.object.binary.base64">
<value>
AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w
LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACJTeXN0
ZW0uV2luZG93cy5Gb3Jtcy5MaXN0Vmlld0dyb3VwBAAAAAZIZWFkZXIPSGVhZGVyQWxpZ25tZW50A1Rh
ZwROYW1lAQQCAShTeXN0ZW0uV2luZG93cy5Gb3Jtcy5Ib3Jpem9udGFsQWxpZ25tZW50AgAAAAIAAAAG
AwAAAAzmoIflh4botKbmiLcF/P///yhTeXN0ZW0uV2luZG93cy5Gb3Jtcy5Ib3Jpem9udGFsQWxpZ25t
ZW50AQAAAAd2YWx1ZV9fAAgCAAAAAAAAAAoGBQAAABVzdGFuZGFyZENvbnRyYWN0R3JvdXAL
</value>
AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w
LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACJTeXN0
ZW0uV2luZG93cy5Gb3Jtcy5MaXN0Vmlld0dyb3VwBAAAAAZIZWFkZXIPSGVhZGVyQWxpZ25tZW50A1Rh
ZwROYW1lAQQCAShTeXN0ZW0uV2luZG93cy5Gb3Jtcy5Ib3Jpem9udGFsQWxpZ25tZW50AgAAAAIAAAAG
AwAAAAzmoIflh4botKbmiLcF/P///yhTeXN0ZW0uV2luZG93cy5Gb3Jtcy5Ib3Jpem9udGFsQWxpZ25t
ZW50AQAAAAd2YWx1ZV9fAAgCAAAAAAAAAAoGBQAAABVzdGFuZGFyZENvbnRyYWN0R3JvdXAL
</value>
</data>
<data name="listView1.Groups1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>
AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w
LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACJTeXN0
ZW0uV2luZG93cy5Gb3Jtcy5MaXN0Vmlld0dyb3VwBAAAAAZIZWFkZXIPSGVhZGVyQWxpZ25tZW50A1Rh
ZwROYW1lAQQCAShTeXN0ZW0uV2luZG93cy5Gb3Jtcy5Ib3Jpem9udGFsQWxpZ25tZW50AgAAAAIAAAAG
AwAAAAzlkIjnuqblnLDlnYAF/P///yhTeXN0ZW0uV2luZG93cy5Gb3Jtcy5Ib3Jpem9udGFsQWxpZ25t
ZW50AQAAAAd2YWx1ZV9fAAgCAAAAAAAAAAoGBQAAABhub25zdGFuZGFyZENvbnRyYWN0R3JvdXAL
</value>
AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w
LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACJTeXN0
ZW0uV2luZG93cy5Gb3Jtcy5MaXN0Vmlld0dyb3VwBAAAAAZIZWFkZXIPSGVhZGVyQWxpZ25tZW50A1Rh
ZwROYW1lAQQCAShTeXN0ZW0uV2luZG93cy5Gb3Jtcy5Ib3Jpem9udGFsQWxpZ25tZW50AgAAAAIAAAAG
AwAAAAzlkIjnuqblnLDlnYAF/P///yhTeXN0ZW0uV2luZG93cy5Gb3Jtcy5Ib3Jpem9udGFsQWxpZ25t
ZW50AQAAAAd2YWx1ZV9fAAgCAAAAAAAAAAoGBQAAABhub25zdGFuZGFyZENvbnRyYWN0R3JvdXAL
</value>
</data>
<data name="toolStripStatusLabel1.Size" type="System.Drawing.Size, System.Drawing">
<value>35, 17</value>
Expand Down
94 changes: 94 additions & 0 deletions AntSharesUI/UI/RestoreAccountsDialog.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions AntSharesUI/UI/RestoreAccountsDialog.cs
Original file line number Diff line number Diff line change
@@ -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<Contract> GetContracts()
{
return listView1.CheckedItems.OfType<ListViewItem>().Select(p => (Contract)p.Tag);
}

private void RestoreAccountsDialog_Load(object sender, EventArgs e)
{
IEnumerable<Account> accounts = Program.CurrentWallet.GetAccounts();
accounts = accounts.Where(account => Program.CurrentWallet.GetContracts(account.PublicKeyHash).All(contract => !contract.IsStandard));
IEnumerable<Contract> 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;
}
}
}
Loading

0 comments on commit cc27c99

Please sign in to comment.