This repository was archived by the owner on Dec 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 220
node: Mode system #853
Open
Jim8y
wants to merge
83
commits into
neo-project:master
Choose a base branch
from
Jim8y:mode-system
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
node: Mode system #853
Changes from 70 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 35269f6
set new network id for testnet
superboyiii 51b5514
revert
superboyiii 2ad44ef
Add new testnet network id (#852)
superboyiii ab5447d
typo, comment (#847)
8cac90f
create mode folders
c9c3392
privatenet config and commands
029ac42
load mode
d4bb9e4
list mode
11dabc8
delete mode
e86ab46
save mode
c73623b
optimise code
2564839
done with the mode system and added an icon for neo-cli
cbd62b3
fix format
fd1ec20
fix format....well, no idea where the format issue is
7d5ed7f
remove mode file
6427f54
update wallet file
01daf77
save config files in a same folder
8536ff9
code optimise
4f62c33
fix logic
f41de1a
fix format
de3ccd8
optimise code and solve delete issue
6dd88ef
when user install plugin, save the config to the current mode
dd130bb
copy plugin config.json to all modes
27ea359
Update neo-cli/CLI/MainService.Mode.cs
5e0e7f8
Merge branch 'develop' into mode-system
d0c0f30
update mode system
a89a910
Merge branch 'master' into mode-system
04c2d42
Merge branch 'master' into mode-system
fedde51
merge master
7aac009
Update neo-cli/CLI/MainService.Mode.cs
817bae6
fix issues as nico comments
7745c8d
minor update
f921835
fix plugin delete issue
e6e225e
Update neo-cli/CLI/MainService.Mode.cs
f3fd7aa
fix path issue
91eb460
fix format
fd9203f
fix plugin name issue
87feb0f
fix config issue while install plugin from the mode
092d546
Merge branch 'master' into mode-system
d30b8d1
add warning info
5894885
stop the node
7e6919c
Merge branch 'master' into mode-system
f83ab4f
rename and remove
9af9e0c
fix async issue
3d44018
Merge branch 'master' into mode-system
13697d7
Merge branch 'master' into mode-system
d38e39e
in case of duplicly install plugin while loading mode
6a1b2ba
Merge branch 'master' into mode-system
dd69999
fix case in path
6a4df34
add plugin file
2a98ccb
on create new mode
f5f6b8a
add oracle mode
e73a42c
try to fix cpytofolder
ef18644
fix mode load issue
ced9cc3
udpate the expect
1056ec2
Revert "udpate the expect"
e33c868
fix plugin name case issue
5dad265
fix plugin name case issue and remove oracle mode
009f802
format check
e79bde9
1. config exists in mode and in mode => move config from mode to plugin
bcad2a0
config.json
86a7174
fix format
0bd73ce
fix expect test
842fc07
fix path issue
3d06822
fix path
2a3e53e
fix privatenet wallet path
f1977f0
fix expect
e12ad2d
Update neo-cli/Modes/privatenet/config.json
6cf1de2
Merge branch 'master' into mode-system
17e009c
Merge branch 'master' into mode-system
cb96042
Update neo-cli/CLI/MainService.Plugins.cs
858a922
Update neo-cli/CLI/MainService.Plugins.cs
9cdedc8
Merge branch 'master' into mode-system
305ab79
Update Helper.cs
shargon c0cb778
Merge branch 'master' into mode-system
superboyiii 456afc9
Merge branch 'mode-system' of github.com:Liaojinghui/neo-node into mo…
fc27b27
Merge branch 'master' into mode-system
374acf6
Merge branch 'mode-system' of github.com:Liaojinghui/neo-node into mo…
2e07919
update format
9445883
Merge branch 'master' into mode-system
vncoelho 892f2cd
Merge branch 'master' into mode-system
5faefae
Merge branch 'master' into mode-system
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,10 @@ expect { | |
| timeout { exit 1 } | ||
| } | ||
|
|
||
| sleep 5 | ||
|
|
||
| spawn dotnet out/neo-cli.dll | ||
|
|
||
| # | ||
| # Test 'create wallet' | ||
| # | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,209 @@ | ||
| // Copyright (C) 2016-2022 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.IO; | ||
| using System.Linq; | ||
| using System.Threading.Tasks; | ||
| using Akka.Util.Internal; | ||
| using Neo.ConsoleService; | ||
| namespace Neo.CLI; | ||
|
|
||
| partial class MainService | ||
| { | ||
| /// <summary> | ||
| /// Process "mode list" command. | ||
| /// </summary> | ||
| [ConsoleCommand("mode list", Category = "Mode Commands")] | ||
| private void OnListModes() | ||
| { | ||
| try | ||
| { | ||
| Directory.GetDirectories(ModePath).ForEach(p => ConsoleHelper.Info(p)); | ||
| } | ||
| catch (IOException) | ||
| { | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Process "mode save" command | ||
| /// <param name="modeName">Mode name</param> | ||
| /// </summary> | ||
| [ConsoleCommand("mode save", Category = "Mode Commands")] | ||
| private void OnSaveMode(string modeName) | ||
| { | ||
| // if no mode name assigned | ||
| if (modeName is null) | ||
| { | ||
| ConsoleHelper.Error("No mode name assigned."); | ||
| return; | ||
| } | ||
| modeName = modeName.ToLower(); | ||
| try | ||
| { | ||
| var targetMode = new DirectoryInfo($"{ModePath}/{modeName}"); | ||
| // Create the mode if it does not exist | ||
| if (!targetMode.Exists) Directory.CreateDirectory(targetMode.FullName); | ||
| // Get the config files of the node | ||
| MoveModeConfig(modeName.ToLower()); | ||
| var plugins = new DirectoryInfo(PluginPath); | ||
| // Cache directories before we start copying | ||
| var dirs = plugins.GetDirectories(); | ||
| // Create an empty .PLUGINS file | ||
| File.Create($"{ModePath}/{modeName}/.PLUGINS").Close(); | ||
| // Save the Plugin files | ||
| foreach (var plugin in dirs) | ||
| { | ||
| foreach (var file in plugin.GetFiles().Where(p => p.Extension == ".json")) | ||
| { | ||
| file.CopyTo($"{ModePath}/{modeName}/{plugin.Name}.json", true); | ||
| } | ||
| AddPluginToMode(plugin.Name, modeName); | ||
| } | ||
| } | ||
| catch (Exception e) | ||
| { | ||
| Console.WriteLine(e); | ||
| throw; | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Process "mode delete" command | ||
| /// <param name="modeName">Mode name</param> | ||
| /// </summary> | ||
| [ConsoleCommand("mode delete", Category = "Mode Commands")] | ||
| private void OnDeleteMode(string modeName) | ||
| { | ||
| try | ||
| { | ||
| var dir = new DirectoryInfo($"{ModePath}/{modeName.ToLower()}"); | ||
| if (!dir.Exists) | ||
| return; | ||
| Directory.Delete(dir.FullName, true); | ||
| ConsoleHelper.Info("Mode ", modeName, " was deleted."); | ||
| } | ||
| catch (Exception e) | ||
| { | ||
| Console.WriteLine(e); | ||
| throw; | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Load the target mode, plugin should be according to the mode, | ||
| /// if the mode contains the plugin, install the plugin, otherwise delete the plugin | ||
| /// </summary> | ||
| /// <param name="mode"> name of the mode</param> | ||
| /// <exception cref="DirectoryNotFoundException"> if the mode is not found</exception> | ||
| private async Task LoadMode(string mode) | ||
| { | ||
| try | ||
| { | ||
| mode = mode.ToLower(); | ||
| var dir = new DirectoryInfo($"{ModePath}/{mode}"); | ||
| if (!dir.Exists) | ||
| throw new DirectoryNotFoundException($"Mode not found: {dir.FullName}"); | ||
| // Process the plugin | ||
| var modePlugins = File.ReadAllLines($"{ModePath}/{_currentMode}/.PLUGINS"); | ||
| // loop modePlugins | ||
| foreach (var pluginName in modePlugins) | ||
| { | ||
| // if the plugin is not installed, install it | ||
| if (!Directory.Exists($"{PluginPath}/{pluginName}/")) | ||
| { | ||
| await InstallPluginAsync(pluginName, overWrite: true, saveConfig: false); | ||
| _needRestart = true; | ||
| } | ||
| // if the mode has the plugin config, load the config from the mode | ||
| if (File.Exists($"{ModePath}/{mode}/{pluginName}.json")) | ||
| File.Copy($"{ModePath}/{mode}/{pluginName}.json", | ||
| $"{PluginPath}/{pluginName}/config.json", true); | ||
| } | ||
| // get the system config file from the mode | ||
| MoveModeConfig(mode, false); | ||
|
|
||
| // Get existing plugins and delete them if they are not in the mode | ||
| new DirectoryInfo($"{PluginPath}/").GetDirectories().ForEach(p => | ||
| { | ||
| if (modePlugins.Any(k => string.Compare(Path.GetFileNameWithoutExtension(k), p.Name, StringComparison.OrdinalIgnoreCase) == 0) | ||
| || !File.Exists($"{PluginPath}/{p.Name}/config.json")) return; | ||
| try | ||
| { | ||
| ConsoleHelper.Info("Removing plugin ", p.Name); | ||
| Directory.Delete($"{PluginPath}/{p.Name}", true); | ||
| _needRestart = true; | ||
| } | ||
| catch | ||
| { | ||
| // ignored | ||
| } | ||
| }); | ||
| } | ||
| catch (Exception e) | ||
| { | ||
| Console.WriteLine(e); | ||
| throw; | ||
| } | ||
| } | ||
|
|
||
| /// save config.json and config.fs.json to the mode directory | ||
| /// <param name="mode"> name of the mode</param> | ||
| /// <param name="toMode"></param> | ||
| /// <exception cref="DirectoryNotFoundException"> if the mode is not found</exception> | ||
| private static void MoveModeConfig(string mode, bool toMode = true) | ||
| { | ||
| var modeDir = new DirectoryInfo($"{ModePath}/{mode.ToLower()}"); | ||
| var configDir = new DirectoryInfo($"{StrExeFilePath}"); | ||
| if (!modeDir.Exists) | ||
| throw new DirectoryNotFoundException($"Mode not found: {modeDir.FullName}"); | ||
| try | ||
| { | ||
| if (toMode) | ||
| { | ||
| File.Copy(configDir.FullName + "/config.json", | ||
| modeDir.FullName + "/config.json", true); | ||
| File.Copy(configDir.FullName + "/config.fs.json", | ||
| modeDir.FullName + "/config.fs.json", true); | ||
| } | ||
| else | ||
| { | ||
| File.Copy(modeDir.FullName + "/config.json", | ||
| configDir.FullName + "/config.json", true); | ||
| File.Copy(modeDir.FullName + "/config.fs.json", | ||
| configDir.FullName + "/config.fs.json", true); | ||
| } | ||
Jim8y marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| catch (Exception e) | ||
| { | ||
| Console.WriteLine(e); | ||
| throw; | ||
| } | ||
| } | ||
|
|
||
| // Add plugin to .PLUGINS file | ||
| private static void AddPluginToMode(string pluginName, string modeName) | ||
| { | ||
| var plugins = File.ReadAllLines($"{ModePath}/{modeName}/.PLUGINS"); | ||
| if (plugins.Contains(pluginName)) return; | ||
| var newPlugins = plugins.Append(pluginName).ToArray(); | ||
| File.WriteAllLines($"{ModePath}/{modeName}/.PLUGINS", newPlugins); | ||
| } | ||
|
|
||
| // Remove plugin from .PLUGINS file | ||
| private static void RemovePluginFromMode(string pluginName, string modeName) | ||
| { | ||
| var plugins = File.ReadAllLines($"{ModePath}/{modeName}/.PLUGINS"); | ||
| // if (plugins.All(p => !string.Equals(p, pluginName, StringComparison.CurrentCultureIgnoreCase))) return; | ||
| var newPlugins = plugins.Where(p => !string.Equals(p, pluginName, StringComparison.CurrentCultureIgnoreCase)).ToArray(); | ||
| File.WriteAllLines($"{ModePath}/{modeName}/.PLUGINS", newPlugins); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
5 seconds is required?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, has to wait for 5 seconds, at least