Skip to content
This repository has been archived by the owner on Feb 15, 2024. It is now read-only.

Commit

Permalink
Feature/advanced transfer (#107)
Browse files Browse the repository at this point in the history
* allow users to add fee to a transaction and set change address

* update dependency: Neo v2.5.2
  • Loading branch information
Erik Zhang committed Dec 14, 2017
1 parent 64db4d4 commit d4162f2
Show file tree
Hide file tree
Showing 8 changed files with 295 additions and 19 deletions.
13 changes: 13 additions & 0 deletions neo-gui/UI/InvokeContractDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 5 additions & 1 deletion neo-gui/UI/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
55 changes: 55 additions & 0 deletions neo-gui/UI/TransferDialog.Designer.cs

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

16 changes: 15 additions & 1 deletion neo-gui/UI/TransferDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}
}
}
Loading

0 comments on commit d4162f2

Please sign in to comment.