diff --git a/CHANGELOG b/CHANGELOG index c51422595..413a2989a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,9 +2,19 @@ All notable changes to this project will be documented in this file. ## [Unreleased] + +## [2.7.5] - 2018-05-18 +### Added +- Importing/exporting blocks with sharding. +- Daemonizing the neo process. +- Support for Neo Plugins System. +- New smart contract API: `Neo.Contract.IsPayable`. + ### Changed - Optimize RPC command `getbalance` for NEP-5. - Optimize config.json +- Improve the performance of p2p network. +- Improve the performance of block synchronization. ### Fixed - Prevents blocking when the second instance is started. diff --git a/neo-cli/Consensus/ConsensusWithLog.cs b/neo-cli/Consensus/ConsensusWithLog.cs new file mode 100644 index 000000000..1beeff856 --- /dev/null +++ b/neo-cli/Consensus/ConsensusWithLog.cs @@ -0,0 +1,32 @@ +using Neo.Network; +using Neo.Wallets; +using System; +using System.IO; + +namespace Neo.Consensus +{ + internal class ConsensusWithLog : ConsensusService + { + private string log_dictionary; + + public ConsensusWithLog(LocalNode localNode, Wallet wallet, string log_dictionary) + : base(localNode, wallet) + { + this.log_dictionary = log_dictionary; + } + + protected override void Log(string message) + { + DateTime now = DateTime.Now; + string line = $"[{now.TimeOfDay:hh\\:mm\\:ss}] {message}"; + Console.WriteLine(line); + if (string.IsNullOrEmpty(log_dictionary)) return; + lock (log_dictionary) + { + Directory.CreateDirectory(log_dictionary); + string path = Path.Combine(log_dictionary, $"{now:yyyy-MM-dd}.log"); + File.AppendAllLines(path, new[] { line }); + } + } + } +} diff --git a/neo-cli/Consensus/ConsensusWithPolicy.cs b/neo-cli/Consensus/ConsensusWithPolicy.cs deleted file mode 100644 index b5ced7f2f..000000000 --- a/neo-cli/Consensus/ConsensusWithPolicy.cs +++ /dev/null @@ -1,54 +0,0 @@ -using Neo.Core; -using Neo.Network; -using Neo.Wallets; -using System; -using System.IO; -using System.Linq; - -namespace Neo.Consensus -{ - internal class ConsensusWithPolicy : ConsensusService - { - private string log_dictionary; - - public ConsensusWithPolicy(LocalNode localNode, Wallet wallet, string log_dictionary) - : base(localNode, wallet) - { - this.log_dictionary = log_dictionary; - } - - protected override bool CheckPolicy(Transaction tx) - { - switch (Policy.Default.PolicyLevel) - { - case PolicyLevel.AllowAll: - return true; - case PolicyLevel.AllowList: - return tx.Scripts.All(p => Policy.Default.List.Contains(p.VerificationScript.ToScriptHash())) || tx.Outputs.All(p => Policy.Default.List.Contains(p.ScriptHash)); - case PolicyLevel.DenyList: - return tx.Scripts.All(p => !Policy.Default.List.Contains(p.VerificationScript.ToScriptHash())) && tx.Outputs.All(p => !Policy.Default.List.Contains(p.ScriptHash)); - default: - return base.CheckPolicy(tx); - } - } - - protected override void Log(string message) - { - DateTime now = DateTime.Now; - string line = $"[{now.TimeOfDay:hh\\:mm\\:ss}] {message}"; - Console.WriteLine(line); - if (string.IsNullOrEmpty(log_dictionary)) return; - lock (log_dictionary) - { - Directory.CreateDirectory(log_dictionary); - string path = Path.Combine(log_dictionary, $"{now:yyyy-MM-dd}.log"); - File.AppendAllLines(path, new[] { line }); - } - } - - public void RefreshPolicy() - { - Policy.Default.Refresh(); - } - } -} diff --git a/neo-cli/Consensus/Policy.cs b/neo-cli/Consensus/Policy.cs deleted file mode 100644 index c7cc384f8..000000000 --- a/neo-cli/Consensus/Policy.cs +++ /dev/null @@ -1,38 +0,0 @@ -using Neo.Wallets; -using Microsoft.Extensions.Configuration; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; - -namespace Neo.Consensus -{ - internal class Policy - { - public PolicyLevel PolicyLevel { get; private set; } - public HashSet List { get; private set; } - - public static Policy Default { get; private set; } - - static Policy() - { - Default = new Policy(); - Default.Refresh(); - } - - public void Refresh() - { - if (File.Exists("policy.json")) - { - IConfigurationSection section = new ConfigurationBuilder().AddJsonFile("policy.json").Build().GetSection("PolicyConfiguration"); - PolicyLevel = (PolicyLevel)Enum.Parse(typeof(PolicyLevel), section.GetSection("PolicyLevel").Value, true); - List = new HashSet(section.GetSection("List").GetChildren().Select(p => Wallet.ToScriptHash(p.Value))); - } - else - { - PolicyLevel = PolicyLevel.AllowAll; - List = new HashSet(); - } - } - } -} diff --git a/neo-cli/Consensus/PolicyLevel.cs b/neo-cli/Consensus/PolicyLevel.cs deleted file mode 100644 index 55ea03489..000000000 --- a/neo-cli/Consensus/PolicyLevel.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace Neo.Consensus -{ - internal enum PolicyLevel : byte - { - AllowAll, - DenyAll, - AllowList, - DenyList - } -} diff --git a/neo-cli/Shell/MainService.cs b/neo-cli/Shell/MainService.cs index 9898a5bda..3f6337138 100644 --- a/neo-cli/Shell/MainService.cs +++ b/neo-cli/Shell/MainService.cs @@ -29,7 +29,7 @@ internal class MainService : ConsoleServiceBase private const string PeerStatePath = "peers.dat"; private RpcServerWithWallet rpc; - private ConsensusWithPolicy consensus; + private ConsensusWithLog consensus; protected LocalNode LocalNode { get; private set; } protected override string Prompt => "neo"; @@ -78,8 +78,6 @@ protected override bool OnCommand(string[] args) return OnOpenCommand(args); case "rebuild": return OnRebuildCommand(args); - case "refresh": - return OnRefreshCommand(args); case "send": return OnSendCommand(args); case "show": @@ -407,8 +405,7 @@ private bool OnHelpCommand(string[] args) "\texport block[s] [path=chain.acc]\n" + "\texport block[s] [count]\n" + "Advanced Commands:\n" + - "\tstart consensus\n" + - "\trefresh policy\n"); + "\tstart consensus\n"); return true; } @@ -617,24 +614,6 @@ private bool OnRebuildIndexCommand(string[] args) return true; } - private bool OnRefreshCommand(string[] args) - { - switch (args[1].ToLower()) - { - case "policy": - return OnRefreshPolicyCommand(args); - default: - return base.OnCommand(args); - } - } - - private bool OnRefreshPolicyCommand(string[] args) - { - if (consensus == null) return true; - consensus.RefreshPolicy(); - return true; - } - private bool OnSendCommand(string[] args) { if (args.Length < 4 || args.Length > 5) @@ -941,7 +920,7 @@ private bool OnStartConsensusCommand(string[] args) return true; } string log_dictionary = Path.Combine(AppContext.BaseDirectory, "Logs"); - consensus = new ConsensusWithPolicy(LocalNode, Program.Wallet, log_dictionary); + consensus = new ConsensusWithLog(LocalNode, Program.Wallet, log_dictionary); ShowPrompt = false; consensus.Start(); return true; diff --git a/neo-cli/neo-cli.csproj b/neo-cli/neo-cli.csproj index 511f30821..56d33b7f6 100644 --- a/neo-cli/neo-cli.csproj +++ b/neo-cli/neo-cli.csproj @@ -3,7 +3,7 @@ 2016-2017 The Neo Project Neo.CLI - 2.7.4 + 2.7.5 The Neo Project netcoreapp2.0 neo-cli @@ -28,7 +28,7 @@ - +