Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
172 changes: 0 additions & 172 deletions CHANGELOG.md

This file was deleted.

32 changes: 0 additions & 32 deletions neo-cli/Consensus/ConsensusWithLog.cs

This file was deleted.

54 changes: 54 additions & 0 deletions neo-cli/Consensus/ConsensusWithPolicy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
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();
}
}
}
38 changes: 38 additions & 0 deletions neo-cli/Consensus/Policy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
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<UInt160> 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<UInt160>(section.GetSection("List").GetChildren().Select(p => Wallet.ToScriptHash(p.Value)));
}
else
{
PolicyLevel = PolicyLevel.AllowAll;
List = new HashSet<UInt160>();
}
}
}
}
10 changes: 10 additions & 0 deletions neo-cli/Consensus/PolicyLevel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Neo.Consensus
{
internal enum PolicyLevel : byte
{
AllowAll,
DenyAll,
AllowList,
DenyList
}
}
15 changes: 4 additions & 11 deletions neo-cli/Network/RPC/RpcServerWithWallet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,11 @@ protected override JObject Process(string method, JArray _params)
throw new RpcException(-400, "Access denied.");
else
{
UInt256 assetId = UInt256.Parse(_params[0].AsString());
IEnumerable<Coin> coins = Program.Wallet.GetCoins().Where(p => !p.State.HasFlag(CoinState.Spent) && p.Output.AssetId.Equals(assetId));
JObject json = new JObject();
switch (UIntBase.Parse(_params[0].AsString()))
{
case UInt160 asset_id_160: //NEP-5 balance
json["balance"] = Program.Wallet.GetAvailable(asset_id_160).ToString();
break;
case UInt256 asset_id_256: //Global Assets balance
IEnumerable<Coin> coins = Program.Wallet.GetCoins().Where(p => !p.State.HasFlag(CoinState.Spent) && p.Output.AssetId.Equals(asset_id_256));
json["balance"] = coins.Sum(p => p.Output.Value).ToString();
json["confirmed"] = coins.Where(p => p.State.HasFlag(CoinState.Confirmed)).Sum(p => p.Output.Value).ToString();
break;
}
json["balance"] = coins.Sum(p => p.Output.Value).ToString();
json["confirmed"] = coins.Where(p => p.State.HasFlag(CoinState.Confirmed)).Sum(p => p.Output.Value).ToString();
return json;
}
case "listaddress":
Expand Down
8 changes: 2 additions & 6 deletions neo-cli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Neo
{
static class Program
{
internal static Wallet Wallet;
internal static Wallet Wallet;

private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
Expand All @@ -21,11 +21,7 @@ private static void CurrentDomain_UnhandledException(object sender, UnhandledExc
static void Main(string[] args)
{
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
var bufferSize = 1024 * 67 + 128;
Stream inputStream = Console.OpenStandardInput(bufferSize);
Console.SetIn(new StreamReader(inputStream, Console.InputEncoding, false, bufferSize));
var mainService = new MainService();
mainService.Run(args);
new MainService().Run(args);
}

private static void PrintErrorLogs(StreamWriter writer, Exception ex)
Expand Down
3 changes: 1 addition & 2 deletions neo-cli/Services/ConsoleServiceBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Reflection;
using System.Security;
using System.Text;
using Neo.Shell;

namespace Neo.Services
{
Expand All @@ -14,7 +13,7 @@ public abstract class ConsoleServiceBase

protected bool ShowPrompt { get; set; } = true;

protected virtual bool OnCommand(string[] args)
protected virtual bool OnCommand(string[] args)
{
switch (args[0].ToLower())
{
Expand Down
Loading