Skip to content

Commit

Permalink
2.7.6
Browse files Browse the repository at this point in the history
  • Loading branch information
erikzhang committed Jul 6, 2018
1 parent 90d1d63 commit c87c568
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 30 deletions.
5 changes: 4 additions & 1 deletion SimplePolicy/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Neo.Wallets;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;

Expand All @@ -17,7 +18,9 @@ internal class Settings

static Settings()
{
Default = new Settings(Assembly.GetExecutingAssembly().GetConfiguration());
string path = Path.Combine(Assembly.GetExecutingAssembly().GetName().Name, "config.json");
IConfigurationSection section = new ConfigurationBuilder().AddJsonFile(path).Build().GetSection("PluginConfiguration");
Default = new Settings(section);
}

public Settings(IConfigurationSection section)
Expand Down
6 changes: 3 additions & 3 deletions SimplePolicy/SimplePolicy.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Version>3.0.0-preview2-02</Version>
<Version>2.7.6</Version>
<TargetFrameworks>netstandard2.0;net47</TargetFrameworks>
<RootNamespace>Neo.Plugins</RootNamespace>
</PropertyGroup>
Expand All @@ -14,7 +14,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Neo" Version="3.0.0-preview2-02" />
<PackageReference Include="Neo" Version="2.7.6" />
</ItemGroup>

</Project>
33 changes: 7 additions & 26 deletions SimplePolicy/SimplePolicyPlugin.cs
Original file line number Diff line number Diff line change
@@ -1,33 +1,29 @@
using Neo.Consensus;
using Neo.Network.P2P.Payloads;
using Neo.SmartContract;
using System;
using Neo.Core;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Neo.Plugins
{
public class SimplePolicyPlugin : Plugin, ILogPlugin, IPolicyPlugin
public class SimplePolicyPlugin : PolicyPlugin
{
private static string log_dictionary = Path.Combine(AppContext.BaseDirectory, "Logs");
public override string Name => GetType().Name;

public bool CheckPolicy(Transaction tx)
protected override bool CheckPolicy(Transaction tx)
{
switch (Settings.Default.BlockedAccounts.Type)
{
case PolicyType.AllowAll:
return true;
case PolicyType.AllowList:
return tx.Witnesses.All(p => Settings.Default.BlockedAccounts.List.Contains(p.VerificationScript.ToScriptHash())) || tx.Outputs.All(p => Settings.Default.BlockedAccounts.List.Contains(p.ScriptHash));
return tx.Scripts.All(p => Settings.Default.BlockedAccounts.List.Contains(p.VerificationScript.ToScriptHash())) || tx.Outputs.All(p => Settings.Default.BlockedAccounts.List.Contains(p.ScriptHash));
case PolicyType.DenyList:
return tx.Witnesses.All(p => !Settings.Default.BlockedAccounts.List.Contains(p.VerificationScript.ToScriptHash())) && tx.Outputs.All(p => !Settings.Default.BlockedAccounts.List.Contains(p.ScriptHash));
return tx.Scripts.All(p => !Settings.Default.BlockedAccounts.List.Contains(p.VerificationScript.ToScriptHash())) && tx.Outputs.All(p => !Settings.Default.BlockedAccounts.List.Contains(p.ScriptHash));
default:
return false;
}
}

public IEnumerable<Transaction> Filter(IEnumerable<Transaction> transactions)
protected override IEnumerable<Transaction> Filter(IEnumerable<Transaction> transactions)
{
Transaction[] array = transactions.ToArray();
if (array.Length + 1 <= Settings.Default.MaxTransactionsPerBlock)
Expand All @@ -47,20 +43,5 @@ private IEnumerable<Transaction> FilterFree(IEnumerable<Transaction> transaction
else
yield break;
}

void ILogPlugin.Log(string source, LogLevel level, string message)
{
if (source != nameof(ConsensusService)) return;
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 });
}
}
}
}

0 comments on commit c87c568

Please sign in to comment.