-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathAirdropSettings.cs
81 lines (66 loc) · 3.41 KB
/
AirdropSettings.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using System.Text;
using Blockcore.Configuration;
using Blockcore.Networks;
using Blockcore.Utilities;
using Microsoft.Extensions.Logging;
namespace Blockcore.Features.Airdrop
{
/// <summary>
/// Configuration related to the the airdrop feature.
/// </summary>
public class AirdropSettings
{
/// <summary>Defines block height at wich to create the airdrop.</summary>
public int? SnapshotHeight { get; set; }
public bool SnapshotMode { get; set; }
public bool DistributeMode { get; set; }
/// <summary>Instance logger.</summary>
private readonly ILogger logger;
/// <summary>
/// Initializes an instance of the object from the node configuration.
/// </summary>
/// <param name="nodeSettings">The node configuration.</param>
public AirdropSettings(NodeSettings nodeSettings)
{
Guard.NotNull(nodeSettings, nameof(nodeSettings));
logger = nodeSettings.LoggerFactory.CreateLogger(typeof(AirdropSettings).FullName);
TextFileConfiguration config = nodeSettings.ConfigReader;
SnapshotMode = config.GetOrDefault<bool>("snapshot", false, logger);
DistributeMode = config.GetOrDefault<bool>("distribute", false, logger);
if (SnapshotMode && DistributeMode)
{
throw new ConfigurationException("-distribute and -snapshot can not be both enabled");
}
SnapshotHeight = config.GetOrDefault<int>("snapshotheight", 0, logger);
if (SnapshotHeight == 0)
{
throw new ConfigurationException("-snapshotheight not found or invalid");
}
}
/// <summary>Prints the help information on how to configure the DNS settings to the logger.</summary>
/// <param name="network">The network to use.</param>
public static void PrintHelp(Network network)
{
var builder = new StringBuilder();
builder.AppendLine($"-snapshot Put the airdrop tool in snapshot mode");
builder.AppendLine($"-snapshotheight=<1-max> The height of the chain to take the snapshot form");
builder.AppendLine($"-distribute Put the airdrop tool in distribution mode");
NodeSettings.Default(network).Logger.LogInformation(builder.ToString());
}
/// <summary>
/// Get the default configuration.
/// </summary>
/// <param name="builder">The string builder to add the settings to.</param>
/// <param name="network">The network to base the defaults off.</param>
public static void BuildDefaultConfigurationFile(StringBuilder builder, Network network)
{
builder.AppendLine("####Airdrop Settings####");
builder.AppendLine($"#The height of the chain to take the snapshot this will also be part of the database filename.");
builder.AppendLine($"#-snapshotheight=0");
builder.AppendLine($"#Snapshot mode, to enable the snapshot feature. the snapshot will be written to a SQLite file snapshot.db");
builder.AppendLine($"#-snapshot");
builder.AppendLine($"#Distribute mode, to start distribution. the distribution will read from the db snapshot.db and use the select query in file distribute.sql");
builder.AppendLine($"#-distribute");
}
}
}