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

3.2.1 #859

Merged
merged 10 commits into from
Apr 19, 2022
Merged

3.2.1 #859

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# Changelog
All notable changes to this project will be documented in this file.

## [3.2.1]

### Changed
- ([#807](https://github.com/neo-project/neo-node/pull/807/)) Install plugin and dependencies
- ([#850](https://github.com/neo-project/neo-node/pull/850/)) Modify MaxTransactionsPerBlock for testnet
- ([#852](https://github.com/neo-project/neo-node/pull/852/)) Add new testnet network id
- ([#847](https://github.com/neo-project/neo-node/pull/847/)) typo, comment

## [3.1.0]

### Changed
Expand Down
4 changes: 2 additions & 2 deletions Neo.ConsoleService/CommandToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ internal abstract class CommandToken
/// <summary>
/// Value
/// </summary>
public string Value { get; protected set; }
public string Value { get; protected init; }

/// <summary>
/// Constructor
Expand Down Expand Up @@ -152,7 +152,7 @@ public static void Trim(List<CommandToken> args)

// Trim end

while (args.Count > 0 && args[args.Count - 1].Type == CommandTokenType.Space)
while (args.Count > 0 && args[^1].Type == CommandTokenType.Space)
{
args.RemoveAt(args.Count - 1);
}
Expand Down
2 changes: 1 addition & 1 deletion Neo.ConsoleService/ConsoleCommandMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ internal class ConsoleCommandMethod
/// </summary>
/// <param name="instance">Instance</param>
/// <param name="method">Method</param>
/// <param name="verbs">Verbs</param>
/// <param name="attribute">Attribute</param>
public ConsoleCommandMethod(object instance, MethodInfo method, ConsoleCommandAttribute attribute)
{
Method = method;
Expand Down
74 changes: 31 additions & 43 deletions Neo.ConsoleService/ConsoleServiceBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ public abstract class ConsoleServiceBase
public bool ReadingPassword { get; set; } = false;

private bool _running;
private readonly CancellationTokenSource _shutdownTokenSource = new CancellationTokenSource();
private readonly CountdownEvent _shutdownAcknowledged = new CountdownEvent(1);
private readonly Dictionary<string, List<ConsoleCommandMethod>> _verbs = new Dictionary<string, List<ConsoleCommandMethod>>();
private readonly Dictionary<string, object> _instances = new Dictionary<string, object>();
private readonly Dictionary<Type, Func<List<CommandToken>, bool, object>> _handlers = new Dictionary<Type, Func<List<CommandToken>, bool, object>>();
private readonly CancellationTokenSource _shutdownTokenSource = new();
private readonly CountdownEvent _shutdownAcknowledged = new(1);
private readonly Dictionary<string, List<ConsoleCommandMethod>> _verbs = new();
private readonly Dictionary<string, object> _instances = new();
private readonly Dictionary<Type, Func<List<CommandToken>, bool, object>> _handlers = new();

private bool OnCommand(string commandLine)
{
Expand Down Expand Up @@ -188,10 +188,10 @@ protected void OnHelpCommand(string key)

withHelp.Sort((a, b) =>
{
var cate = a.HelpCategory.CompareTo(b.HelpCategory);
var cate = string.Compare(a.HelpCategory, b.HelpCategory, StringComparison.Ordinal);
if (cate == 0)
{
cate = a.Key.CompareTo(b.Key);
cate = string.Compare(a.Key, b.Key, StringComparison.Ordinal);
}
return cate;
});
Expand Down Expand Up @@ -234,7 +234,7 @@ protected void OnHelpCommand(string key)

if (lastKey != command.Key)
{
Console.WriteLine($"You can call this command like this:");
Console.WriteLine("You can call this command like this:");
lastKey = command.Key;
}

Expand All @@ -247,7 +247,7 @@ protected void OnHelpCommand(string key)

if (!found)
{
throw new ArgumentException($"Command not found.");
throw new ArgumentException("Command not found.");
}
}
}
Expand Down Expand Up @@ -297,8 +297,7 @@ public virtual void OnStop()
public string ReadUserInput(string prompt, bool password = false)
{
const string t = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
StringBuilder sb = new StringBuilder();
ConsoleKeyInfo key;
var sb = new StringBuilder();

if (!string.IsNullOrEmpty(prompt))
{
Expand All @@ -316,21 +315,15 @@ public string ReadUserInput(string prompt, bool password = false)
}
else
{
ConsoleKeyInfo key;
do
{
key = Console.ReadKey(true);

if (t.IndexOf(key.KeyChar) != -1)
{
sb.Append(key.KeyChar);
if (password)
{
Console.Write('*');
}
else
{
Console.Write(key.KeyChar);
}
Console.Write(password ? '*' : key.KeyChar);
}
else if (key.Key == ConsoleKey.Backspace && sb.Length > 0)
{
Expand Down Expand Up @@ -411,38 +404,33 @@ protected ConsoleServiceBase()
{
// Register self commands

RegisterCommandHander<string>((args, canConsumeAll) =>
{
return CommandToken.ReadString(args, canConsumeAll);
});
RegisterCommandHandler<string>(CommandToken.ReadString);

RegisterCommandHander<string[]>((args, canConsumeAll) =>
RegisterCommandHandler<string[]>((args, canConsumeAll) =>
{
if (canConsumeAll)
{
var ret = CommandToken.ToString(args);
args.Clear();
return ret.Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries);
}
else
{
return CommandToken.ReadString(args, false).Split(',', ' ');
return ret.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries);
}

return CommandToken.ReadString(args, false).Split(',', ' ');
});

RegisterCommandHander<string, byte>(false, (str) => byte.Parse(str));
RegisterCommandHander<string, bool>(false, (str) => str == "1" || str == "yes" || str == "y" || bool.Parse(str));
RegisterCommandHander<string, ushort>(false, (str) => ushort.Parse(str));
RegisterCommandHander<string, uint>(false, (str) => uint.Parse(str));
RegisterCommandHander<string, IPAddress>(false, (str) => IPAddress.Parse(str));
RegisterCommandHandler<string, byte>(false, str => byte.Parse(str));
RegisterCommandHandler<string, bool>(false, str => str == "1" || str == "yes" || str == "y" || bool.Parse(str));
RegisterCommandHandler<string, ushort>(false, str => ushort.Parse(str));
RegisterCommandHandler<string, uint>(false, str => uint.Parse(str));
RegisterCommandHandler<string, IPAddress>(false, IPAddress.Parse);
}

/// <summary>
/// Register command handler
/// </summary>
/// <typeparam name="TRet">Return type</typeparam>
/// <param name="handler">Handler</param>
private void RegisterCommandHander<TRet>(Func<List<CommandToken>, bool, object> handler)
private void RegisterCommandHandler<TRet>(Func<List<CommandToken>, bool, object> handler)
{
_handlers[typeof(TRet)] = handler;
}
Expand All @@ -454,9 +442,9 @@ private void RegisterCommandHander<TRet>(Func<List<CommandToken>, bool, object>
/// <typeparam name="TRet">Return type</typeparam>
/// <param name="canConsumeAll">Can consume all</param>
/// <param name="handler">Handler</param>
public void RegisterCommandHander<T, TRet>(bool canConsumeAll, Func<T, object> handler)
public void RegisterCommandHandler<T, TRet>(bool canConsumeAll, Func<T, object> handler)
{
_handlers[typeof(TRet)] = (args, cosumeAll) =>
_handlers[typeof(TRet)] = (args, _) =>
{
var value = (T)_handlers[typeof(T)](args, canConsumeAll);
return handler(value);
Expand All @@ -469,11 +457,11 @@ public void RegisterCommandHander<T, TRet>(bool canConsumeAll, Func<T, object> h
/// <typeparam name="T">Base type</typeparam>
/// <typeparam name="TRet">Return type</typeparam>
/// <param name="handler">Handler</param>
public void RegisterCommandHander<T, TRet>(Func<T, object> handler)
public void RegisterCommandHandler<T, TRet>(Func<T, object> handler)
{
_handlers[typeof(TRet)] = (args, cosumeAll) =>
_handlers[typeof(TRet)] = (args, consumeAll) =>
{
var value = (T)_handlers[typeof(T)](args, cosumeAll);
var value = (T)_handlers[typeof(T)](args, consumeAll);
return handler(value);
};
}
Expand All @@ -498,7 +486,7 @@ public void RegisterCommand(object instance, string name = null)

if (!method.GetParameters().All(u => u.ParameterType.IsEnum || _handlers.ContainsKey(u.ParameterType)))
{
throw new ArgumentException("Handler not found for the command: " + method.ToString());
throw new ArgumentException("Handler not found for the command: " + method);
}

// Add command
Expand Down Expand Up @@ -576,7 +564,7 @@ public void Run(string[] args)

protected string ReadLine()
{
Task<string> readLineTask = Task.Run(() => Console.ReadLine());
Task<string> readLineTask = Task.Run(Console.ReadLine);

try
{
Expand Down Expand Up @@ -623,7 +611,7 @@ public virtual void RunConsole()
ConsoleHelper.Error("Command not found");
}
}
catch (TargetInvocationException ex)
catch (TargetInvocationException ex) when (ex.InnerException is not null)
{
ConsoleHelper.Error(ex.InnerException.Message);
}
Expand Down
8 changes: 4 additions & 4 deletions Neo.ConsoleService/ServiceProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@ namespace Neo.ConsoleService
{
internal class ServiceProxy : ServiceBase
{
private readonly ConsoleServiceBase service;
private readonly ConsoleServiceBase _service;

public ServiceProxy(ConsoleServiceBase service)
{
this.service = service;
this._service = service;
}

protected override void OnStart(string[] args)
{
service.OnStart(args);
_service.OnStart(args);
}

protected override void OnStop()
{
service.OnStop();
_service.OnStop();
}
}
}
9 changes: 5 additions & 4 deletions neo-cli/CLI/ConsolePercent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public class ConsolePercent : IDisposable
{
#region Variables

private long _maxValue, _value;
private readonly long _maxValue;
private long _value;
private decimal _lastFactor;
private string _lastPercent;

Expand All @@ -33,7 +34,7 @@ public class ConsolePercent : IDisposable
/// </summary>
public long Value
{
get { return _value; }
get => _value;
set
{
if (value == _value) return;
Expand All @@ -48,8 +49,8 @@ public long Value
/// </summary>
public long MaxValue
{
get { return _maxValue; }
set
get => _maxValue;
init
{
if (value == _maxValue) return;

Expand Down
17 changes: 8 additions & 9 deletions neo-cli/CLI/MainService.Contracts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ partial class MainService
/// </summary>
/// <param name="filePath">File path</param>
/// <param name="manifestPath">Manifest path</param>
/// <param name="data">Extra data for deploy</param>
[ConsoleCommand("deploy", Category = "Contract Commands")]
private void OnDeployCommand(string filePath, string manifestPath = null, JObject data = null)
{
Expand Down Expand Up @@ -57,8 +58,12 @@ private void OnDeployCommand(string filePath, string manifestPath = null, JObjec
/// <summary>
/// Process "update" command
/// </summary>
/// <param name="scriptHash">Script hash</param>
/// <param name="filePath">File path</param>
/// <param name="manifestPath">Manifest path</param>
/// <param name="sender">Sender</param>
/// <param name="signerAccounts">Signer Accounts</param>
/// <param name="data">Extra data for update</param>
[ConsoleCommand("update", Category = "Contract Commands")]
private void OnUpdateCommand(UInt160 scriptHash, string filePath, string manifestPath, UInt160 sender, UInt160[] signerAccounts = null, JObject data = null)
{
Expand All @@ -68,7 +73,7 @@ private void OnUpdateCommand(UInt160 scriptHash, string filePath, string manifes
if (sender != null)
{
if (signerAccounts == null)
signerAccounts = new UInt160[1] { sender };
signerAccounts = new[] { sender };
else if (signerAccounts.Contains(sender) && signerAccounts[0] != sender)
{
var signersList = signerAccounts.ToList();
Expand All @@ -82,13 +87,7 @@ private void OnUpdateCommand(UInt160 scriptHash, string filePath, string manifes
signers = signerAccounts.Select(p => new Signer() { Account = p, Scopes = WitnessScope.CalledByEntry }).ToArray();
}

Transaction tx = new Transaction
{
Signers = signers,
Attributes = Array.Empty<TransactionAttribute>(),
Witnesses = Array.Empty<Witness>()
};

Transaction tx;
try
{
byte[] script = LoadUpdateScript(scriptHash, filePath, manifestPath, data, out var nef, out var manifest);
Expand Down Expand Up @@ -127,7 +126,7 @@ private void OnUpdateCommand(UInt160 scriptHash, string filePath, string manifes
/// <param name="contractParameters">Contract parameters</param>
/// <param name="sender">Transaction's sender</param>
/// <param name="signerAccounts">Signer's accounts</param>
/// <param name="masGas">Max fee for running the script</param>
/// <param name="maxGas">Max fee for running the script</param>
[ConsoleCommand("invoke", Category = "Contract Commands")]
private void OnInvokeCommand(UInt160 scriptHash, string operation, JArray contractParameters = null, UInt160 sender = null, UInt160[] signerAccounts = null, decimal maxGas = 20)
{
Expand Down
18 changes: 11 additions & 7 deletions neo-cli/CLI/MainService.NEP17.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
using Neo.VM.Types;
using Neo.Wallets;
using System;
using System.Collections.Generic;
using System.Linq;
using Array = System.Array;

namespace Neo.CLI
{
Expand All @@ -27,7 +29,7 @@ partial class MainService
/// </summary>
/// <param name="tokenHash">Script hash</param>
/// <param name="to">To</param>
/// <param name="amount">Ammount</param>
/// <param name="amount">Amount</param>
/// <param name="from">From</param>
/// <param name="data">Data</param>
/// <param name="signersAccounts">Signer's accounts</param>
Expand Down Expand Up @@ -58,7 +60,7 @@ private void OnTransferCommand(UInt160 tokenHash, UInt160 to, decimal amount, UI
Scopes = WitnessScope.CalledByEntry,
Account = p
})
.ToArray() ?? new Signer[0]);
.ToArray() ?? Array.Empty<Signer>());
}
catch (InvalidOperationException e)
{
Expand All @@ -80,9 +82,11 @@ private void OnTransferCommand(UInt160 tokenHash, UInt160 to, decimal amount, UI
[ConsoleCommand("balanceOf", Category = "NEP17 Commands")]
private void OnBalanceOfCommand(UInt160 tokenHash, UInt160 address)
{
var arg = new JObject();
arg["type"] = "Hash160";
arg["value"] = address.ToString();
var arg = new JObject
{
["type"] = "Hash160",
["value"] = address.ToString()
};

var asset = new AssetDescriptor(NeoSystem.StoreView, NeoSystem.Settings, tokenHash);

Expand Down Expand Up @@ -113,7 +117,7 @@ private void OnNameCommand(UInt160 tokenHash)
[ConsoleCommand("decimals", Category = "NEP17 Commands")]
private void OnDecimalsCommand(UInt160 tokenHash)
{
if (!OnInvokeWithResult(tokenHash, "decimals", out StackItem result, null)) return;
if (!OnInvokeWithResult(tokenHash, "decimals", out StackItem result)) return;

ConsoleHelper.Info("Result: ", $"{((PrimitiveType)result).GetInteger()}");
}
Expand All @@ -125,7 +129,7 @@ private void OnDecimalsCommand(UInt160 tokenHash)
[ConsoleCommand("totalSupply", Category = "NEP17 Commands")]
private void OnTotalSupplyCommand(UInt160 tokenHash)
{
if (!OnInvokeWithResult(tokenHash, "totalSupply", out StackItem result, null)) return;
if (!OnInvokeWithResult(tokenHash, "totalSupply", out StackItem result)) return;

var asset = new AssetDescriptor(NeoSystem.StoreView, NeoSystem.Settings, tokenHash);
var totalSupply = new BigDecimal(((PrimitiveType)result).GetInteger(), asset.Decimals);
Expand Down
Loading