This repository has been archived by the owner on Dec 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 224
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 74 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)
Jim8y 8cac90f
create mode folders
Jim8y c9c3392
privatenet config and commands
Jim8y 029ac42
load mode
Jim8y d4bb9e4
list mode
Jim8y 11dabc8
delete mode
Jim8y e86ab46
save mode
Jim8y c73623b
optimise code
Jim8y 2564839
done with the mode system and added an icon for neo-cli
Jim8y cbd62b3
fix format
Jim8y fd1ec20
fix format....well, no idea where the format issue is
Jim8y 7d5ed7f
remove mode file
Jim8y 6427f54
update wallet file
Jim8y 01daf77
save config files in a same folder
Jim8y 8536ff9
code optimise
Jim8y 4f62c33
fix logic
Jim8y f41de1a
fix format
Jim8y de3ccd8
optimise code and solve delete issue
Jim8y 6dd88ef
when user install plugin, save the config to the current mode
Jim8y dd130bb
copy plugin config.json to all modes
Jim8y 27ea359
Update neo-cli/CLI/MainService.Mode.cs
Jim8y 5e0e7f8
Merge branch 'develop' into mode-system
Jim8y d0c0f30
update mode system
Jim8y a89a910
Merge branch 'master' into mode-system
Jim8y 04c2d42
Merge branch 'master' into mode-system
Jim8y fedde51
merge master
Jim8y 7aac009
Update neo-cli/CLI/MainService.Mode.cs
Jim8y 817bae6
fix issues as nico comments
Jim8y 7745c8d
minor update
Jim8y f921835
fix plugin delete issue
Jim8y e6e225e
Update neo-cli/CLI/MainService.Mode.cs
Jim8y f3fd7aa
fix path issue
Jim8y 91eb460
fix format
Jim8y fd9203f
fix plugin name issue
Jim8y 87feb0f
fix config issue while install plugin from the mode
Jim8y 092d546
Merge branch 'master' into mode-system
Jim8y d30b8d1
add warning info
Jim8y 5894885
stop the node
Jim8y 7e6919c
Merge branch 'master' into mode-system
Jim8y f83ab4f
rename and remove
Jim8y 9af9e0c
fix async issue
Jim8y 3d44018
Merge branch 'master' into mode-system
Jim8y 13697d7
Merge branch 'master' into mode-system
Jim8y d38e39e
in case of duplicly install plugin while loading mode
Jim8y 6a1b2ba
Merge branch 'master' into mode-system
Jim8y dd69999
fix case in path
Jim8y 6a4df34
add plugin file
Jim8y 2a98ccb
on create new mode
Jim8y f5f6b8a
add oracle mode
Jim8y e73a42c
try to fix cpytofolder
Jim8y ef18644
fix mode load issue
Jim8y ced9cc3
udpate the expect
Jim8y 1056ec2
Revert "udpate the expect"
Jim8y e33c868
fix plugin name case issue
Jim8y 5dad265
fix plugin name case issue and remove oracle mode
Jim8y 009f802
format check
Jim8y e79bde9
1. config exists in mode and in mode => move config from mode to plugin
Jim8y bcad2a0
config.json
Jim8y 86a7174
fix format
Jim8y 0bd73ce
fix expect test
Jim8y 842fc07
fix path issue
Jim8y 3d06822
fix path
Jim8y 2a3e53e
fix privatenet wallet path
Jim8y f1977f0
fix expect
Jim8y e12ad2d
Update neo-cli/Modes/privatenet/config.json
Jim8y 6cf1de2
Merge branch 'master' into mode-system
Jim8y 17e009c
Merge branch 'master' into mode-system
Jim8y cb96042
Update neo-cli/CLI/MainService.Plugins.cs
Jim8y 858a922
Update neo-cli/CLI/MainService.Plugins.cs
Jim8y 9cdedc8
Merge branch 'master' into mode-system
Jim8y 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…
Jim8y fc27b27
Merge branch 'master' into mode-system
Jim8y 374acf6
Merge branch 'mode-system' of github.com:Liaojinghui/neo-node into mo…
Jim8y 2e07919
update format
Jim8y 9445883
Merge branch 'master' into mode-system
vncoelho 892f2cd
Merge branch 'master' into mode-system
Jim8y 5faefae
Merge branch 'master' into mode-system
Jim8y 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 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 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 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 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?
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