Skip to content
This repository has been archived by the owner on Dec 7, 2023. It is now read-only.

Commit

Permalink
sync neo changes (#748)
Browse files Browse the repository at this point in the history
* sync neo changes

* format

* update

Co-authored-by: Shargon <shargon@gmail.com>
  • Loading branch information
Ashuaidehao and shargon authored Feb 21, 2021
1 parent 17666db commit 411be0c
Show file tree
Hide file tree
Showing 14 changed files with 38 additions and 37 deletions.
4 changes: 2 additions & 2 deletions neo-cli/CLI/MainService.Node.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ private void OnShowStateCommand()
uint headerHeight = NeoSystem.HeaderCache.Last?.Index ?? height;

Console.SetCursorPosition(0, 0);
WriteLineWithoutFlicker($"block: {height}/{headerHeight} connected: {localNode.ConnectedCount} unconnected: {localNode.UnconnectedCount}", Console.WindowWidth - 1);
WriteLineWithoutFlicker($"block: {height}/{headerHeight} connected: {LocalNode.ConnectedCount} unconnected: {LocalNode.UnconnectedCount}", Console.WindowWidth - 1);

int linesWritten = 1;
foreach (RemoteNode node in localNode.GetRemoteNodes().OrderByDescending(u => u.LastBlockIndex).Take(Console.WindowHeight - 2).ToArray())
foreach (RemoteNode node in LocalNode.GetRemoteNodes().OrderByDescending(u => u.LastBlockIndex).Take(Console.WindowHeight - 2).ToArray())
{
Console.WriteLine(
$" ip: {node.Remote.Address,-15}\tport: {node.Remote.Port,-5}\tlisten: {node.ListenerTcpPort,-5}\theight: {node.LastBlockIndex,-7}");
Expand Down
4 changes: 2 additions & 2 deletions neo-cli/CLI/MainService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public partial class MainService : ConsoleServiceBase, IWalletProvider
public const long TestModeGas = 20_00000000;

private Wallet currentWallet;
private LocalNode localNode;
public LocalNode LocalNode;

public Wallet CurrentWallet
{
Expand Down Expand Up @@ -354,7 +354,7 @@ public async void Start(string[] args)

NeoSystem.AddService(this);

localNode = await NeoSystem.LocalNode.Ask<LocalNode>(new LocalNode.GetInstance());
LocalNode = await NeoSystem.LocalNode.Ask<LocalNode>(new LocalNode.GetInstance());

foreach (var plugin in Plugin.Plugins)
{
Expand Down
6 changes: 3 additions & 3 deletions neo-gui/GUI/BulkPayDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public BulkPayDialog(AssetDescriptor asset = null)
{
try
{
comboBox1.Items.Add(new AssetDescriptor(assetId));
comboBox1.Items.Add(new AssetDescriptor(Service.NeoSystem.StoreView, Service.NeoSystem.Settings, assetId));
}
catch (ArgumentException)
{
Expand All @@ -44,7 +44,7 @@ public TxOutListBoxItem[] GetOutputs()
AssetName = asset.AssetName,
AssetId = asset.AssetId,
Value = BigDecimal.Parse(line[1], asset.Decimals),
ScriptHash = line[0].ToScriptHash()
ScriptHash = line[0].ToScriptHash(Service.NeoSystem.Settings.AddressVersion)
};
}).Where(p => p.Value.Value != 0).ToArray();
}
Expand All @@ -53,7 +53,7 @@ private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBox1.SelectedItem is AssetDescriptor asset)
{
textBox3.Text = Service.CurrentWallet.GetAvailable(asset.AssetId).ToString();
textBox3.Text = Service.CurrentWallet.GetAvailable(Service.NeoSystem.StoreView, asset.AssetId).ToString();
}
else
{
Expand Down
6 changes: 3 additions & 3 deletions neo-gui/GUI/DeveloperToolsForm.ContractParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
if (listBox1.SelectedIndex < 0) return;
listBox2.Items.Clear();
if (Service.CurrentWallet == null) return;
UInt160 hash = ((string)listBox1.SelectedItem).ToScriptHash();
UInt160 hash = ((string)listBox1.SelectedItem).ToScriptHash(Service.NeoSystem.Settings.AddressVersion);
var parameters = context.GetParameters(hash);
if (parameters == null)
{
Expand Down Expand Up @@ -53,7 +53,7 @@ private void button1_Click(object sender, EventArgs e)
if (string.IsNullOrEmpty(input)) return;
try
{
context = ContractParametersContext.Parse(input);
context = ContractParametersContext.Parse(input, Service.NeoSystem.StoreView);
}
catch (FormatException ex)
{
Expand All @@ -64,7 +64,7 @@ private void button1_Click(object sender, EventArgs e)
listBox2.Items.Clear();
textBox1.Clear();
textBox2.Clear();
listBox1.Items.AddRange(context.ScriptHashes.Select(p => p.ToAddress()).ToArray());
listBox1.Items.AddRange(context.ScriptHashes.Select(p => p.ToAddress(Service.NeoSystem.Settings.AddressVersion)).ToArray());
button2.Enabled = true;
button4.Visible = context.Completed;
}
Expand Down
2 changes: 1 addition & 1 deletion neo-gui/GUI/DeveloperToolsForm.TxBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ private void propertyGrid1_SelectedObjectsChanged(object sender, EventArgs e)
private void button8_Click(object sender, EventArgs e)
{
TransactionWrapper wrapper = (TransactionWrapper)propertyGrid1.SelectedObject;
ContractParametersContext context = new ContractParametersContext(wrapper.Unwrap());
ContractParametersContext context = new ContractParametersContext(Program.Service.NeoSystem.StoreView, wrapper.Unwrap());
InformationBox.Show(context.ToString(), "ParametersContext", "ParametersContext");
}
}
Expand Down
2 changes: 1 addition & 1 deletion neo-gui/GUI/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static void SignAndShowInformation(Transaction tx)
ContractParametersContext context;
try
{
context = new ContractParametersContext(tx);
context = new ContractParametersContext(Service.NeoSystem.StoreView, tx);
}
catch (InvalidOperationException)
{
Expand Down
4 changes: 2 additions & 2 deletions neo-gui/GUI/InvokeContractDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public InvokeContractDialog(byte[] script) : this()
public Transaction GetTransaction()
{
byte[] script = textBox6.Text.Trim().HexToBytes();
return tx ?? Service.CurrentWallet.MakeTransaction(script);
return tx ?? Service.CurrentWallet.MakeTransaction(Service.NeoSystem.StoreView, script);
}

private void UpdateScript()
Expand Down Expand Up @@ -76,7 +76,7 @@ private void button5_Click(object sender, EventArgs e)
Script = script,
Witnesses = new Witness[0]
};
using ApplicationEngine engine = ApplicationEngine.Run(tx_test.Script, container: tx_test);
using ApplicationEngine engine = ApplicationEngine.Run(tx_test.Script, Service.NeoSystem.StoreView, container: tx_test);
StringBuilder sb = new StringBuilder();
sb.AppendLine($"VM State: {engine.State}");
sb.AppendLine($"Gas Consumed: {engine.GasConsumed}");
Expand Down
22 changes: 11 additions & 11 deletions neo-gui/GUI/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public MainForm(XDocument xdoc = null)
{
InitializeComponent();

toolStripProgressBar1.Maximum = (int)Blockchain.TimePerBlock.TotalSeconds;
toolStripProgressBar1.Maximum = (int)Service.NeoSystem.Settings.TimePerBlock.TotalSeconds;

if (xdoc != null)
{
Expand Down Expand Up @@ -150,7 +150,7 @@ private void RefreshConfirmations()
foreach (ListViewItem item in listView3.Items)
{
uint? height = item.Tag as uint?;
int? confirmations = (int)NativeContract.Ledger.CurrentIndex(Blockchain.Singleton.View) - (int?)height + 1;
int? confirmations = (int)NativeContract.Ledger.CurrentIndex(Service.NeoSystem.StoreView) - (int?)height + 1;
if (confirmations <= 0) confirmations = null;
item.SubItems["confirmations"].Text = confirmations?.ToString() ?? Strings.Unconfirmed;
}
Expand All @@ -159,26 +159,26 @@ private void RefreshConfirmations()
private void MainForm_Load(object sender, EventArgs e)
{
actor = Service.NeoSystem.ActorSystem.ActorOf(EventWrapper<Blockchain.PersistCompleted>.Props(Blockchain_PersistCompleted));
Service.WalletOpened += Service_WalletChanged;
Service.WalletChanged += Service_WalletChanged;
}

private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{
if (actor != null)
Service.NeoSystem.ActorSystem.Stop(actor);
Service.WalletOpened -= Service_WalletChanged;
Service.WalletChanged -= Service_WalletChanged;
}

private void timer1_Tick(object sender, EventArgs e)
{
uint height = NativeContract.Ledger.CurrentIndex(Blockchain.Singleton.View);
uint headerHeight = Blockchain.Singleton.HeaderCache.Last?.Index ?? height;
uint height = NativeContract.Ledger.CurrentIndex(Service.NeoSystem.StoreView);
uint headerHeight = Service.NeoSystem.HeaderCache.Last?.Index ?? height;

lbl_height.Text = $"{height}/{headerHeight}";
lbl_count_node.Text = LocalNode.Singleton.ConnectedCount.ToString();
lbl_count_node.Text = Service.LocalNode.ConnectedCount.ToString();
TimeSpan persistence_span = DateTime.UtcNow - persistence_time;
if (persistence_span < TimeSpan.Zero) persistence_span = TimeSpan.Zero;
if (persistence_span > Blockchain.TimePerBlock)
if (persistence_span > Service.NeoSystem.Settings.TimePerBlock)
{
toolStripProgressBar1.Style = ProgressBarStyle.Marquee;
}
Expand All @@ -192,7 +192,7 @@ private void timer1_Tick(object sender, EventArgs e)
check_nep5_balance = false;
UInt160[] addresses = Service.CurrentWallet.GetAccounts().Select(p => p.ScriptHash).ToArray();
if (addresses.Length == 0) return;
using var snapshot = Blockchain.Singleton.GetSnapshot();
using var snapshot = Service.NeoSystem.GetSnapshot();
foreach (UInt160 assetId in NEP5Watched)
{
byte[] script;
Expand All @@ -217,7 +217,7 @@ private void timer1_Tick(object sender, EventArgs e)
symbol = NativeContract.GAS.Symbol;
if (symbol != null)
for (int i = 0; i < addresses.Length; i++)
listView1.Items[addresses[i].ToAddress()].SubItems[symbol].Text = new BigDecimal(balances[i], decimals).ToString();
listView1.Items[addresses[i].ToAddress(Service.NeoSystem.Settings.AddressVersion)].SubItems[symbol].Text = new BigDecimal(balances[i], decimals).ToString();
BigInteger amount = balances.Sum();
if (amount == 0)
{
Expand Down Expand Up @@ -473,7 +473,7 @@ private void importWatchOnlyAddressToolStripMenuItem_Click(object sender, EventA
UInt160 scriptHash;
try
{
scriptHash = address.ToScriptHash();
scriptHash = address.ToScriptHash(Service.NeoSystem.Settings.AddressVersion);
}
catch (FormatException)
{
Expand Down
10 changes: 5 additions & 5 deletions neo-gui/GUI/PayToDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public PayToDialog(AssetDescriptor asset = null, UInt160 scriptHash = null)
{
try
{
comboBox1.Items.Add(new AssetDescriptor(assetId));
comboBox1.Items.Add(new AssetDescriptor(Service.NeoSystem.StoreView, Service.NeoSystem.Settings, assetId));
}
catch (ArgumentException)
{
Expand All @@ -32,7 +32,7 @@ public PayToDialog(AssetDescriptor asset = null, UInt160 scriptHash = null)
}
if (scriptHash != null)
{
textBox1.Text = scriptHash.ToAddress();
textBox1.Text = scriptHash.ToAddress(Service.NeoSystem.Settings.AddressVersion);
textBox1.ReadOnly = true;
}
}
Expand All @@ -45,15 +45,15 @@ public TxOutListBoxItem GetOutput()
AssetName = asset.AssetName,
AssetId = asset.AssetId,
Value = BigDecimal.Parse(textBox2.Text, asset.Decimals),
ScriptHash = textBox1.Text.ToScriptHash()
ScriptHash = textBox1.Text.ToScriptHash(Service.NeoSystem.Settings.AddressVersion)
};
}

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBox1.SelectedItem is AssetDescriptor asset)
{
textBox3.Text = Service.CurrentWallet.GetAvailable(asset.AssetId).ToString();
textBox3.Text = Service.CurrentWallet.GetAvailable(Service.NeoSystem.StoreView, asset.AssetId).ToString();
}
else
{
Expand All @@ -71,7 +71,7 @@ private void textBox_TextChanged(object sender, EventArgs e)
}
try
{
textBox1.Text.ToScriptHash();
textBox1.Text.ToScriptHash(Service.NeoSystem.Settings.AddressVersion);
}
catch (FormatException)
{
Expand Down
4 changes: 2 additions & 2 deletions neo-gui/GUI/SigningTxDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ private void button1_Click(object sender, EventArgs e)
MessageBox.Show(Strings.SigningFailedNoDataMessage);
return;
}
ContractParametersContext context = ContractParametersContext.Parse(textBox1.Text);
ContractParametersContext context = ContractParametersContext.Parse(textBox1.Text, Service.NeoSystem.StoreView);
if (!Service.CurrentWallet.Sign(context))
{
MessageBox.Show(Strings.SigningFailedKeyNotFoundMessage);
Expand All @@ -41,7 +41,7 @@ private void button2_Click(object sender, EventArgs e)

private void button4_Click(object sender, EventArgs e)
{
ContractParametersContext context = ContractParametersContext.Parse(textBox2.Text);
ContractParametersContext context = ContractParametersContext.Parse(textBox2.Text, Service.NeoSystem.StoreView);
if (!(context.Verifiable is Transaction tx))
{
MessageBox.Show("Only support to broadcast transaction.");
Expand Down
4 changes: 2 additions & 2 deletions neo-gui/GUI/TransferDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public TransferDialog()
public Transaction GetTransaction()
{
TransferOutput[] outputs = txOutListBox1.Items.ToArray();
UInt160 from = comboBoxFrom.SelectedItem is null ? null : ((string)comboBoxFrom.SelectedItem).ToScriptHash();
return Service.CurrentWallet.MakeTransaction(outputs, from);
UInt160 from = comboBoxFrom.SelectedItem is null ? null : ((string)comboBoxFrom.SelectedItem).ToScriptHash(Service.NeoSystem.Settings.AddressVersion);
return Service.CurrentWallet.MakeTransaction(Service.NeoSystem.StoreView, outputs, from);
}

private void txOutListBox1_ItemsChanged(object sender, EventArgs e)
Expand Down
2 changes: 1 addition & 1 deletion neo-gui/GUI/TxOutListBoxItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ internal class TxOutListBoxItem : TransferOutput

public override string ToString()
{
return $"{ScriptHash.ToAddress()}\t{Value}\t{AssetName}";
return $"{ScriptHash.ToAddress(Program.Service.NeoSystem.Settings.AddressVersion)}\t{Value}\t{AssetName}";
}
}
}
3 changes: 2 additions & 1 deletion neo-gui/GUI/ViewContractDialog.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Neo.SmartContract;
using System.Linq;
using System.Windows.Forms;
using Neo.Wallets;

namespace Neo.GUI
{
Expand All @@ -9,7 +10,7 @@ public partial class ViewContractDialog : Form
public ViewContractDialog(Contract contract)
{
InitializeComponent();
textBox1.Text = contract.Address;
textBox1.Text = contract.ScriptHash.ToAddress(Program.Service.NeoSystem.Settings.AddressVersion);
textBox2.Text = contract.ScriptHash.ToString();
textBox3.Text = contract.ParameterList.Cast<byte>().ToArray().ToHexString();
textBox4.Text = contract.Script.ToHexString();
Expand Down
2 changes: 1 addition & 1 deletion neo-gui/GUI/VotingDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public VotingDialog(UInt160 script_hash)
{
InitializeComponent();
this.script_hash = script_hash;
label1.Text = script_hash.ToAddress();
label1.Text = script_hash.ToAddress(Program.Service.NeoSystem.Settings.AddressVersion);
}
}
}

0 comments on commit 411be0c

Please sign in to comment.