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

Commit

Permalink
NEO-GUI v2.9.0 (#246)
Browse files Browse the repository at this point in the history
  • Loading branch information
erikzhang authored Sep 14, 2018
1 parent 688bc9f commit c3cbb30
Show file tree
Hide file tree
Showing 42 changed files with 613 additions and 554 deletions.
9 changes: 4 additions & 5 deletions neo-gui/Cryptography/CertificateQueryService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Neo.Core;
using Neo.Properties;
using Neo.Properties;
using Neo.SmartContract;
using Neo.Wallets;
using System;
Expand Down Expand Up @@ -36,7 +35,7 @@ private static void Web_DownloadDataCompleted(object sender, DownloadDataComplet
}
else
{
string address = Wallet.ToAddress(hash);
string address = hash.ToAddress();
string path = Path.Combine(Settings.Default.Paths.CertCache, $"{address}.cer");
File.WriteAllBytes(path, e.Result);
lock (results)
Expand All @@ -59,7 +58,7 @@ public static CertificateQueryResult Query(UInt160 hash)
if (results.ContainsKey(hash)) return results[hash];
results[hash] = new CertificateQueryResult { Type = CertificateQueryResultType.Querying };
}
string address = Wallet.ToAddress(hash);
string address = hash.ToAddress();
string path = Path.Combine(Settings.Default.Paths.CertCache, $"{address}.cer");
if (File.Exists(path))
{
Expand All @@ -80,7 +79,7 @@ public static CertificateQueryResult Query(UInt160 hash)

private static void UpdateResultFromFile(UInt160 hash)
{
string address = Wallet.ToAddress(hash);
string address = hash.ToAddress();
X509Certificate2 cert;
try
{
Expand Down
25 changes: 25 additions & 0 deletions neo-gui/IO/Actors/EventWrapper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Akka.Actor;
using System;

namespace Neo.IO.Actors
{
internal class EventWrapper<T> : UntypedActor
{
private readonly Action<T> callback;

public EventWrapper(Action<T> callback)
{
this.callback = callback;
}

protected override void OnReceive(object message)
{
if (message is T obj) callback(obj);
}

public static Props Props(Action<T> callback)
{
return Akka.Actor.Props.Create(() => new EventWrapper<T>(callback));
}
}
}
21 changes: 4 additions & 17 deletions neo-gui/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Neo.Core;
using Neo.Implementations.Blockchains.LevelDB;
using Neo.Network;
using Neo.Persistence.LevelDB;
using Neo.Properties;
using Neo.UI;
using Neo.Wallets;
Expand All @@ -18,7 +16,7 @@ namespace Neo
{
internal static class Program
{
public static LocalNode LocalNode;
public static NeoSystem NeoSystem;
public static Wallet CurrentWallet;
public static MainForm MainForm;

Expand Down Expand Up @@ -105,22 +103,11 @@ public static void Main()
}
}
if (!InstallCertificate()) return;
const string PeerStatePath = "peers.dat";
if (File.Exists(PeerStatePath))
using (FileStream fs = new FileStream(PeerStatePath, FileMode.Open, FileAccess.Read, FileShare.Read))
{
LocalNode.LoadState(fs);
}
using (Blockchain.RegisterBlockchain(new LevelDBBlockchain(Settings.Default.Paths.Chain)))
using (LocalNode = new LocalNode())
using (LevelDBStore store = new LevelDBStore(Settings.Default.Paths.Chain))
using (NeoSystem = new NeoSystem(store))
{
LocalNode.UpnpEnabled = true;
Application.Run(MainForm = new MainForm(xdoc));
}
using (FileStream fs = new FileStream(PeerStatePath, FileMode.Create, FileAccess.Write, FileShare.None))
{
LocalNode.SaveState(fs);
}
}

private static void PrintErrorLogs(StreamWriter writer, Exception ex)
Expand Down
4 changes: 2 additions & 2 deletions neo-gui/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("neo-gui")]
[assembly: AssemblyCopyright("© The Neo Project 2015-2017 Released under the MIT license")]
[assembly: AssemblyCopyright("© The Neo Project 2015-2018 Released under the MIT license")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand All @@ -30,6 +30,6 @@
//
// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
// 方法是按如下所示使用“*”:
[assembly: AssemblyVersion("2.7.*")]
[assembly: AssemblyVersion("2.9.*")]
//[assembly: AssemblyVersion("1.0.0.0")]
//[assembly: AssemblyFileVersion("1.0.0.0")]
4 changes: 3 additions & 1 deletion neo-gui/Properties/Settings.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Microsoft.Extensions.Configuration;
using Neo.Network;
using Neo.Network.P2P;
using System.Linq;

namespace Neo.Properties
Expand Down Expand Up @@ -30,11 +30,13 @@ public Settings()
internal class PathsSettings
{
public string Chain { get; }
public string Index { get; }
public string CertCache { get; }

public PathsSettings(IConfigurationSection section)
{
this.Chain = string.Format(section.GetSection("Chain").Value, Message.Magic.ToString("X8"));
this.Index = string.Format(section.GetSection("Index").Value, Message.Magic.ToString("X8"));
this.CertCache = section.GetSection("CertCache").Value;
}
}
Expand Down
12 changes: 6 additions & 6 deletions neo-gui/UI/AssetRegisterDialog.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Neo.Core;
using Neo.Cryptography.ECC;
using Neo.Cryptography.ECC;
using Neo.Network.P2P.Payloads;
using Neo.SmartContract;
using Neo.VM;
using Neo.Wallets;
Expand All @@ -24,8 +24,8 @@ public InvocationTransaction GetTransaction()
Fixed8 amount = checkBox1.Checked ? Fixed8.Parse(textBox2.Text) : -Fixed8.Satoshi;
byte precision = (byte)numericUpDown1.Value;
ECPoint owner = (ECPoint)comboBox2.SelectedItem;
UInt160 admin = Wallet.ToScriptHash(comboBox3.Text);
UInt160 issuer = Wallet.ToScriptHash(comboBox4.Text);
UInt160 admin = comboBox3.Text.ToScriptHash();
UInt160 issuer = comboBox4.Text.ToScriptHash();
using (ScriptBuilder sb = new ScriptBuilder())
{
sb.EmitSysCall("Neo.Asset.Create", asset_type, name, amount, precision, owner, admin, issuer);
Expand Down Expand Up @@ -77,8 +77,8 @@ private void CheckForm(object sender, EventArgs e)
{
try
{
Wallet.ToScriptHash(comboBox3.Text);
Wallet.ToScriptHash(comboBox4.Text);
comboBox3.Text.ToScriptHash();
comboBox4.Text.ToScriptHash();
}
catch (FormatException)
{
Expand Down
9 changes: 4 additions & 5 deletions neo-gui/UI/BulkPayDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,20 @@ public TxOutListBoxItem[] GetOutputs()
AssetName = asset.AssetName,
AssetId = asset.AssetId,
Value = BigDecimal.Parse(line[1], asset.Decimals),
ScriptHash = Wallet.ToScriptHash(line[0])
ScriptHash = line[0].ToScriptHash()
};
}).Where(p => p.Value.Value != 0).ToArray();
}

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
AssetDescriptor asset = comboBox1.SelectedItem as AssetDescriptor;
if (asset == null)
if (comboBox1.SelectedItem is AssetDescriptor asset)
{
textBox3.Text = "";
textBox3.Text = Program.CurrentWallet.GetAvailable(asset.AssetId).ToString();
}
else
{
textBox3.Text = Program.CurrentWallet.GetAvailable(asset.AssetId).ToString();
textBox3.Text = "";
}
textBox1_TextChanged(this, EventArgs.Empty);
}
Expand Down
8 changes: 2 additions & 6 deletions neo-gui/UI/CertificateRequestWizard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,11 @@ private void textBox_TextChanged(object sender, EventArgs e)

private void button1_Click(object sender, EventArgs e)
{
const int ECDSA_PRIVATE_P256_MAGIC = 0x32534345;
if (saveFileDialog1.ShowDialog() != DialogResult.OK) return;
KeyPair key = (KeyPair)comboBox1.SelectedItem;
byte[] pubkey = key.PublicKey.EncodePoint(false).Skip(1).ToArray();
byte[] prikey;
using (key.Decrypt())
{
const int ECDSA_PRIVATE_P256_MAGIC = 0x32534345;
prikey = BitConverter.GetBytes(ECDSA_PRIVATE_P256_MAGIC).Concat(BitConverter.GetBytes(32)).Concat(pubkey).Concat(key.PrivateKey).ToArray();
}
byte[] prikey = BitConverter.GetBytes(ECDSA_PRIVATE_P256_MAGIC).Concat(BitConverter.GetBytes(32)).Concat(pubkey).Concat(key.PrivateKey).ToArray();
CX509PrivateKey x509key = new CX509PrivateKey();
x509key.AlgorithmName = "ECDSA_P256";
x509key.Import("ECCPRIVATEBLOB", Convert.ToBase64String(prikey));
Expand Down
64 changes: 38 additions & 26 deletions neo-gui/UI/ClaimForm.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
using Neo.Core;
using Akka.Actor;
using Neo.IO.Actors;
using Neo.Ledger;
using Neo.Network.P2P.Payloads;
using Neo.Persistence;
using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -8,6 +12,8 @@ namespace Neo.UI
{
public partial class ClaimForm : Form
{
private IActorRef actor;

public ClaimForm()
{
InitializeComponent();
Expand All @@ -24,62 +30,68 @@ private void CalculateBonusUnavailable(uint height)

foreach (var group in unspent.GroupBy(p => p.PrevHash))
{
int height_start;
Transaction tx = Blockchain.Default.GetTransaction(group.Key, out height_start);
if (tx == null)
if (!Blockchain.Singleton.ContainsTransaction(group.Key))
continue; // not enough of the chain available
foreach (var reference in group)
references.Add(reference);
}

textBox2.Text = Blockchain.CalculateBonus(references, height).ToString();
using (Snapshot snapshot = Blockchain.Singleton.GetSnapshot())
{
textBox2.Text = snapshot.CalculateBonus(references, height).ToString();
}
}

private void ClaimForm_Load(object sender, EventArgs e)
{
Fixed8 bonus_available = Blockchain.CalculateBonus(Program.CurrentWallet.GetUnclaimedCoins().Select(p => p.Reference));
textBox1.Text = bonus_available.ToString();
if (bonus_available == Fixed8.Zero) button1.Enabled = false;
CalculateBonusUnavailable(Blockchain.Default.Height + 1);
Blockchain.PersistCompleted += Blockchain_PersistCompleted;
using (Snapshot snapshot = Blockchain.Singleton.GetSnapshot())
{
Fixed8 bonus_available = snapshot.CalculateBonus(Program.CurrentWallet.GetUnclaimedCoins().Select(p => p.Reference));
textBox1.Text = bonus_available.ToString();
if (bonus_available == Fixed8.Zero) button1.Enabled = false;
CalculateBonusUnavailable(snapshot.Height + 1);
}
actor = Program.NeoSystem.ActorSystem.ActorOf(EventWrapper<Blockchain.PersistCompleted>.Props(Blockchain_PersistCompleted));
Program.NeoSystem.Blockchain.Tell(new Blockchain.Register(), actor);
}

private void ClaimForm_FormClosing(object sender, FormClosingEventArgs e)
{
Blockchain.PersistCompleted -= Blockchain_PersistCompleted;
Program.NeoSystem.ActorSystem.Stop(actor);
}

private void Blockchain_PersistCompleted(object sender, Block block)
private void Blockchain_PersistCompleted(Blockchain.PersistCompleted e)
{
if (InvokeRequired)
{
BeginInvoke(new Action<object, Block>(Blockchain_PersistCompleted), sender, block);
BeginInvoke(new Action<Blockchain.PersistCompleted>(Blockchain_PersistCompleted), e);
}
else
{
CalculateBonusUnavailable(block.Index + 1);
CalculateBonusUnavailable(e.Block.Index + 1);
}
}

private void button1_Click(object sender, EventArgs e)
{
CoinReference[] claims = Program.CurrentWallet.GetUnclaimedCoins().Select(p => p.Reference).ToArray();
if (claims.Length == 0) return;
Helper.SignAndShowInformation(new ClaimTransaction
{
Claims = claims,
Attributes = new TransactionAttribute[0],
Inputs = new CoinReference[0],
Outputs = new[]
using (Snapshot snapshot = Blockchain.Singleton.GetSnapshot())
Helper.SignAndShowInformation(new ClaimTransaction
{
new TransactionOutput
Claims = claims,
Attributes = new TransactionAttribute[0],
Inputs = new CoinReference[0],
Outputs = new[]
{
AssetId = Blockchain.UtilityToken.Hash,
Value = Blockchain.CalculateBonus(claims),
ScriptHash = Program.CurrentWallet.GetChangeAddress()
new TransactionOutput
{
AssetId = Blockchain.UtilityToken.Hash,
Value = snapshot.CalculateBonus(claims),
ScriptHash = Program.CurrentWallet.GetChangeAddress()
}
}
}
});
});
Close();
}
}
Expand Down
2 changes: 1 addition & 1 deletion neo-gui/UI/ContractDetailsDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ internal partial class ContractDetailsDialog : Form
public ContractDetailsDialog(Contract contract)
{
InitializeComponent();
textBox1.Text = Wallet.ToAddress(contract.ScriptHash);
textBox1.Text = contract.ScriptHash.ToAddress();
textBox2.Text = contract.ScriptHash.ToString();
textBox3.Text = contract.Script.ToHexString();
}
Expand Down
Loading

0 comments on commit c3cbb30

Please sign in to comment.