From f93ce8ff366eb0d6dcdfbe147302db7593e89171 Mon Sep 17 00:00:00 2001 From: Jim8y Date: Fri, 29 Dec 2023 17:52:20 +0800 Subject: [PATCH 01/18] enable command line command --- .../Neo.CLI => config}/config.fs.mainnet.json | 0 .../Neo.CLI => config}/config.fs.testnet.json | 0 {src/Neo.CLI => config}/config.json | 0 {src/Neo.CLI => config}/config.mainnet.json | 0 {src/Neo.CLI => config}/config.testnet.json | 0 src/Neo.CLI/CLI/CommandLineOption.cs | 26 ++++ src/Neo.CLI/CLI/MainService.CommandLine.cs | 120 ++++++++++++++++++ src/Neo.CLI/CLI/MainService.cs | 29 ++--- src/Neo.CLI/Neo.CLI.csproj | 7 +- src/Neo.CLI/Settings.cs | 58 +++++---- src/Neo/ProtocolSettings.cs | 12 +- 11 files changed, 208 insertions(+), 44 deletions(-) rename {src/Neo.CLI => config}/config.fs.mainnet.json (100%) rename {src/Neo.CLI => config}/config.fs.testnet.json (100%) rename {src/Neo.CLI => config}/config.json (100%) rename {src/Neo.CLI => config}/config.mainnet.json (100%) rename {src/Neo.CLI => config}/config.testnet.json (100%) create mode 100644 src/Neo.CLI/CLI/CommandLineOption.cs create mode 100644 src/Neo.CLI/CLI/MainService.CommandLine.cs diff --git a/src/Neo.CLI/config.fs.mainnet.json b/config/config.fs.mainnet.json similarity index 100% rename from src/Neo.CLI/config.fs.mainnet.json rename to config/config.fs.mainnet.json diff --git a/src/Neo.CLI/config.fs.testnet.json b/config/config.fs.testnet.json similarity index 100% rename from src/Neo.CLI/config.fs.testnet.json rename to config/config.fs.testnet.json diff --git a/src/Neo.CLI/config.json b/config/config.json similarity index 100% rename from src/Neo.CLI/config.json rename to config/config.json diff --git a/src/Neo.CLI/config.mainnet.json b/config/config.mainnet.json similarity index 100% rename from src/Neo.CLI/config.mainnet.json rename to config/config.mainnet.json diff --git a/src/Neo.CLI/config.testnet.json b/config/config.testnet.json similarity index 100% rename from src/Neo.CLI/config.testnet.json rename to config/config.testnet.json diff --git a/src/Neo.CLI/CLI/CommandLineOption.cs b/src/Neo.CLI/CLI/CommandLineOption.cs new file mode 100644 index 0000000000..949d4020cb --- /dev/null +++ b/src/Neo.CLI/CLI/CommandLineOption.cs @@ -0,0 +1,26 @@ +// Copyright (C) 2015-2023 The Neo Project. +// +// The Neo.Compiler.CSharp is free software distributed under the MIT +// software license, see the accompanying file LICENSE in the main directory +// of the project or http://www.opensource.org/licenses/mit-license.php +// for more details. +// +// Redistribution and use in source and binary forms with or without +// modifications are permitted. + +#nullable enable + +namespace Neo.CLI +{ + public class CommandLineOptions + { + public string? Config { get; init; } + public string? Network { get; init; } + public string? Wallet { get; init; } + public string? Password { get; init; } + public string[]? Plugins { get; set; } + public string? DBEngine { get; init; } + public string? DBPath { get; init; } + public bool? NoVerify { get; init; } + } +} diff --git a/src/Neo.CLI/CLI/MainService.CommandLine.cs b/src/Neo.CLI/CLI/MainService.CommandLine.cs new file mode 100644 index 0000000000..3c13161370 --- /dev/null +++ b/src/Neo.CLI/CLI/MainService.CommandLine.cs @@ -0,0 +1,120 @@ +// Copyright (C) 2016-2023 The Neo Project. +// +// The neo-cli is free software distributed under the MIT software +// license, see the accompanying file LICENSE in the main directory of +// the project or http://www.opensource.org/licenses/mit-license.php +// for more details. +// +// Redistribution and use in source and binary forms with or without +// modifications are permitted. + +using System; +using System.CommandLine; +using System.CommandLine.Invocation; +using System.CommandLine.NamingConventionBinder; +using System.Reflection; +using Microsoft.Extensions.Configuration; + +namespace Neo.CLI +{ + public partial class MainService + { + private int OnStartWithCommandLine(string[] args) + { + RootCommand rootCommand = new(Assembly.GetExecutingAssembly().GetCustomAttribute()!.Title) + { + new Option(new[] { "-c", "--config","/config" }, "Specifies the config file."), + new Option(new[] { "-n", "--network","/network" }, "Indicates the network of the chain [mainnet, testnet, privnet]."), + new Option(new[] { "-w", "--wallet","/wallet" }, "The path of the neo3 wallet [*.json]."), + new Option(new[] { "-p", "--password" ,"/password" }, "Password to decrypt the wallet, either from the command line or config file."), + new Option(new[] { "--db-engine","/db-engine" }, "Specify the db engine."), + new Option(new[] { "--db-path","/db-path" }, "Specify the db path."), + new Option(new[] { "--noverify","/noverify" }, "Indicates whether the blocks need to be verified when importing."), + new Option(new[] { "--plugins","/plugins" }, "The path of the plugin [plugin1 plugin2]."), + }; + + rootCommand.Handler = CommandHandler.Create(Handle); + return rootCommand.Invoke(args); + } + + private void Handle(RootCommand command, CommandLineOptions options, InvocationContext context) + { + Start(options); + } + + private static void CustomProtocolSettings(CommandLineOptions options, ProtocolSettings settings) + { + uint network = settings.Network; + ProtocolSettings tempSetting = settings; + // if specified network without specifying config, then load the default config + if (!string.IsNullOrEmpty(options.Network)) + { + if (!uint.TryParse(options.Network, out network)) + { + network = options.Network switch + { + "mainnet" => 860833102, + "testnet" => 894710606, + _ => throw new Exception("Invalid network") + }; + } + + // if also specified config, then load the config and check the network + if (!string.IsNullOrEmpty(options.Config)) + { + tempSetting = ProtocolSettings.Load(options.Config); + // the network in config file must match the network from command line + if (network != tempSetting.Network) throw new ArgumentException($"Network mismatch {network} {tempSetting.Network}"); + } + else // if the network if specified without config, then load the default config + { + tempSetting = ProtocolSettings.Load(network == 860833102 ? "config.mainnet.json" : "config.testnet.json"); + } + } + + ProtocolSettings customSetting = new ProtocolSettings + { + Network = network, + AddressVersion = tempSetting.AddressVersion, + StandbyCommittee = tempSetting.StandbyCommittee, + ValidatorsCount = tempSetting.ValidatorsCount, + SeedList = tempSetting.SeedList, + MillisecondsPerBlock = tempSetting.MillisecondsPerBlock, + MaxTransactionsPerBlock = tempSetting.MaxTransactionsPerBlock, + MemoryPoolMaxTransactions = tempSetting.MemoryPoolMaxTransactions, + MaxTraceableBlocks = tempSetting.MaxTraceableBlocks, + InitialGasDistribution = tempSetting.InitialGasDistribution, + Hardforks = tempSetting.Hardforks + }; + + if (!string.IsNullOrEmpty(options.Config) || !string.IsNullOrEmpty(options.Network)) ProtocolSettings.Custom = customSetting; + } + + private static void CustomApplicationSettings(CommandLineOptions options, Settings settings) + { + Settings tempSetting = string.IsNullOrEmpty(options.Config) ? settings : new Settings(new ConfigurationBuilder().AddJsonFile(options.Config, optional: true).Build().GetSection("ApplicationConfiguration")); + + Settings customSetting = new Settings + { + Logger = tempSetting.Logger, + Storage = new StorageSettings + { + Engine = options.DBEngine ?? tempSetting.Storage.Engine, + Path = options.DBPath ?? tempSetting.Storage.Path + }, + P2P = tempSetting.P2P, + UnlockWallet = new UnlockWalletSettings + { + Path = options.Wallet ?? tempSetting.UnlockWallet.Path, + Password = options.Password ?? tempSetting.UnlockWallet.Password + } + }; + if (!string.IsNullOrEmpty(options.Config) + || !string.IsNullOrEmpty(options.Network) + || !string.IsNullOrEmpty(options.DBEngine) + || !string.IsNullOrEmpty(options.DBPath) + || !string.IsNullOrEmpty(options.Wallet) + || !string.IsNullOrEmpty(options.Password)) Settings.Custom = customSetting; + } + } +} diff --git a/src/Neo.CLI/CLI/MainService.cs b/src/Neo.CLI/CLI/MainService.cs index 7beea39310..0ce4a1216b 100644 --- a/src/Neo.CLI/CLI/MainService.cs +++ b/src/Neo.CLI/CLI/MainService.cs @@ -1,10 +1,10 @@ // Copyright (C) 2016-2023 The Neo Project. -// -// The neo-cli is free software distributed under the MIT software +// +// The neo-cli is free software distributed under the MIT software // license, see the accompanying file LICENSE in the main directory of -// the project or http://www.opensource.org/licenses/mit-license.php +// the project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -324,7 +324,8 @@ private byte[] LoadUpdateScript(UInt160 scriptHash, string nefFilePath, string m public override void OnStart(string[] args) { base.OnStart(args); - Start(args); + OnStartWithCommandLine(args); + } public override void OnStop() @@ -343,26 +344,22 @@ public void OpenWallet(string path, string password) CurrentWallet = Wallet.Open(path, password, NeoSystem.Settings) ?? throw new NotSupportedException(); } - public async void Start(string[] args) + public async void Start(CommandLineOptions options) { if (NeoSystem != null) return; - bool verifyImport = true; - for (int i = 0; i < args.Length; i++) - switch (args[i]) - { - case "/noverify": - case "--noverify": - verifyImport = false; - break; - } + bool verifyImport = options.NoVerify ?? true; ProtocolSettings protocol = ProtocolSettings.Load("config.json"); - + CustomProtocolSettings(options, protocol); + CustomApplicationSettings(options, Settings.Default); NeoSystem = new NeoSystem(protocol, Settings.Default.Storage.Engine, string.Format(Settings.Default.Storage.Path, protocol.Network.ToString("X8"))); NeoSystem.AddService(this); LocalNode = NeoSystem.LocalNode.Ask(new LocalNode.GetInstance()).Result; + // installing plugins + options.Plugins?.Select(p => p).Where(p => !string.IsNullOrEmpty(p)).ToList().ForEach(async p => await InstallPluginAsync(p)); + foreach (var plugin in Plugin.Plugins) { // Register plugins commands diff --git a/src/Neo.CLI/Neo.CLI.csproj b/src/Neo.CLI/Neo.CLI.csproj index 19f92a92cc..30903072d9 100644 --- a/src/Neo.CLI/Neo.CLI.csproj +++ b/src/Neo.CLI/Neo.CLI.csproj @@ -15,7 +15,7 @@ - + PreserveNewest PreserveNewest @@ -26,4 +26,9 @@ + + + + + diff --git a/src/Neo.CLI/Settings.cs b/src/Neo.CLI/Settings.cs index ace4cb4863..b89383a3d1 100644 --- a/src/Neo.CLI/Settings.cs +++ b/src/Neo.CLI/Settings.cs @@ -1,10 +1,10 @@ // Copyright (C) 2016-2023 The Neo Project. -// -// The neo-cli is free software distributed under the MIT software +// +// The neo-cli is free software distributed under the MIT software // license, see the accompanying file LICENSE in the main directory of -// the project or http://www.opensource.org/licenses/mit-license.php +// the project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -16,10 +16,10 @@ namespace Neo { public class Settings { - public LoggerSettings Logger { get; } - public StorageSettings Storage { get; } - public P2PSettings P2P { get; } - public UnlockWalletSettings UnlockWallet { get; } + public LoggerSettings Logger { get; init; } + public StorageSettings Storage { get; init; } + public P2PSettings P2P { get; init; } + public UnlockWalletSettings UnlockWallet { get; init; } static Settings _default; @@ -44,10 +44,12 @@ public static Settings Default Initialize(config); } - return _default; + return Custom ?? _default; } } + public static Settings? Custom { get; set; } + public Settings(IConfigurationSection section) { this.Logger = new LoggerSettings(section.GetSection("Logger")); @@ -55,13 +57,17 @@ public Settings(IConfigurationSection section) this.P2P = new P2PSettings(section.GetSection("P2P")); this.UnlockWallet = new UnlockWalletSettings(section.GetSection("UnlockWallet")); } + + public Settings() + { + } } public class LoggerSettings { - public string Path { get; } - public bool ConsoleOutput { get; } - public bool Active { get; } + public string Path { get; init; } + public bool ConsoleOutput { get; init; } + public bool Active { get; init; } public LoggerSettings(IConfigurationSection section) { @@ -73,23 +79,27 @@ public LoggerSettings(IConfigurationSection section) public class StorageSettings { - public string Engine { get; } - public string Path { get; } + public string Engine { get; init; } + public string Path { get; init; } public StorageSettings(IConfigurationSection section) { this.Engine = section.GetValue("Engine", "LevelDBStore"); this.Path = section.GetValue("Path", "Data_LevelDB_{0}"); } + + public StorageSettings() + { + } } public class P2PSettings { - public ushort Port { get; } - public ushort WsPort { get; } - public int MinDesiredConnections { get; } - public int MaxConnections { get; } - public int MaxConnectionsPerAddress { get; } + public ushort Port { get; init; } + public ushort WsPort { get; init; } + public int MinDesiredConnections { get; init; } + public int MaxConnections { get; init; } + public int MaxConnectionsPerAddress { get; init; } public P2PSettings(IConfigurationSection section) { @@ -103,9 +113,9 @@ public P2PSettings(IConfigurationSection section) public class UnlockWalletSettings { - public string Path { get; } - public string Password { get; } - public bool IsActive { get; } + public string Path { get; init; } + public string Password { get; init; } + public bool IsActive { get; init; } public UnlockWalletSettings(IConfigurationSection section) { @@ -116,5 +126,9 @@ public UnlockWalletSettings(IConfigurationSection section) this.IsActive = bool.Parse(section.GetValue("IsActive", "false")); } } + + public UnlockWalletSettings() + { + } } } diff --git a/src/Neo/ProtocolSettings.cs b/src/Neo/ProtocolSettings.cs index 74807e4d97..f948c801f4 100644 --- a/src/Neo/ProtocolSettings.cs +++ b/src/Neo/ProtocolSettings.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2022 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -102,7 +102,7 @@ public record ProtocolSettings /// /// The default protocol settings for NEO MainNet. /// - public static ProtocolSettings Default { get; } = new ProtocolSettings + public static ProtocolSettings Default { get; } = Custom ?? new ProtocolSettings { Network = 0u, AddressVersion = 0x35, @@ -117,6 +117,8 @@ public record ProtocolSettings Hardforks = ImmutableDictionary.Empty }; + public static ProtocolSettings? Custom { get; set; } + /// /// Loads the at the specified path. /// From 86137ae8620fa69d6574fe46514260c6d149ba32 Mon Sep 17 00:00:00 2001 From: Jim8y Date: Fri, 29 Dec 2023 18:12:22 +0800 Subject: [PATCH 02/18] fix GUI --- src/Neo.CLI/CLI/MainService.CommandLine.cs | 2 +- src/Neo.GUI/Program.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Neo.CLI/CLI/MainService.CommandLine.cs b/src/Neo.CLI/CLI/MainService.CommandLine.cs index 3c13161370..ad03a9b414 100644 --- a/src/Neo.CLI/CLI/MainService.CommandLine.cs +++ b/src/Neo.CLI/CLI/MainService.CommandLine.cs @@ -19,7 +19,7 @@ namespace Neo.CLI { public partial class MainService { - private int OnStartWithCommandLine(string[] args) + public int OnStartWithCommandLine(string[] args) { RootCommand rootCommand = new(Assembly.GetExecutingAssembly().GetCustomAttribute()!.Title) { diff --git a/src/Neo.GUI/Program.cs b/src/Neo.GUI/Program.cs index f872706ff5..9d5cf35fd7 100644 --- a/src/Neo.GUI/Program.cs +++ b/src/Neo.GUI/Program.cs @@ -67,7 +67,7 @@ static void Main(string[] args) return; } } - Service.Start(args); + Service.OnStartWithCommandLine(args); Application.Run(MainForm = new MainForm(xdoc)); Service.Stop(); } From cef330efb069c22cd9ea5982d8b76157dbc8cecb Mon Sep 17 00:00:00 2001 From: Jim8y Date: Wed, 10 Jan 2024 19:12:41 +0800 Subject: [PATCH 03/18] update format --- src/Neo.CLI/CLI/CommandLineOption.cs | 9 +++++---- src/Neo.CLI/CLI/MainService.CommandLine.cs | 11 ++++++----- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/Neo.CLI/CLI/CommandLineOption.cs b/src/Neo.CLI/CLI/CommandLineOption.cs index 949d4020cb..a784708ca4 100644 --- a/src/Neo.CLI/CLI/CommandLineOption.cs +++ b/src/Neo.CLI/CLI/CommandLineOption.cs @@ -1,8 +1,9 @@ -// Copyright (C) 2015-2023 The Neo Project. +// Copyright (C) 2015-2024 The Neo Project. // -// The Neo.Compiler.CSharp is free software distributed under the MIT -// software license, see the accompanying file LICENSE in the main directory -// of the project or http://www.opensource.org/licenses/mit-license.php +// CommandLineOption.cs file belongs to the neo project and is free +// software distributed under the MIT software license, see the +// accompanying file LICENSE in the main directory of the +// repository or http://www.opensource.org/licenses/mit-license.php // for more details. // // Redistribution and use in source and binary forms with or without diff --git a/src/Neo.CLI/CLI/MainService.CommandLine.cs b/src/Neo.CLI/CLI/MainService.CommandLine.cs index 9090055c6d..f224e1433a 100644 --- a/src/Neo.CLI/CLI/MainService.CommandLine.cs +++ b/src/Neo.CLI/CLI/MainService.CommandLine.cs @@ -1,19 +1,20 @@ -// Copyright (C) 2016-2023 The Neo Project. +// Copyright (C) 2015-2024 The Neo Project. // -// The neo-cli is free software distributed under the MIT software -// license, see the accompanying file LICENSE in the main directory of -// the project or http://www.opensource.org/licenses/mit-license.php +// MainService.CommandLine.cs file belongs to the neo project and is free +// software distributed under the MIT software license, see the +// accompanying file LICENSE in the main directory of the +// repository or http://www.opensource.org/licenses/mit-license.php // for more details. // // Redistribution and use in source and binary forms with or without // modifications are permitted. +using Microsoft.Extensions.Configuration; using System; using System.CommandLine; using System.CommandLine.Invocation; using System.CommandLine.NamingConventionBinder; using System.Reflection; -using Microsoft.Extensions.Configuration; namespace Neo.CLI { From 502b154fe8fdcef05b327c53e7d2e4e6af259075 Mon Sep 17 00:00:00 2001 From: Jim8y Date: Thu, 11 Jan 2024 10:34:52 +0800 Subject: [PATCH 04/18] remove network config --- src/Neo.CLI/CLI/CommandLineOption.cs | 1 - src/Neo.CLI/CLI/MainService.CommandLine.cs | 34 ++++------------------ 2 files changed, 5 insertions(+), 30 deletions(-) diff --git a/src/Neo.CLI/CLI/CommandLineOption.cs b/src/Neo.CLI/CLI/CommandLineOption.cs index a784708ca4..f1ba958eeb 100644 --- a/src/Neo.CLI/CLI/CommandLineOption.cs +++ b/src/Neo.CLI/CLI/CommandLineOption.cs @@ -16,7 +16,6 @@ namespace Neo.CLI public class CommandLineOptions { public string? Config { get; init; } - public string? Network { get; init; } public string? Wallet { get; init; } public string? Password { get; init; } public string[]? Plugins { get; set; } diff --git a/src/Neo.CLI/CLI/MainService.CommandLine.cs b/src/Neo.CLI/CLI/MainService.CommandLine.cs index f224e1433a..bd393ace28 100644 --- a/src/Neo.CLI/CLI/MainService.CommandLine.cs +++ b/src/Neo.CLI/CLI/MainService.CommandLine.cs @@ -25,7 +25,6 @@ public int OnStartWithCommandLine(string[] args) RootCommand rootCommand = new(Assembly.GetExecutingAssembly().GetCustomAttribute()!.Title) { new Option(new[] { "-c", "--config","/config" }, "Specifies the config file."), - new Option(new[] { "-n", "--network","/network" }, "Indicates the network of the chain [mainnet, testnet, privnet]."), new Option(new[] { "-w", "--wallet","/wallet" }, "The path of the neo3 wallet [*.json]."), new Option(new[] { "-p", "--password" ,"/password" }, "Password to decrypt the wallet, either from the command line or config file."), new Option(new[] { "--db-engine","/db-engine" }, "Specify the db engine."), @@ -45,37 +44,16 @@ private void Handle(RootCommand command, CommandLineOptions options, InvocationC private static void CustomProtocolSettings(CommandLineOptions options, ProtocolSettings settings) { - uint network = settings.Network; ProtocolSettings tempSetting = settings; - // if specified network without specifying config, then load the default config - if (!string.IsNullOrEmpty(options.Network)) + // if specified config, then load the config and check the network + if (!string.IsNullOrEmpty(options.Config)) { - if (!uint.TryParse(options.Network, out network)) - { - network = options.Network switch - { - "mainnet" => 860833102, - "testnet" => 894710606, - _ => throw new Exception("Invalid network") - }; - } - - // if also specified config, then load the config and check the network - if (!string.IsNullOrEmpty(options.Config)) - { - tempSetting = ProtocolSettings.Load(options.Config); - // the network in config file must match the network from command line - if (network != tempSetting.Network) throw new ArgumentException($"Network mismatch {network} {tempSetting.Network}"); - } - else // if the network if specified without config, then load the default config - { - tempSetting = ProtocolSettings.Load(network == 860833102 ? "config.mainnet.json" : "config.testnet.json"); - } + tempSetting = ProtocolSettings.Load(options.Config); } ProtocolSettings customSetting = new ProtocolSettings { - Network = network, + Network = tempSetting.Network, AddressVersion = tempSetting.AddressVersion, StandbyCommittee = tempSetting.StandbyCommittee, ValidatorsCount = tempSetting.ValidatorsCount, @@ -88,13 +66,12 @@ private static void CustomProtocolSettings(CommandLineOptions options, ProtocolS Hardforks = tempSetting.Hardforks }; - if (!string.IsNullOrEmpty(options.Config) || !string.IsNullOrEmpty(options.Network)) ProtocolSettings.Custom = customSetting; + if (!string.IsNullOrEmpty(options.Config)) ProtocolSettings.Custom = customSetting; } private static void CustomApplicationSettings(CommandLineOptions options, Settings settings) { Settings tempSetting = string.IsNullOrEmpty(options.Config) ? settings : new Settings(new ConfigurationBuilder().AddJsonFile(options.Config, optional: true).Build().GetSection("ApplicationConfiguration")); - Settings customSetting = new Settings { Logger = tempSetting.Logger, @@ -111,7 +88,6 @@ private static void CustomApplicationSettings(CommandLineOptions options, Settin } }; if (!string.IsNullOrEmpty(options.Config) - || !string.IsNullOrEmpty(options.Network) || !string.IsNullOrEmpty(options.DBEngine) || !string.IsNullOrEmpty(options.DBPath) || !string.IsNullOrEmpty(options.Wallet) From a90b401a4e39131ac114c9d3203bf131d4624112 Mon Sep 17 00:00:00 2001 From: Fernando Diaz Toledano Date: Thu, 11 Jan 2024 08:12:20 +0100 Subject: [PATCH 05/18] Fix conflicts --- src/Neo.CLI/Settings.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Neo.CLI/Settings.cs b/src/Neo.CLI/Settings.cs index eacfd85ea2..35f0de202f 100644 --- a/src/Neo.CLI/Settings.cs +++ b/src/Neo.CLI/Settings.cs @@ -111,9 +111,9 @@ public P2PSettings(IConfigurationSection section) public class UnlockWalletSettings { - public string? Path { get; } = string.Empty; - public string? Password { get; } = string.Empty; - public bool IsActive { get; } = false; + public string? Path { get; init; } = string.Empty; + public string? Password { get; init; } = string.Empty; + public bool IsActive { get; init; } = false; public UnlockWalletSettings(IConfigurationSection section) { From 9b06a1bd25085bf320d26707da5ebf3ccc1ae095 Mon Sep 17 00:00:00 2001 From: Fernando Diaz Toledano Date: Thu, 11 Jan 2024 08:21:58 +0100 Subject: [PATCH 06/18] Remove Settings messages --- src/Neo.CLI/Settings.cs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/Neo.CLI/Settings.cs b/src/Neo.CLI/Settings.cs index 35f0de202f..e6159b925e 100644 --- a/src/Neo.CLI/Settings.cs +++ b/src/Neo.CLI/Settings.cs @@ -60,12 +60,16 @@ public Settings(IConfigurationSection section) public Settings() { + Logger = new LoggerSettings(); + Storage = new StorageSettings(); + P2P = new P2PSettings(); + UnlockWallet = new UnlockWalletSettings(); } } public class LoggerSettings { - public string Path { get; init; } + public string Path { get; init; } = string.Empty; public bool ConsoleOutput { get; init; } public bool Active { get; init; } @@ -75,6 +79,8 @@ public LoggerSettings(IConfigurationSection section) ConsoleOutput = section.GetValue(nameof(ConsoleOutput), false); Active = section.GetValue(nameof(Active), false); } + + public LoggerSettings() { } } public class StorageSettings @@ -88,9 +94,7 @@ public StorageSettings(IConfigurationSection section) Path = section.GetValue(nameof(Path), "Data_LevelDB_{0}")!; } - public StorageSettings() - { - } + public StorageSettings() { } } public class P2PSettings @@ -107,6 +111,8 @@ public P2PSettings(IConfigurationSection section) MaxConnections = section.GetValue(nameof(MaxConnections), Peer.DefaultMaxConnections); MaxConnectionsPerAddress = section.GetValue(nameof(MaxConnectionsPerAddress), 3); } + + public P2PSettings() { } } public class UnlockWalletSettings @@ -125,8 +131,6 @@ public UnlockWalletSettings(IConfigurationSection section) } } - public UnlockWalletSettings() - { - } + public UnlockWalletSettings() { } } } From af5dc0ef99c03203365b9bbaab591c3da04b3a4c Mon Sep 17 00:00:00 2001 From: Fernando Diaz Toledano Date: Thu, 11 Jan 2024 08:29:11 +0100 Subject: [PATCH 07/18] My review --- src/Neo.CLI/CLI/CommandLineOption.cs | 13 +++++++++++-- src/Neo.CLI/CLI/MainService.CommandLine.cs | 16 ++++++---------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/Neo.CLI/CLI/CommandLineOption.cs b/src/Neo.CLI/CLI/CommandLineOption.cs index f1ba958eeb..e82a9a0540 100644 --- a/src/Neo.CLI/CLI/CommandLineOption.cs +++ b/src/Neo.CLI/CLI/CommandLineOption.cs @@ -9,8 +9,6 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -#nullable enable - namespace Neo.CLI { public class CommandLineOptions @@ -22,5 +20,16 @@ public class CommandLineOptions public string? DBEngine { get; init; } public string? DBPath { get; init; } public bool? NoVerify { get; init; } + + /// + /// Check if CommandLineOptions was configured + /// + public bool IsValid => + !string.IsNullOrEmpty(Config) || + !string.IsNullOrEmpty(Wallet) || + !string.IsNullOrEmpty(Password) || + !string.IsNullOrEmpty(DBEngine) || + !string.IsNullOrEmpty(DBPath) || + (Plugins?.Length > 0); } } diff --git a/src/Neo.CLI/CLI/MainService.CommandLine.cs b/src/Neo.CLI/CLI/MainService.CommandLine.cs index bd393ace28..6a83fa93de 100644 --- a/src/Neo.CLI/CLI/MainService.CommandLine.cs +++ b/src/Neo.CLI/CLI/MainService.CommandLine.cs @@ -30,7 +30,7 @@ public int OnStartWithCommandLine(string[] args) new Option(new[] { "--db-engine","/db-engine" }, "Specify the db engine."), new Option(new[] { "--db-path","/db-path" }, "Specify the db path."), new Option(new[] { "--noverify","/noverify" }, "Indicates whether the blocks need to be verified when importing."), - new Option(new[] { "--plugins","/plugins" }, "The list of the plugins [plugin1 plugin2]."), + new Option(new[] { "--plugins","/plugins" }, "The list of plugins, if not present, will be installed [plugin1 plugin2]."), }; rootCommand.Handler = CommandHandler.Create(Handle); @@ -44,14 +44,14 @@ private void Handle(RootCommand command, CommandLineOptions options, InvocationC private static void CustomProtocolSettings(CommandLineOptions options, ProtocolSettings settings) { - ProtocolSettings tempSetting = settings; + var tempSetting = settings; // if specified config, then load the config and check the network if (!string.IsNullOrEmpty(options.Config)) { tempSetting = ProtocolSettings.Load(options.Config); } - ProtocolSettings customSetting = new ProtocolSettings + var customSetting = new ProtocolSettings { Network = tempSetting.Network, AddressVersion = tempSetting.AddressVersion, @@ -71,8 +71,8 @@ private static void CustomProtocolSettings(CommandLineOptions options, ProtocolS private static void CustomApplicationSettings(CommandLineOptions options, Settings settings) { - Settings tempSetting = string.IsNullOrEmpty(options.Config) ? settings : new Settings(new ConfigurationBuilder().AddJsonFile(options.Config, optional: true).Build().GetSection("ApplicationConfiguration")); - Settings customSetting = new Settings + var tempSetting = string.IsNullOrEmpty(options.Config) ? settings : new Settings(new ConfigurationBuilder().AddJsonFile(options.Config, optional: true).Build().GetSection("ApplicationConfiguration")); + var customSetting = new Settings { Logger = tempSetting.Logger, Storage = new StorageSettings @@ -87,11 +87,7 @@ private static void CustomApplicationSettings(CommandLineOptions options, Settin Password = options.Password ?? tempSetting.UnlockWallet.Password } }; - if (!string.IsNullOrEmpty(options.Config) - || !string.IsNullOrEmpty(options.DBEngine) - || !string.IsNullOrEmpty(options.DBPath) - || !string.IsNullOrEmpty(options.Wallet) - || !string.IsNullOrEmpty(options.Password)) Settings.Custom = customSetting; + if (options.IsValid) Settings.Custom = customSetting; } } } From b0f9a2231e06e76aaad52066540224c0d578b0e0 Mon Sep 17 00:00:00 2001 From: Fernando Diaz Toledano Date: Thu, 11 Jan 2024 08:30:08 +0100 Subject: [PATCH 08/18] Add NoVerify check in IsValid --- src/Neo.CLI/CLI/CommandLineOption.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Neo.CLI/CLI/CommandLineOption.cs b/src/Neo.CLI/CLI/CommandLineOption.cs index e82a9a0540..617856cee9 100644 --- a/src/Neo.CLI/CLI/CommandLineOption.cs +++ b/src/Neo.CLI/CLI/CommandLineOption.cs @@ -30,6 +30,7 @@ public class CommandLineOptions !string.IsNullOrEmpty(Password) || !string.IsNullOrEmpty(DBEngine) || !string.IsNullOrEmpty(DBPath) || - (Plugins?.Length > 0); + (Plugins?.Length > 0) || + NoVerify is not null; } } From 392ba5840b505f2032fddf736993789b90638157 Mon Sep 17 00:00:00 2001 From: Fernando Diaz Toledano Date: Thu, 11 Jan 2024 08:32:21 +0100 Subject: [PATCH 09/18] Clean using --- src/Neo.CLI/CLI/MainService.CommandLine.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Neo.CLI/CLI/MainService.CommandLine.cs b/src/Neo.CLI/CLI/MainService.CommandLine.cs index 6a83fa93de..1edc80b1ab 100644 --- a/src/Neo.CLI/CLI/MainService.CommandLine.cs +++ b/src/Neo.CLI/CLI/MainService.CommandLine.cs @@ -10,7 +10,6 @@ // modifications are permitted. using Microsoft.Extensions.Configuration; -using System; using System.CommandLine; using System.CommandLine.Invocation; using System.CommandLine.NamingConventionBinder; From f6471cf1036f7e8e7730b290d0cb4bddc3cfebbe Mon Sep 17 00:00:00 2001 From: Jim8y Date: Thu, 11 Jan 2024 21:01:11 +0800 Subject: [PATCH 10/18] format --- src/Neo.CLI/Settings.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Neo.CLI/Settings.cs b/src/Neo.CLI/Settings.cs index c4c34edc48..33dcaf077a 100644 --- a/src/Neo.CLI/Settings.cs +++ b/src/Neo.CLI/Settings.cs @@ -22,7 +22,7 @@ public class Settings public StorageSettings Storage { get; init; } public P2PSettings P2P { get; init; } public UnlockWalletSettings UnlockWallet { get; init; } - public ContractsSettings Contracts { get; init;} + public ContractsSettings Contracts { get; init; } static Settings? s_default; From 7d54c5dfd9ababb663f41955fa5d116d4469fcba Mon Sep 17 00:00:00 2001 From: Jim8y Date: Thu, 11 Jan 2024 21:02:47 +0800 Subject: [PATCH 11/18] move config --- {src/Neo.CLI => config}/config.fs.mainnet.json | 0 {src/Neo.CLI => config}/config.fs.testnet.json | 0 {src/Neo.CLI => config}/config.json | 0 {src/Neo.CLI => config}/config.mainnet.json | 0 {src/Neo.CLI => config}/config.testnet.json | 0 5 files changed, 0 insertions(+), 0 deletions(-) rename {src/Neo.CLI => config}/config.fs.mainnet.json (100%) rename {src/Neo.CLI => config}/config.fs.testnet.json (100%) rename {src/Neo.CLI => config}/config.json (100%) rename {src/Neo.CLI => config}/config.mainnet.json (100%) rename {src/Neo.CLI => config}/config.testnet.json (100%) diff --git a/src/Neo.CLI/config.fs.mainnet.json b/config/config.fs.mainnet.json similarity index 100% rename from src/Neo.CLI/config.fs.mainnet.json rename to config/config.fs.mainnet.json diff --git a/src/Neo.CLI/config.fs.testnet.json b/config/config.fs.testnet.json similarity index 100% rename from src/Neo.CLI/config.fs.testnet.json rename to config/config.fs.testnet.json diff --git a/src/Neo.CLI/config.json b/config/config.json similarity index 100% rename from src/Neo.CLI/config.json rename to config/config.json diff --git a/src/Neo.CLI/config.mainnet.json b/config/config.mainnet.json similarity index 100% rename from src/Neo.CLI/config.mainnet.json rename to config/config.mainnet.json diff --git a/src/Neo.CLI/config.testnet.json b/config/config.testnet.json similarity index 100% rename from src/Neo.CLI/config.testnet.json rename to config/config.testnet.json From a4c760d0a76c7c59869c0119d074252e567c21ed Mon Sep 17 00:00:00 2001 From: Jim8y Date: Thu, 11 Jan 2024 21:03:37 +0800 Subject: [PATCH 12/18] Revert "move config" This reverts commit 7d54c5dfd9ababb663f41955fa5d116d4469fcba. --- {config => src/Neo.CLI}/config.fs.mainnet.json | 0 {config => src/Neo.CLI}/config.fs.testnet.json | 0 {config => src/Neo.CLI}/config.json | 0 {config => src/Neo.CLI}/config.mainnet.json | 0 {config => src/Neo.CLI}/config.testnet.json | 0 5 files changed, 0 insertions(+), 0 deletions(-) rename {config => src/Neo.CLI}/config.fs.mainnet.json (100%) rename {config => src/Neo.CLI}/config.fs.testnet.json (100%) rename {config => src/Neo.CLI}/config.json (100%) rename {config => src/Neo.CLI}/config.mainnet.json (100%) rename {config => src/Neo.CLI}/config.testnet.json (100%) diff --git a/config/config.fs.mainnet.json b/src/Neo.CLI/config.fs.mainnet.json similarity index 100% rename from config/config.fs.mainnet.json rename to src/Neo.CLI/config.fs.mainnet.json diff --git a/config/config.fs.testnet.json b/src/Neo.CLI/config.fs.testnet.json similarity index 100% rename from config/config.fs.testnet.json rename to src/Neo.CLI/config.fs.testnet.json diff --git a/config/config.json b/src/Neo.CLI/config.json similarity index 100% rename from config/config.json rename to src/Neo.CLI/config.json diff --git a/config/config.mainnet.json b/src/Neo.CLI/config.mainnet.json similarity index 100% rename from config/config.mainnet.json rename to src/Neo.CLI/config.mainnet.json diff --git a/config/config.testnet.json b/src/Neo.CLI/config.testnet.json similarity index 100% rename from config/config.testnet.json rename to src/Neo.CLI/config.testnet.json From 39092613730f3653c4b7ec96a3538dc765a70786 Mon Sep 17 00:00:00 2001 From: Jim8y Date: Thu, 11 Jan 2024 21:04:09 +0800 Subject: [PATCH 13/18] fix config --- src/Neo.CLI/Neo.CLI.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Neo.CLI/Neo.CLI.csproj b/src/Neo.CLI/Neo.CLI.csproj index ebb4a5d624..0fa76ee2c9 100644 --- a/src/Neo.CLI/Neo.CLI.csproj +++ b/src/Neo.CLI/Neo.CLI.csproj @@ -21,7 +21,7 @@ - + PreserveNewest PreserveNewest From b530d500f78de55b9c3dfd7bb8122d1b2f204445 Mon Sep 17 00:00:00 2001 From: Jim8y Date: Thu, 11 Jan 2024 21:24:13 +0800 Subject: [PATCH 14/18] update plugins install command --- src/Neo.CLI/CLI/MainService.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Neo.CLI/CLI/MainService.cs b/src/Neo.CLI/CLI/MainService.cs index 38d5ca83d8..902ba1dd80 100644 --- a/src/Neo.CLI/CLI/MainService.cs +++ b/src/Neo.CLI/CLI/MainService.cs @@ -35,6 +35,7 @@ using System.Reflection; using System.Text.RegularExpressions; using System.Threading; +using System.Threading.Tasks; using Array = System.Array; namespace Neo.CLI @@ -381,8 +382,11 @@ public async void Start(CommandLineOptions options) LocalNode = NeoSystem.LocalNode.Ask(new LocalNode.GetInstance()).Result; // installing plugins - options.Plugins?.Select(p => p).Where(p => !string.IsNullOrEmpty(p)).ToList().ForEach(async p => await InstallPluginAsync(p)); - + var installTasks = options.Plugins?.Select(p => p).Where(p => !string.IsNullOrEmpty(p)).ToList().Select( p => InstallPluginAsync(p)); + if (installTasks is not null) + { + await Task.WhenAll(installTasks); + } foreach (var plugin in Plugin.Plugins) { // Register plugins commands From d2333e99914f34b495bfa3486edd37ac06459d7c Mon Sep 17 00:00:00 2001 From: Jim8y Date: Thu, 11 Jan 2024 21:24:25 +0800 Subject: [PATCH 15/18] format --- src/Neo.CLI/CLI/MainService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Neo.CLI/CLI/MainService.cs b/src/Neo.CLI/CLI/MainService.cs index 902ba1dd80..9b1f72e8a5 100644 --- a/src/Neo.CLI/CLI/MainService.cs +++ b/src/Neo.CLI/CLI/MainService.cs @@ -382,7 +382,7 @@ public async void Start(CommandLineOptions options) LocalNode = NeoSystem.LocalNode.Ask(new LocalNode.GetInstance()).Result; // installing plugins - var installTasks = options.Plugins?.Select(p => p).Where(p => !string.IsNullOrEmpty(p)).ToList().Select( p => InstallPluginAsync(p)); + var installTasks = options.Plugins?.Select(p => p).Where(p => !string.IsNullOrEmpty(p)).ToList().Select(p => InstallPluginAsync(p)); if (installTasks is not null) { await Task.WhenAll(installTasks); From c2530125c65a3f0a53a23750d64f1664dadc2364 Mon Sep 17 00:00:00 2001 From: Jim8y Date: Sat, 13 Jan 2024 01:39:11 +0800 Subject: [PATCH 16/18] fix build error --- src/Neo.CLI/Settings.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Neo.CLI/Settings.cs b/src/Neo.CLI/Settings.cs index 0acf81e33f..5056a5ec78 100644 --- a/src/Neo.CLI/Settings.cs +++ b/src/Neo.CLI/Settings.cs @@ -89,8 +89,8 @@ public LoggerSettings() { } public class StorageSettings { - public string Engine { get; } = nameof(MemoryStore); - public string Path { get; } = string.Empty; + public string Engine { get; init; } = nameof(MemoryStore); + public string Path { get; init; } = string.Empty; public StorageSettings(IConfigurationSection section) { From ec924a2c54ff9636f551b95b4deb77229e62c4ca Mon Sep 17 00:00:00 2001 From: Jimmy Date: Wed, 31 Jan 2024 22:09:15 +0800 Subject: [PATCH 17/18] Update src/Neo.CLI/CLI/MainService.cs Co-authored-by: Shargon --- src/Neo.CLI/CLI/MainService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Neo.CLI/CLI/MainService.cs b/src/Neo.CLI/CLI/MainService.cs index 9b1f72e8a5..68b82de8cc 100644 --- a/src/Neo.CLI/CLI/MainService.cs +++ b/src/Neo.CLI/CLI/MainService.cs @@ -371,7 +371,7 @@ public void OpenWallet(string path, string password) public async void Start(CommandLineOptions options) { if (NeoSystem != null) return; - bool verifyImport = options.NoVerify ?? true; + bool verifyImport = !(options.NoVerify ?? false); ProtocolSettings protocol = ProtocolSettings.Load("config.json"); CustomProtocolSettings(options, protocol); From 1f3f7d6a23fe00ba04cdee8b992cbb56899fd510 Mon Sep 17 00:00:00 2001 From: Fernando Diaz Toledano Date: Thu, 1 Feb 2024 10:48:22 +0100 Subject: [PATCH 18/18] Fix Contracts --- src/Neo.CLI/Settings.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Neo.CLI/Settings.cs b/src/Neo.CLI/Settings.cs index 5056a5ec78..4390a4ce36 100644 --- a/src/Neo.CLI/Settings.cs +++ b/src/Neo.CLI/Settings.cs @@ -68,6 +68,7 @@ public Settings() Storage = new StorageSettings(); P2P = new P2PSettings(); UnlockWallet = new UnlockWalletSettings(); + Contracts = new ContractsSettings(); } } @@ -140,7 +141,7 @@ public UnlockWalletSettings() { } public class ContractsSettings { - public UInt160 NeoNameService { get; } = UInt160.Zero; + public UInt160 NeoNameService { get; init; } = UInt160.Zero; public ContractsSettings(IConfigurationSection section) { @@ -154,5 +155,7 @@ public ContractsSettings(IConfigurationSection section) throw new ArgumentException("Neo Name Service (NNS): NeoNameService hash is invalid. Check your config.json.", nameof(NeoNameService)); } } + + public ContractsSettings() { } } }