From d4162f25ce8800fc96eaf8109b1e24bfcca0cb0e Mon Sep 17 00:00:00 2001 From: Erik Zhang Date: Thu, 14 Dec 2017 02:15:02 -0600 Subject: [PATCH] Feature/advanced transfer (#107) * allow users to add fee to a transaction and set change address * update dependency: Neo v2.5.2 --- neo-gui/UI/InvokeContractDialog.cs | 13 ++ neo-gui/UI/MainForm.cs | 6 +- neo-gui/UI/TransferDialog.Designer.cs | 55 ++++++++ neo-gui/UI/TransferDialog.cs | 16 ++- neo-gui/UI/TransferDialog.resx | 184 +++++++++++++++++++++++-- neo-gui/UI/TransferDialog.zh-Hans.resx | 34 +++++ neo-gui/neo-gui.csproj | 4 +- neo-gui/packages.config | 2 +- 8 files changed, 295 insertions(+), 19 deletions(-) diff --git a/neo-gui/UI/InvokeContractDialog.cs b/neo-gui/UI/InvokeContractDialog.cs index d2900101..63ebc252 100644 --- a/neo-gui/UI/InvokeContractDialog.cs +++ b/neo-gui/UI/InvokeContractDialog.cs @@ -44,6 +44,19 @@ public InvocationTransaction GetTransaction() }, fee: fee); } + public InvocationTransaction GetTransaction(UInt160 change_address, Fixed8 fee) + { + return Program.CurrentWallet.MakeTransaction(new InvocationTransaction + { + Version = tx.Version, + Script = tx.Script, + Gas = tx.Gas, + Attributes = tx.Attributes, + Inputs = tx.Inputs, + Outputs = tx.Outputs + }, change_address, fee); + } + private void UpdateScript() { if (parameters.Any(p => p.Value == null)) return; diff --git a/neo-gui/UI/MainForm.cs b/neo-gui/UI/MainForm.cs index 2f08d6b0..f022ec3a 100644 --- a/neo-gui/UI/MainForm.cs +++ b/neo-gui/UI/MainForm.cs @@ -597,17 +597,21 @@ private void 退出XToolStripMenuItem_Click(object sender, EventArgs e) private void 转账TToolStripMenuItem_Click(object sender, EventArgs e) { Transaction tx; + UInt160 change_address; + Fixed8 fee; using (TransferDialog dialog = new TransferDialog()) { if (dialog.ShowDialog() != DialogResult.OK) return; tx = dialog.GetTransaction(); + change_address = dialog.ChangeAddress; + fee = dialog.Fee; } if (tx is InvocationTransaction itx) { using (InvokeContractDialog dialog = new InvokeContractDialog(itx)) { if (dialog.ShowDialog() != DialogResult.OK) return; - tx = dialog.GetTransaction(); + tx = dialog.GetTransaction(change_address, fee); } } Helper.SignAndShowInformation(tx); diff --git a/neo-gui/UI/TransferDialog.Designer.cs b/neo-gui/UI/TransferDialog.Designer.cs index 69d4a76f..77e64ebd 100644 --- a/neo-gui/UI/TransferDialog.Designer.cs +++ b/neo-gui/UI/TransferDialog.Designer.cs @@ -34,7 +34,14 @@ private void InitializeComponent() this.txOutListBox1 = new Neo.UI.TxOutListBox(); this.button4 = new System.Windows.Forms.Button(); this.button3 = new System.Windows.Forms.Button(); + this.button2 = new System.Windows.Forms.Button(); + this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.comboBox1 = new System.Windows.Forms.ComboBox(); + this.label2 = new System.Windows.Forms.Label(); + this.textBox1 = new System.Windows.Forms.TextBox(); + this.label1 = new System.Windows.Forms.Label(); this.groupBox3.SuspendLayout(); + this.groupBox1.SuspendLayout(); this.SuspendLayout(); // // groupBox3 @@ -76,10 +83,50 @@ private void InitializeComponent() this.button3.Name = "button3"; this.button3.UseVisualStyleBackColor = true; // + // button2 + // + resources.ApplyResources(this.button2, "button2"); + this.button2.Name = "button2"; + this.button2.UseVisualStyleBackColor = true; + this.button2.Click += new System.EventHandler(this.button2_Click); + // + // groupBox1 + // + resources.ApplyResources(this.groupBox1, "groupBox1"); + this.groupBox1.Controls.Add(this.comboBox1); + this.groupBox1.Controls.Add(this.label2); + this.groupBox1.Controls.Add(this.textBox1); + this.groupBox1.Controls.Add(this.label1); + this.groupBox1.Name = "groupBox1"; + this.groupBox1.TabStop = false; + // + // comboBox1 + // + resources.ApplyResources(this.comboBox1, "comboBox1"); + this.comboBox1.FormattingEnabled = true; + this.comboBox1.Name = "comboBox1"; + // + // label2 + // + resources.ApplyResources(this.label2, "label2"); + this.label2.Name = "label2"; + // + // textBox1 + // + resources.ApplyResources(this.textBox1, "textBox1"); + this.textBox1.Name = "textBox1"; + // + // label1 + // + resources.ApplyResources(this.label1, "label1"); + this.label1.Name = "label1"; + // // TransferDialog // resources.ApplyResources(this, "$this"); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.groupBox1); + this.Controls.Add(this.button2); this.Controls.Add(this.button4); this.Controls.Add(this.button3); this.Controls.Add(this.groupBox3); @@ -88,6 +135,8 @@ private void InitializeComponent() this.Name = "TransferDialog"; this.ShowInTaskbar = false; this.groupBox3.ResumeLayout(false); + this.groupBox1.ResumeLayout(false); + this.groupBox1.PerformLayout(); this.ResumeLayout(false); } @@ -98,5 +147,11 @@ private void InitializeComponent() private System.Windows.Forms.Button button3; private TxOutListBox txOutListBox1; private System.Windows.Forms.Button button1; + private System.Windows.Forms.Button button2; + private System.Windows.Forms.GroupBox groupBox1; + private System.Windows.Forms.TextBox textBox1; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.ComboBox comboBox1; } } \ No newline at end of file diff --git a/neo-gui/UI/TransferDialog.cs b/neo-gui/UI/TransferDialog.cs index 2f3d5948..5b2b073a 100644 --- a/neo-gui/UI/TransferDialog.cs +++ b/neo-gui/UI/TransferDialog.cs @@ -2,6 +2,7 @@ using Neo.Properties; using Neo.SmartContract; using Neo.VM; +using Neo.Wallets; using System; using System.Collections.Generic; using System.Linq; @@ -15,9 +16,15 @@ public partial class TransferDialog : Form { private string remark = ""; + public Fixed8 Fee => Fixed8.Parse(textBox1.Text); + public UInt160 ChangeAddress => Wallet.ToScriptHash((string)comboBox1.SelectedItem); + public TransferDialog() { InitializeComponent(); + textBox1.Text = "0"; + comboBox1.Items.AddRange(Program.CurrentWallet.GetAccounts().Select(p => p.Address).ToArray()); + comboBox1.SelectedItem = Wallet.ToAddress(Program.CurrentWallet.GetChangeAddress()); } public Transaction GetTransaction() @@ -110,7 +117,7 @@ public Transaction GetTransaction() tx.Attributes = attributes.ToArray(); tx.Outputs = txOutListBox1.Items.Where(p => p.AssetId is UInt256).Select(p => p.ToTxOutput()).ToArray(); if (tx is ContractTransaction ctx) - tx = Program.CurrentWallet.MakeTransaction(ctx); + tx = Program.CurrentWallet.MakeTransaction(ctx, ChangeAddress, Fee); return tx; } @@ -123,5 +130,12 @@ private void button1_Click(object sender, EventArgs e) { remark = InputBox.Show(Strings.EnterRemarkMessage, Strings.EnterRemarkTitle, remark); } + + private void button2_Click(object sender, EventArgs e) + { + button2.Visible = false; + groupBox1.Visible = true; + this.Height = 479; + } } } diff --git a/neo-gui/UI/TransferDialog.resx b/neo-gui/UI/TransferDialog.resx index a2b35579..4c9b888c 100644 --- a/neo-gui/UI/TransferDialog.resx +++ b/neo-gui/UI/TransferDialog.resx @@ -119,17 +119,17 @@ - Top, Bottom, Left, Right + Top, Left, Right Bottom, Right - 530, 277 + 530, 258 - 27, 27 + 27, 25 @@ -154,13 +154,13 @@ 微软雅黑, 9pt - 6, 24 + 6, 23 3, 4, 3, 4 - 551, 279 + 551, 260 0 @@ -169,7 +169,7 @@ txOutListBox1 - Neo.UI.TxOutListBox, neo-gui, Version=1.4.6263.35881, Culture=neutral, PublicKeyToken=null + Neo.UI.TxOutListBox, neo-gui, Version=2.5.6556.28018, Culture=neutral, PublicKeyToken=null groupBox3 @@ -178,7 +178,7 @@ 1 - 12, 13 + 12, 12 3, 4, 3, 4 @@ -187,7 +187,7 @@ 3, 4, 3, 4 - 563, 311 + 563, 290 0 @@ -205,13 +205,13 @@ $this - 2 + 4 Bottom, Right - 500, 332 + 500, 310 3, 4, 3, 4 @@ -235,7 +235,7 @@ $this - 0 + 2 Bottom, Right @@ -244,7 +244,7 @@ False - 419, 332 + 419, 310 3, 4, 3, 4 @@ -268,16 +268,172 @@ $this + 3 + + + 12, 311 + + + 75, 23 + + + 3 + + + Advanced + + + button2 + + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + 1 + + Top, Left, Right + + + Top, Left, Right + + + 109, 54 + + + 448, 24 + + + 3 + + + comboBox1 + + + System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + groupBox1 + + + 0 + + + True + + + 6, 57 + + + 97, 16 + + + 2 + + + Change Address: + + + label2 + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + groupBox1 + + + 1 + + + Top, Left, Right + + + 109, 25 + + + 448, 23 + + + 1 + + + textBox1 + + + System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + groupBox1 + + + 2 + + + True + + + 74, 28 + + + 29, 16 + + + 0 + + + Fee: + + + label1 + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + groupBox1 + + + 3 + + + 12, 309 + + + 563, 88 + + + 4 + + + Advanced + + + False + + + groupBox1 + + + System.Windows.Forms.GroupBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 0 + True - 7, 17 + 7, 16 - 587, 368 + 587, 346 微软雅黑, 9pt diff --git a/neo-gui/UI/TransferDialog.zh-Hans.resx b/neo-gui/UI/TransferDialog.zh-Hans.resx index 4d8c66c5..b4f16d1a 100644 --- a/neo-gui/UI/TransferDialog.zh-Hans.resx +++ b/neo-gui/UI/TransferDialog.zh-Hans.resx @@ -126,6 +126,40 @@ 确定 + + 高级 + + + + 80, 54 + + + 477, 24 + + + 68, 16 + + + 找零地址: + + + 80, 25 + + + 477, 23 + + + 18, 28 + + + 56, 16 + + + 手续费: + + + 高级 + 转账 diff --git a/neo-gui/neo-gui.csproj b/neo-gui/neo-gui.csproj index b79f422b..040c5ec6 100644 --- a/neo-gui/neo-gui.csproj +++ b/neo-gui/neo-gui.csproj @@ -170,8 +170,8 @@ ..\packages\Microsoft.Net.Http.Headers.2.0.0\lib\netstandard2.0\Microsoft.Net.Http.Headers.dll - - ..\packages\Neo.2.5.1\lib\net47\Neo.dll + + ..\packages\Neo.2.5.2\lib\net47\Neo.dll ..\packages\Neo.VM.2.0.4\lib\net461\Neo.VM.dll diff --git a/neo-gui/packages.config b/neo-gui/packages.config index 098c80f1..09da0d8c 100644 --- a/neo-gui/packages.config +++ b/neo-gui/packages.config @@ -41,7 +41,7 @@ - +