-
Notifications
You must be signed in to change notification settings - Fork 102
/
Settings.cs
56 lines (48 loc) · 1.78 KB
/
Settings.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using Microsoft.Extensions.Configuration;
using Neo.Wallets;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
namespace Neo.Plugins
{
internal class Settings
{
public int MaxTransactionsPerBlock { get; }
public int MaxFreeTransactionsPerBlock { get; }
public BlockedAccounts BlockedAccounts { get; }
public static Settings Default { get; }
static Settings()
{
Default = new Settings(Assembly.GetExecutingAssembly().GetConfiguration());
}
public Settings(IConfigurationSection section)
{
this.MaxTransactionsPerBlock = GetValueOrDefault(section.GetSection("MaxTransactionsPerBlock"), 500, p => int.Parse(p));
this.MaxFreeTransactionsPerBlock = GetValueOrDefault(section.GetSection("MaxFreeTransactionsPerBlock"), 20, p => int.Parse(p));
this.BlockedAccounts = new BlockedAccounts(section.GetSection("BlockedAccounts"));
}
public T GetValueOrDefault<T>(IConfigurationSection section, T defaultValue, Func<string, T> selector)
{
if (section.Value == null) return defaultValue;
return selector(section.Value);
}
}
internal enum PolicyType : byte
{
AllowAll,
DenyAll,
AllowList,
DenyList
}
internal class BlockedAccounts
{
public PolicyType Type { get; }
public HashSet<UInt160> List { get; }
public BlockedAccounts(IConfigurationSection section)
{
this.Type = (PolicyType)Enum.Parse(typeof(PolicyType), section.GetSection("Type").Value, true);
this.List = new HashSet<UInt160>(section.GetSection("List").GetChildren().Select(p => Wallet.ToScriptHash(p.Value)));
}
}
}