-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgram.cs
More file actions
129 lines (106 loc) · 4.21 KB
/
Program.cs
File metadata and controls
129 lines (106 loc) · 4.21 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
using NetCoreServer;
using Org.BouncyCastle.X509;
using RippleDotNet;
using RippleDotNet.Model.Transaction;
using RippleDotNet.Requests.Transaction;
using RippleDotNet.Responses.Transaction.Interfaces;
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Security.Authentication;
using System.Security.Cryptography.X509Certificates;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
namespace XLS_20_Bridge_MasterProcess
{
class Program
{
private static System.Timers.Timer t;
private static Settings config;
private static database db;
private static Ethereum eth;
private static Xrpl xrpl;
private static ValidatorMessage validatorMessage;
private static Recovery recovery;
private static dynamic validatorServer;
private static dynamic apiServer;
static async Task Main(string[] args)
{
bool runServer = true;
config = new Settings();
// WebSocket server port
Console.WriteLine($"Validator WebSocket server port: {config._serverPort}");
Console.WriteLine($"API server port: {config._httpsServerPort}");
Console.WriteLine();
if (config._sslEnabled)
{
// Create and prepare a new SSL server context
var context = new SslContext(SslProtocols.Tls12, new X509Certificate2(config._sslCertPath, config._sslCertPassword == "" ? null : config._sslCertPassword));
// Create a new WebSocket server
validatorServer = new ValidatorSocketServerWss(context, IPAddress.Any, config._serverPort);
//Create http/https server for front end
apiServer = new ApiServerHttps(context, IPAddress.Any, config._httpsServerPort);
}
else
{
// Create a new WebSocket server
validatorServer = new ValidatorSocketServer(IPAddress.Any, config._serverPort);
//Create http/https server for front end
apiServer = new ApiServer(IPAddress.Any, config._httpsServerPort);
}
// Start the server
Console.Write("Servers starting...");
validatorServer.Start();
apiServer.Start();
Console.WriteLine("Done!");
db = new database();
eth = new Ethereum(config, db);
xrpl = new Xrpl(db, config, validatorServer);
validatorMessage = new ValidatorMessage(db, config, validatorServer);
recovery = new Recovery(db, config, eth, xrpl);
bool startValid = await recovery.CheckForRecoveryMode();
if (!startValid)
{
Console.WriteLine($"Startup Invalid. Shutting Down. Pretty any key to exit.");
Console.ReadLine();
return;
}
//Add validator Ping records
for(int i=1;i<=config._numberOfValidators;i++)
{
db.ValidatorUpdatePing(i.ToString());
}
Console.WriteLine("Starting Master Process");
t = new System.Timers.Timer();
t.AutoReset = false;
t.Elapsed += new System.Timers.ElapsedEventHandler(t_ElapsedAsync);
t.Interval = (config._tickTime * 1000);
t.Start();
while (runServer)
{
}
}
static async void t_ElapsedAsync(object sender, System.Timers.ElapsedEventArgs e)
{
PingValidators();
await eth.PullBridgeContractDataAsync(config._blockNumber);
validatorMessage.PushNewNFTsToValidators();
validatorMessage.CheckForSignedMessages();
await xrpl.SendNFTTransactions();
validatorMessage.CheckForSignedOfferMessages();
await xrpl.SendNFTOfferTransactions();
t.Interval = (config._tickTime * 1000);
t.Start();
}
static void PingValidators()
{
List<string> validators = db.GetValidatorsToPing(5);
if(validators.Count > 0)
{
validatorMessage.SendPing();
}
}
}
}