forked from ajkagy/xls20-bridge-master
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ValidatorMessage.cs
92 lines (87 loc) · 3.3 KB
/
ValidatorMessage.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
namespace XLS_20_Bridge_MasterProcess
{
public class ValidatorMessage
{
private static database db { get; set; }
private static Settings config { get; set; }
private static dynamic validatorServer { get; set; }
public ValidatorMessage(database _db, Settings _config, dynamic _validatorServer)
{
config = _config;
db = _db;
validatorServer = _validatorServer;
}
public void SendPing()
{
Payload payload = new Payload();
payload.type = "Request";
payload.command = "Ping";
payload.validator = "0";
var request = JsonSerializer.Serialize(payload);
validatorServer.MulticastText(request);
}
public void PushNewNFTsToValidators()
{
List<BridgeNFT> list = db.GetPendingNFTs();
foreach (BridgeNFT nft in list)
{
PayloadSign payload = new PayloadSign();
payload.type = "Request";
payload.command = "NewBridgeNFTs";
payload.validator = "0";
payload.contractAddress = nft.contractAddress;
payload.originOwner = nft.originOwner;
payload.tokenId = nft.tokenId;
payload.xrplAddress = nft.xrplAddress;
var request = JsonSerializer.Serialize(payload);
validatorServer.MulticastText(request);
}
}
public void CheckForSignedOfferMessages()
{
List<BridgeNFT> list = db.GetNFTsReadyToBeExecutedOffer();
foreach (BridgeNFT nft in list)
{
Combine payload = new Combine();
payload.type = "Request";
payload.command = "CombineMultiSigOffer";
payload.validator = "0";
payload.contractAddress = nft.contractAddress;
payload.originOwner = nft.originOwner;
payload.tokenId = nft.tokenId;
for (int i = 0; i < config._numberOfValidators; i++)
{
payload.txn_blob.Add(nft.validatorMeta[i].mintOfferSigned);
}
var request = JsonSerializer.Serialize(payload);
validatorServer.MulticastText(request);
}
}
public void CheckForSignedMessages()
{
List<BridgeNFT> list = db.GetNFTsReadyToBeExecuted();
foreach (BridgeNFT nft in list)
{
Combine payload = new Combine();
payload.type = "Request";
payload.command = "CombineMultiSig";
payload.validator = "0";
payload.contractAddress = nft.contractAddress;
payload.originOwner = nft.originOwner;
payload.tokenId = nft.tokenId;
for (int i = 0; i < config._numberOfValidators; i++)
{
payload.txn_blob.Add(nft.validatorMeta[i].mintSign);
}
var request = JsonSerializer.Serialize(payload);
validatorServer.MulticastText(request);
}
}
}
}