diff --git a/CHANGELOG.md b/CHANGELOG.md index d12ec0cc7..ac837aa42 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,16 @@ # Changelog All notable changes to this project will be documented in this file. +## [3.3.1] + +### Changed +- ([#860](https://github.com/neo-project/neo-node/pull/860/)) delete plugin folder when uninstall plugin + +## [3.3.0] + +### Changed +- ([#861](https://github.com/neo-project/neo-node/pull/861/)) Use wallet factory + ## [3.2.1] ### Changed diff --git a/neo-cli/CLI/Logger.cs b/neo-cli/CLI/MainService.Logger.cs similarity index 86% rename from neo-cli/CLI/Logger.cs rename to neo-cli/CLI/MainService.Logger.cs index ba61890f2..3d230b754 100644 --- a/neo-cli/CLI/Logger.cs +++ b/neo-cli/CLI/MainService.Logger.cs @@ -1,4 +1,4 @@ -// Copyright (C) 2016-2021 The Neo Project. +// 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 @@ -9,7 +9,6 @@ // modifications are permitted. using Neo.ConsoleService; -using Neo.Plugins; using System; using System.IO; using System.Text; @@ -17,7 +16,7 @@ namespace Neo.CLI { - internal class Logger : Plugin, ILogPlugin + partial class MainService { private static readonly ConsoleColorSet DebugColor = new ConsoleColorSet(ConsoleColor.Cyan); private static readonly ConsoleColorSet InfoColor = new ConsoleColorSet(ConsoleColor.White); @@ -25,10 +24,17 @@ internal class Logger : Plugin, ILogPlugin private static readonly ConsoleColorSet ErrorColor = new ConsoleColorSet(ConsoleColor.Red); private static readonly ConsoleColorSet FatalColor = new ConsoleColorSet(ConsoleColor.Red); - public override string Name => "SystemLog"; - public override string Description => "Prints consensus log and is a built-in plugin which cannot be uninstalled"; - public override string ConfigFile => Combine(GetDirectoryName(Path), "config.json"); - public override string Path => GetType().Assembly.Location; + private readonly object syncRoot = new(); + + private void Initialize_Logger() + { + Utility.Logging += OnLog; + } + + private void Dispose_Logger() + { + Utility.Logging -= OnLog; + } private static void GetErrorLogs(StringBuilder sb, Exception ex) { @@ -50,7 +56,7 @@ private static void GetErrorLogs(StringBuilder sb, Exception ex) } } - void ILogPlugin.Log(string source, LogLevel level, object message) + private void OnLog(string source, LogLevel level, object message) { if (!Settings.Default.Logger.Active) return; @@ -62,7 +68,7 @@ void ILogPlugin.Log(string source, LogLevel level, object message) message = sb.ToString(); } - lock (typeof(Logger)) + lock (syncRoot) { DateTime now = DateTime.Now; var log = $"[{now.TimeOfDay:hh\\:mm\\:ss\\.fff}] {message}"; diff --git a/neo-cli/CLI/MainService.Plugins.cs b/neo-cli/CLI/MainService.Plugins.cs index 8adb4245d..86fb564d4 100644 --- a/neo-cli/CLI/MainService.Plugins.cs +++ b/neo-cli/CLI/MainService.Plugins.cs @@ -1,5 +1,4 @@ // 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 @@ -185,7 +184,7 @@ private async Task InstallDependenciesAsync(Stream config, HashSet insta /// private static bool PluginExists(string pluginName) { - return File.Exists($"Plugins/{pluginName}/{pluginName}.dll"); + return Plugin.Plugins.Any(p => p.Name.Equals(pluginName, StringComparison.InvariantCultureIgnoreCase)); } /// @@ -201,18 +200,6 @@ private void OnUnInstallCommand(string pluginName) return; } - var plugin = Plugin.Plugins.FirstOrDefault(p => p.Name == pluginName); - if (plugin is not null) - { - if (plugin is Logger) - { - ConsoleHelper.Warning("You cannot uninstall a built-in plugin."); - return; - } - - Plugin.Plugins.Remove(plugin); - } - foreach (var p in Plugin.Plugins) { try @@ -224,7 +211,7 @@ private void OnUnInstallCommand(string pluginName) .GetSection("Dependency") .GetChildren() .Select(d => d.Get()) - .Any(v => v == pluginName)) + .Any(v => v.Equals(pluginName, StringComparison.InvariantCultureIgnoreCase))) { ConsoleHelper.Error( $"Can not uninstall. Other plugins depend on this plugin, try `reinstall {pluginName}` if the plugin is broken."); @@ -236,16 +223,11 @@ private void OnUnInstallCommand(string pluginName) // ignored } } - try { - // DeleteFiles(new[] { $"Plugins/{pluginName}/{pluginName}.dll", $"Plugins/{pluginName}/config.json" }); Directory.Delete($"Plugins/{pluginName}", true); } - catch (IOException) - { - } - + catch (IOException) { } ConsoleHelper.Info("Uninstall successful, please restart neo-cli."); } @@ -260,7 +242,6 @@ private void OnPluginsCommand() Console.WriteLine("Loaded plugins:"); foreach (Plugin plugin in Plugin.Plugins) { - if (plugin is Logger) continue; var name = $"{plugin.Name}@{plugin.Version}"; Console.WriteLine($"\t{name,-25}{plugin.Description}"); } diff --git a/neo-cli/CLI/MainService.Wallet.cs b/neo-cli/CLI/MainService.Wallet.cs index f56a759ff..7be27166b 100644 --- a/neo-cli/CLI/MainService.Wallet.cs +++ b/neo-cli/CLI/MainService.Wallet.cs @@ -1,4 +1,4 @@ -// Copyright (C) 2016-2021 The Neo Project. +// 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 @@ -24,6 +24,7 @@ using System.Linq; using System.Numerics; using System.Threading.Tasks; +using static Neo.SmartContract.Helper; namespace Neo.CLI { @@ -392,11 +393,11 @@ private void OnListAddressCommand() { type = "WatchOnly"; } - else if (contract.Script.IsMultiSigContract()) + else if (IsMultiSigContract(contract.Script)) { type = "MultiSignature"; } - else if (contract.Script.IsSignatureContract()) + else if (IsSignatureContract(contract.Script)) { type = "Standard"; } diff --git a/neo-cli/CLI/MainService.cs b/neo-cli/CLI/MainService.cs index 710f5df9c..432e95736 100644 --- a/neo-cli/CLI/MainService.cs +++ b/neo-cli/CLI/MainService.cs @@ -1,10 +1,10 @@ // Copyright (C) 2016-2022 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. @@ -85,6 +85,8 @@ public MainService() : base() RegisterCommandHandler(obj => (JArray)obj); RegisterCommand(this); + + Initialize_Logger(); } internal static UInt160 StringToAddress(string input, byte version) @@ -471,6 +473,7 @@ public async void Start(string[] args) public void Stop() { + Dispose_Logger(); Interlocked.Exchange(ref _neoSystem, null)?.Dispose(); } @@ -550,7 +553,7 @@ private void SendTransaction(byte[] script, UInt160 account = null, long gas = T try { Transaction tx = CurrentWallet.MakeTransaction(snapshot, script, account, signers, maxGas: gas); - ConsoleHelper.Info("Invoking script with: ", $"'{Convert.ToBase64String(tx.Script)}'"); + ConsoleHelper.Info("Invoking script with: ", $"'{Convert.ToBase64String(tx.Script.Span)}'"); using (ApplicationEngine engine = ApplicationEngine.Run(tx.Script, snapshot, container: tx, settings: NeoSystem.Settings, gas: gas)) { diff --git a/neo-cli/Modes/mainnet/config.json b/neo-cli/Modes/mainnet/config.json index bd4d47a19..53523ae0d 100644 --- a/neo-cli/Modes/mainnet/config.json +++ b/neo-cli/Modes/mainnet/config.json @@ -29,6 +29,9 @@ "MaxTransactionsPerBlock": 512, "MemoryPoolMaxTransactions": 50000, "MaxTraceableBlocks": 2102400, + "Hardforks": { + "HF_Aspidochelone": 1730000 + }, "InitialGasDistribution": 5200000000000000, "ValidatorsCount": 7, "StandbyCommittee": [ diff --git a/neo-cli/Modes/testnet/config.json b/neo-cli/Modes/testnet/config.json index 7ee048897..7408f897c 100644 --- a/neo-cli/Modes/testnet/config.json +++ b/neo-cli/Modes/testnet/config.json @@ -29,6 +29,9 @@ "MaxTransactionsPerBlock": 5000, "MemoryPoolMaxTransactions": 50000, "MaxTraceableBlocks": 2102400, + "Hardforks": { + "HF_Aspidochelone": 210000 + }, "InitialGasDistribution": 5200000000000000, "ValidatorsCount": 7, "StandbyCommittee": [ diff --git a/neo-cli/config.json b/neo-cli/config.json new file mode 100644 index 000000000..53523ae0d --- /dev/null +++ b/neo-cli/config.json @@ -0,0 +1,68 @@ +{ + "ApplicationConfiguration": { + "Logger": { + "Path": "Logs", + "ConsoleOutput": false, + "Active": false + }, + "Storage": { + "Engine": "LevelDBStore", + "Path": "Data_LevelDB_{0}" + }, + "P2P": { + "Port": 10333, + "WsPort": 10334, + "MinDesiredConnections": 10, + "MaxConnections": 40, + "MaxConnectionsPerAddress": 3 + }, + "UnlockWallet": { + "Path": "", + "Password": "", + "IsActive": false + } + }, + "ProtocolConfiguration": { + "Network": 860833102, + "AddressVersion": 53, + "MillisecondsPerBlock": 15000, + "MaxTransactionsPerBlock": 512, + "MemoryPoolMaxTransactions": 50000, + "MaxTraceableBlocks": 2102400, + "Hardforks": { + "HF_Aspidochelone": 1730000 + }, + "InitialGasDistribution": 5200000000000000, + "ValidatorsCount": 7, + "StandbyCommittee": [ + "03b209fd4f53a7170ea4444e0cb0a6bb6a53c2bd016926989cf85f9b0fba17a70c", + "02df48f60e8f3e01c48ff40b9b7f1310d7a8b2a193188befe1c2e3df740e895093", + "03b8d9d5771d8f513aa0869b9cc8d50986403b78c6da36890638c3d46a5adce04a", + "02ca0e27697b9c248f6f16e085fd0061e26f44da85b58ee835c110caa5ec3ba554", + "024c7b7fb6c310fccf1ba33b082519d82964ea93868d676662d4a59ad548df0e7d", + "02aaec38470f6aad0042c6e877cfd8087d2676b0f516fddd362801b9bd3936399e", + "02486fd15702c4490a26703112a5cc1d0923fd697a33406bd5a1c00e0013b09a70", + "023a36c72844610b4d34d1968662424011bf783ca9d984efa19a20babf5582f3fe", + "03708b860c1de5d87f5b151a12c2a99feebd2e8b315ee8e7cf8aa19692a9e18379", + "03c6aa6e12638b36e88adc1ccdceac4db9929575c3e03576c617c49cce7114a050", + "03204223f8c86b8cd5c89ef12e4f0dbb314172e9241e30c9ef2293790793537cf0", + "02a62c915cf19c7f19a50ec217e79fac2439bbaad658493de0c7d8ffa92ab0aa62", + "03409f31f0d66bdc2f70a9730b66fe186658f84a8018204db01c106edc36553cd0", + "0288342b141c30dc8ffcde0204929bb46aed5756b41ef4a56778d15ada8f0c6654", + "020f2887f41474cfeb11fd262e982051c1541418137c02a0f4961af911045de639", + "0222038884bbd1d8ff109ed3bdef3542e768eef76c1247aea8bc8171f532928c30", + "03d281b42002647f0113f36c7b8efb30db66078dfaaa9ab3ff76d043a98d512fde", + "02504acbc1f4b3bdad1d86d6e1a08603771db135a73e61c9d565ae06a1938cd2ad", + "0226933336f1b75baa42d42b71d9091508b638046d19abd67f4e119bf64a7cfb4d", + "03cdcea66032b82f5c30450e381e5295cae85c5e6943af716cc6b646352a6067dc", + "02cd5a5547119e24feaa7c2a0f37b8c9366216bab7054de0065c9be42084003c8a" + ], + "SeedList": [ + "seed1.neo.org:10333", + "seed2.neo.org:10333", + "seed3.neo.org:10333", + "seed4.neo.org:10333", + "seed5.neo.org:10333" + ] + } +} diff --git a/neo-cli/neo-cli.csproj b/neo-cli/neo-cli.csproj index 5cbbd760b..f3bcfdf5a 100644 --- a/neo-cli/neo-cli.csproj +++ b/neo-cli/neo-cli.csproj @@ -3,7 +3,7 @@ 2016-2022 The Neo Project Neo.CLI - 3.2.1 + 3.3.1 The Neo Project net6.0 neo-cli @@ -30,7 +30,7 @@ - + diff --git a/neo-gui/GUI/ElectionDialog.cs b/neo-gui/GUI/ElectionDialog.cs index befdb7a91..dbb6c439d 100644 --- a/neo-gui/GUI/ElectionDialog.cs +++ b/neo-gui/GUI/ElectionDialog.cs @@ -1,4 +1,4 @@ -// Copyright (C) 2016-2021 The Neo Project. +// Copyright (C) 2016-2022 The Neo Project. // // The neo-gui is free software distributed under the MIT software // license, see the accompanying file LICENSE in the main directory of @@ -10,13 +10,13 @@ using Neo.Cryptography.ECC; using Neo.IO; -using Neo.SmartContract; using Neo.SmartContract.Native; using Neo.VM; using System; using System.Linq; using System.Windows.Forms; using static Neo.Program; +using static Neo.SmartContract.Helper; namespace Neo.GUI { @@ -37,7 +37,7 @@ public byte[] GetScript() private void ElectionDialog_Load(object sender, EventArgs e) { - comboBox1.Items.AddRange(Service.CurrentWallet.GetAccounts().Where(p => !p.WatchOnly && p.Contract.Script.IsSignatureContract()).Select(p => p.GetKey().PublicKey).ToArray()); + comboBox1.Items.AddRange(Service.CurrentWallet.GetAccounts().Where(p => !p.WatchOnly && IsSignatureContract(p.Contract.Script)).Select(p => p.GetKey().PublicKey).ToArray()); } private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) diff --git a/neo-gui/GUI/InvokeContractDialog.cs b/neo-gui/GUI/InvokeContractDialog.cs index ce7c3ae3c..8de5fd930 100644 --- a/neo-gui/GUI/InvokeContractDialog.cs +++ b/neo-gui/GUI/InvokeContractDialog.cs @@ -1,4 +1,4 @@ -// Copyright (C) 2016-2021 The Neo Project. +// Copyright (C) 2016-2022 The Neo Project. // // The neo-gui is free software distributed under the MIT software // license, see the accompanying file LICENSE in the main directory of @@ -38,7 +38,7 @@ public InvokeContractDialog(Transaction tx) : this() { this.tx = tx; tabControl1.SelectedTab = tabPage2; - textBox6.Text = tx.Script.ToHexString(); + textBox6.Text = tx.Script.Span.ToHexString(); textBox6.ReadOnly = true; } diff --git a/neo-gui/GUI/MainForm.cs b/neo-gui/GUI/MainForm.cs index db95d0590..5c1ef3fe9 100644 --- a/neo-gui/GUI/MainForm.cs +++ b/neo-gui/GUI/MainForm.cs @@ -1,4 +1,4 @@ -// Copyright (C) 2016-2021 The Neo Project. +// Copyright (C) 2016-2022 The Neo Project. // // The neo-gui is free software distributed under the MIT software // license, see the accompanying file LICENSE in the main directory of @@ -12,7 +12,6 @@ using Neo.IO; using Neo.IO.Actors; using Neo.Ledger; -using Neo.Network.P2P; using Neo.Network.P2P.Payloads; using Neo.Properties; using Neo.SmartContract; @@ -34,6 +33,7 @@ using System.Windows.Forms; using System.Xml.Linq; using static Neo.Program; +using static Neo.SmartContract.Helper; using VMArray = Neo.VM.Types.Array; namespace Neo.GUI @@ -76,7 +76,7 @@ private void AddAccount(WalletAccount account, bool selected = false) } if (item == null) { - string groupName = account.WatchOnly ? "watchOnlyGroup" : account.Contract.Script.IsSignatureContract() ? "standardContractGroup" : "nonstandardContractGroup"; + string groupName = account.WatchOnly ? "watchOnlyGroup" : IsSignatureContract(account.Contract.Script) ? "standardContractGroup" : "nonstandardContractGroup"; item = listView1.Items.Add(new ListViewItem(new[] { new ListViewItem.ListViewSubItem @@ -424,7 +424,7 @@ private void contextMenuStrip1_Opening(object sender, CancelEventArgs e) 查看私钥VToolStripMenuItem.Enabled = listView1.SelectedIndices.Count == 1 && !((WalletAccount)listView1.SelectedItems[0].Tag).WatchOnly && - ((WalletAccount)listView1.SelectedItems[0].Tag).Contract.Script.IsSignatureContract(); + IsSignatureContract(((WalletAccount)listView1.SelectedItems[0].Tag).Contract.Script); viewContractToolStripMenuItem.Enabled = listView1.SelectedIndices.Count == 1 && !((WalletAccount)listView1.SelectedItems[0].Tag).WatchOnly; diff --git a/neo-gui/GUI/Wrappers/TransactionAttributeWrapper.cs b/neo-gui/GUI/Wrappers/TransactionAttributeWrapper.cs index 1ba294bbc..64e9f6f1b 100644 --- a/neo-gui/GUI/Wrappers/TransactionAttributeWrapper.cs +++ b/neo-gui/GUI/Wrappers/TransactionAttributeWrapper.cs @@ -1,4 +1,4 @@ -// Copyright (C) 2016-2021 The Neo Project. +// Copyright (C) 2016-2022 The Neo Project. // // The neo-gui is free software distributed under the MIT software // license, see the accompanying file LICENSE in the main directory of @@ -8,10 +8,9 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. +using Neo.IO; using Neo.Network.P2P.Payloads; using System.ComponentModel; -using System.IO; -using System.Text; namespace Neo.GUI.Wrappers { @@ -23,9 +22,8 @@ internal class TransactionAttributeWrapper public TransactionAttribute Unwrap() { - using var reader = new BinaryReader(new MemoryStream(Data), Encoding.UTF8, false); - - return TransactionAttribute.DeserializeFrom(reader); + MemoryReader reader = new(Data); + return TransactionAttribute.DeserializeFrom(ref reader); } } } diff --git a/neo-gui/neo-gui.csproj b/neo-gui/neo-gui.csproj index 94a56ec90..03a64ccbc 100644 --- a/neo-gui/neo-gui.csproj +++ b/neo-gui/neo-gui.csproj @@ -3,7 +3,7 @@ 2016-2022 The Neo Project Neo.GUI - 3.2.1 + 3.3.1 The Neo Project WinExe net6.0-windows diff --git a/tests/Neo.ConsoleService.Tests/Neo.ConsoleService.Tests.csproj b/tests/Neo.ConsoleService.Tests/Neo.ConsoleService.Tests.csproj index 48273aad7..af2052090 100644 --- a/tests/Neo.ConsoleService.Tests/Neo.ConsoleService.Tests.csproj +++ b/tests/Neo.ConsoleService.Tests/Neo.ConsoleService.Tests.csproj @@ -6,9 +6,9 @@ - - - + + +