-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathProgram.cs
95 lines (82 loc) · 3.2 KB
/
Program.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
using Meadow.Core.AccountDerivation;
using System;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
namespace Meadow.TestNode.Host
{
class Program
{
static async Task Main(string[] args)
{
var opts = ProcessArgs.Parse(args);
if (!string.IsNullOrWhiteSpace(opts.Proxy))
{
// TODO: testnode.host proxy support
throw new NotImplementedException();
}
IPAddress host;
if (string.IsNullOrWhiteSpace(opts.Host) || opts.Host.Equals("localhost", StringComparison.OrdinalIgnoreCase))
{
host = IPAddress.Loopback;
}
else if (opts.Host == "*")
{
host = IPAddress.Any;
}
else if (IPAddress.TryParse(opts.Host, out var addr))
{
host = addr;
}
else
{
var entry = await Dns.GetHostEntryAsync(opts.Host);
host = entry.AddressList[0];
}
// Setup account derivation / keys
IAccountDerivation accountDerivation;
if (string.IsNullOrWhiteSpace(opts.Mnemonic))
{
var hdWalletAccountDerivation = HDAccountDerivation.Create();
accountDerivation = hdWalletAccountDerivation;
Console.WriteLine($"Using mnemonic phrase: '{hdWalletAccountDerivation.MnemonicPhrase}'");
Console.WriteLine("Warning: this private key generation is not secure and should not be used in production.");
}
else
{
accountDerivation = new HDAccountDerivation(opts.Mnemonic);
}
var accountConfig = new AccountConfiguration
{
AccountGenerationCount = (int)opts.AccountCount,
DefaultAccountEtherBalance = opts.AccountBalance,
AccountDerivationMethod = accountDerivation
};
// Create our local test node.
using (var testNodeServer = new TestNodeServer(
port: (int)opts.Port,
address: host,
accountConfig: accountConfig))
{
Console.WriteLine("Starting server...");
testNodeServer.RpcServer.DebugLogger = Console.WriteLine;
// Start our local test node.
await testNodeServer.RpcServer.StartAsync();
// Create an RPC client for our local test node.
var serverAddresses = string.Join(", ", testNodeServer.RpcServer.ServerAddresses);
Console.WriteLine($"Test node server listening on: {serverAddresses}");
// Listen for exit request.
var exitEvent = new SemaphoreSlim(0, 1);
Console.CancelKeyPress += (s, e) =>
{
exitEvent.Release();
e.Cancel = true;
};
// Shutdown.
await exitEvent.WaitAsync();
Console.WriteLine("Stopping server and exiting...");
await testNodeServer.RpcServer.StopAsync();
}
}
}
}