cs-codex-dist-tests/Tools/TestNetRewarder/Processor.cs

59 lines
1.8 KiB
C#
Raw Normal View History

2024-06-14 09:05:29 +00:00
using CodexContractsPlugin;
using CodexContractsPlugin.ChainMonitor;
2024-01-26 23:17:56 +00:00
using Logging;
using Utils;
namespace TestNetRewarder
{
public class Processor : ITimeSegmentHandler
2024-01-26 23:17:56 +00:00
{
private readonly RequestBuilder builder;
private readonly RewardChecker rewardChecker;
private readonly MarketTracker marketTracker;
private readonly BufferLogger bufferLogger;
2024-06-14 09:05:29 +00:00
private readonly ChainState chainState;
private readonly BotClient client;
2024-01-26 23:17:56 +00:00
private readonly ILog log;
public Processor(Configuration config, BotClient client, ICodexContracts contracts, ILog log)
2024-01-26 23:17:56 +00:00
{
this.client = client;
2024-01-26 23:17:56 +00:00
this.log = log;
2024-06-14 09:05:29 +00:00
builder = new RequestBuilder();
rewardChecker = new RewardChecker(builder);
marketTracker = new MarketTracker(config, log);
bufferLogger = new BufferLogger();
var handler = new ChainChangeMux(
rewardChecker.Handler,
marketTracker
);
chainState = new ChainState(new LogSplitter(log, bufferLogger), contracts, handler, config.HistoryStartUtc);
2024-01-26 23:17:56 +00:00
}
2024-06-14 09:05:29 +00:00
public async Task OnNewSegment(TimeRange timeRange)
2024-01-26 23:17:56 +00:00
{
try
{
2024-06-14 09:05:29 +00:00
chainState.Update(timeRange.To);
var averages = marketTracker.GetAverages();
var lines = bufferLogger.Get();
var request = builder.Build(averages, lines);
if (request.HasAny())
{
await client.SendRewards(request);
}
2024-01-26 23:17:56 +00:00
}
catch (Exception ex)
{
log.Error("Exception processing time segment: " + ex);
2024-04-01 11:56:07 +00:00
throw;
2024-01-26 23:17:56 +00:00
}
}
}
}