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

node: Mode system #853

Open
wants to merge 83 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
d1bc7d1
neo-cli: tune MaxTransactionsPerBlock for testnet (#850)
roman-khimov Feb 10, 2022
35269f6
set new network id for testnet
superboyiii Mar 28, 2022
51b5514
revert
superboyiii Mar 28, 2022
2ad44ef
Add new testnet network id (#852)
superboyiii Mar 29, 2022
ab5447d
typo, comment (#847)
Jim8y Mar 31, 2022
8cac90f
create mode folders
Jim8y Apr 3, 2022
c9c3392
privatenet config and commands
Jim8y Apr 3, 2022
029ac42
load mode
Jim8y Apr 7, 2022
d4bb9e4
list mode
Jim8y Apr 7, 2022
11dabc8
delete mode
Jim8y Apr 7, 2022
e86ab46
save mode
Jim8y Apr 7, 2022
c73623b
optimise code
Jim8y Apr 7, 2022
2564839
done with the mode system and added an icon for neo-cli
Jim8y Apr 7, 2022
cbd62b3
fix format
Jim8y Apr 7, 2022
fd1ec20
fix format....well, no idea where the format issue is
Jim8y Apr 7, 2022
7d5ed7f
remove mode file
Jim8y Apr 8, 2022
6427f54
update wallet file
Jim8y Apr 8, 2022
01daf77
save config files in a same folder
Jim8y Apr 8, 2022
8536ff9
code optimise
Jim8y Apr 8, 2022
4f62c33
fix logic
Jim8y Apr 8, 2022
f41de1a
fix format
Jim8y Apr 8, 2022
de3ccd8
optimise code and solve delete issue
Jim8y Apr 8, 2022
6dd88ef
when user install plugin, save the config to the current mode
Jim8y Apr 8, 2022
dd130bb
copy plugin config.json to all modes
Jim8y Apr 9, 2022
27ea359
Update neo-cli/CLI/MainService.Mode.cs
Jim8y Apr 9, 2022
5e0e7f8
Merge branch 'develop' into mode-system
Jim8y Apr 19, 2022
d0c0f30
update mode system
Jim8y May 18, 2022
a89a910
Merge branch 'master' into mode-system
Jim8y May 25, 2022
04c2d42
Merge branch 'master' into mode-system
Jim8y Jun 25, 2022
fedde51
merge master
Jim8y Jul 3, 2022
7aac009
Update neo-cli/CLI/MainService.Mode.cs
Jim8y Jul 14, 2022
817bae6
fix issues as nico comments
Jim8y Jul 14, 2022
7745c8d
minor update
Jim8y Jul 14, 2022
f921835
fix plugin delete issue
Jim8y Jul 15, 2022
e6e225e
Update neo-cli/CLI/MainService.Mode.cs
Jim8y Jul 18, 2022
f3fd7aa
fix path issue
Jim8y Jul 18, 2022
91eb460
fix format
Jim8y Jul 18, 2022
fd9203f
fix plugin name issue
Jim8y Jul 18, 2022
87feb0f
fix config issue while install plugin from the mode
Jim8y Jul 20, 2022
092d546
Merge branch 'master' into mode-system
Jim8y Jul 26, 2022
d30b8d1
add warning info
Jim8y Jul 28, 2022
5894885
stop the node
Jim8y Jul 28, 2022
7e6919c
Merge branch 'master' into mode-system
Jim8y Jul 28, 2022
f83ab4f
rename and remove
Jim8y Jul 28, 2022
9af9e0c
fix async issue
Jim8y Aug 2, 2022
3d44018
Merge branch 'master' into mode-system
Jim8y Aug 9, 2022
13697d7
Merge branch 'master' into mode-system
Jim8y Aug 10, 2022
d38e39e
in case of duplicly install plugin while loading mode
Jim8y Aug 10, 2022
6a1b2ba
Merge branch 'master' into mode-system
Jim8y Aug 18, 2022
dd69999
fix case in path
Jim8y Sep 8, 2022
6a4df34
add plugin file
Jim8y Sep 8, 2022
2a98ccb
on create new mode
Jim8y Sep 8, 2022
f5f6b8a
add oracle mode
Jim8y Sep 8, 2022
e73a42c
try to fix cpytofolder
Jim8y Sep 8, 2022
ef18644
fix mode load issue
Jim8y Sep 8, 2022
ced9cc3
udpate the expect
Jim8y Sep 8, 2022
1056ec2
Revert "udpate the expect"
Jim8y Sep 8, 2022
e33c868
fix plugin name case issue
Jim8y Sep 15, 2022
5dad265
fix plugin name case issue and remove oracle mode
Jim8y Sep 21, 2022
009f802
format check
Jim8y Sep 22, 2022
e79bde9
1. config exists in mode and in mode => move config from mode to plugin
Jim8y Sep 22, 2022
bcad2a0
config.json
Jim8y Sep 22, 2022
86a7174
fix format
Jim8y Oct 10, 2022
0bd73ce
fix expect test
Jim8y Oct 26, 2022
842fc07
fix path issue
Jim8y Oct 26, 2022
3d06822
fix path
Jim8y Oct 27, 2022
2a3e53e
fix privatenet wallet path
Jim8y Oct 27, 2022
f1977f0
fix expect
Jim8y Oct 27, 2022
e12ad2d
Update neo-cli/Modes/privatenet/config.json
Jim8y Oct 27, 2022
6cf1de2
Merge branch 'master' into mode-system
Jim8y Oct 27, 2022
17e009c
Merge branch 'master' into mode-system
Jim8y Oct 27, 2022
cb96042
Update neo-cli/CLI/MainService.Plugins.cs
Jim8y Oct 31, 2022
858a922
Update neo-cli/CLI/MainService.Plugins.cs
Jim8y Oct 31, 2022
9cdedc8
Merge branch 'master' into mode-system
Jim8y Dec 8, 2022
305ab79
Update Helper.cs
shargon Dec 12, 2022
c0cb778
Merge branch 'master' into mode-system
superboyiii Jan 11, 2023
456afc9
Merge branch 'mode-system' of github.com:Liaojinghui/neo-node into mo…
Jim8y Jan 30, 2023
fc27b27
Merge branch 'master' into mode-system
Jim8y Feb 2, 2023
374acf6
Merge branch 'mode-system' of github.com:Liaojinghui/neo-node into mo…
Jim8y Feb 2, 2023
2e07919
update format
Jim8y Feb 2, 2023
9445883
Merge branch 'master' into mode-system
vncoelho Feb 23, 2023
892f2cd
Merge branch 'master' into mode-system
Jim8y Feb 27, 2023
5faefae
Merge branch 'master' into mode-system
Jim8y Aug 10, 2023
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
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
Loading