2025-04-16 16:25:31 +02:00
|
|
|
|
using CodexContractsPlugin.ChainMonitor;
|
|
|
|
|
|
using DiscordRewards;
|
2025-01-16 13:51:29 +01:00
|
|
|
|
using Utils;
|
2024-06-17 15:34:08 +02:00
|
|
|
|
|
|
|
|
|
|
namespace TestNetRewarder
|
|
|
|
|
|
{
|
2025-04-16 15:17:40 +02:00
|
|
|
|
public class RequestBuilder
|
2024-06-17 15:34:08 +02:00
|
|
|
|
{
|
2025-04-16 16:25:31 +02:00
|
|
|
|
public EventsAndErrors Build(ChainState chainState, ChainEventMessage[] lines, string[] errors)
|
2024-06-17 15:34:08 +02:00
|
|
|
|
{
|
2025-04-16 16:25:31 +02:00
|
|
|
|
var activeChainAddresses = CollectActiveAddresses(chainState);
|
|
|
|
|
|
|
2025-04-16 15:17:40 +02:00
|
|
|
|
return new EventsAndErrors
|
2024-06-17 15:34:08 +02:00
|
|
|
|
{
|
2024-10-18 11:03:05 +02:00
|
|
|
|
EventsOverview = lines,
|
2025-04-16 16:25:31 +02:00
|
|
|
|
Errors = errors,
|
|
|
|
|
|
ActiveChainAddresses = activeChainAddresses
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private ActiveChainAddresses CollectActiveAddresses(ChainState chainState)
|
|
|
|
|
|
{
|
|
|
|
|
|
var hosts = new List<string>();
|
|
|
|
|
|
var clients = new List<string>();
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var request in chainState.Requests)
|
|
|
|
|
|
{
|
|
|
|
|
|
CollectAddresses(request, hosts, clients);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return new ActiveChainAddresses
|
|
|
|
|
|
{
|
|
|
|
|
|
Hosts = hosts.ToArray(),
|
|
|
|
|
|
Clients = clients.ToArray()
|
2024-06-17 15:34:08 +02:00
|
|
|
|
};
|
|
|
|
|
|
}
|
2025-04-16 16:25:31 +02:00
|
|
|
|
|
|
|
|
|
|
private void CollectAddresses(IChainStateRequest request, List<string> hosts, List<string> clients)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (request.State != CodexContractsPlugin.RequestState.Started) return;
|
|
|
|
|
|
|
|
|
|
|
|
AddIfNew(clients, request.Client);
|
|
|
|
|
|
foreach (var host in request.Hosts.GetHosts())
|
|
|
|
|
|
{
|
|
|
|
|
|
AddIfNew(hosts, host);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void AddIfNew(List<string> list, EthAddress address)
|
|
|
|
|
|
{
|
|
|
|
|
|
var addr = address.Address;
|
|
|
|
|
|
if (!list.Contains(addr)) list.Add(addr);
|
|
|
|
|
|
}
|
2024-06-17 15:34:08 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|