2024-06-14 11:05:29 +02:00
|
|
|
|
using CodexContractsPlugin.ChainMonitor;
|
2024-04-07 14:04:31 +02:00
|
|
|
|
using DiscordRewards;
|
2024-06-27 10:07:10 +02:00
|
|
|
|
using GethPlugin;
|
2024-06-17 15:34:08 +02:00
|
|
|
|
using Logging;
|
2024-04-07 14:04:31 +02:00
|
|
|
|
using System.Numerics;
|
|
|
|
|
|
|
|
|
|
namespace TestNetRewarder
|
|
|
|
|
{
|
2024-06-14 11:05:29 +02:00
|
|
|
|
public class MarketTracker : IChainStateChangeHandler
|
2024-04-07 14:04:31 +02:00
|
|
|
|
{
|
2024-06-17 15:34:08 +02:00
|
|
|
|
private readonly List<MarketBuffer> buffers = new List<MarketBuffer>();
|
|
|
|
|
private readonly ILog log;
|
2024-04-07 14:04:31 +02:00
|
|
|
|
|
2024-06-17 15:34:08 +02:00
|
|
|
|
public MarketTracker(Configuration config, ILog log)
|
2024-04-07 14:04:31 +02:00
|
|
|
|
{
|
2024-06-17 15:34:08 +02:00
|
|
|
|
var intervals = GetInsightCounts(config);
|
2024-04-07 14:04:31 +02:00
|
|
|
|
|
2024-06-17 15:34:08 +02:00
|
|
|
|
foreach (var i in intervals)
|
2024-04-07 14:04:31 +02:00
|
|
|
|
{
|
2024-06-17 15:34:08 +02:00
|
|
|
|
buffers.Add(new MarketBuffer(
|
|
|
|
|
config.Interval * i
|
|
|
|
|
));
|
2024-04-07 14:04:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
2024-06-17 15:34:08 +02:00
|
|
|
|
this.log = log;
|
2024-04-07 14:04:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
2024-06-17 15:34:08 +02:00
|
|
|
|
public MarketAverage[] GetAverages()
|
2024-04-07 14:04:31 +02:00
|
|
|
|
{
|
2024-06-17 15:34:08 +02:00
|
|
|
|
foreach (var b in buffers) b.Update();
|
|
|
|
|
|
|
|
|
|
return buffers.Select(b => b.GetAverage()).Where(a => a != null).Cast<MarketAverage>().ToArray();
|
2024-04-07 14:04:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
2024-06-27 11:43:25 +02:00
|
|
|
|
public void OnNewRequest(RequestEvent requestEvent)
|
2024-04-07 14:04:31 +02:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-27 11:43:25 +02:00
|
|
|
|
public void OnRequestFinished(RequestEvent requestEvent)
|
2024-04-07 14:04:31 +02:00
|
|
|
|
{
|
2024-06-27 11:43:25 +02:00
|
|
|
|
foreach (var b in buffers) b.Add(requestEvent);
|
2024-04-07 14:04:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
2024-06-27 11:43:25 +02:00
|
|
|
|
public void OnRequestFulfilled(RequestEvent requestEvent)
|
2024-04-07 14:04:31 +02:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-27 11:43:25 +02:00
|
|
|
|
public void OnRequestCancelled(RequestEvent requestEvent)
|
2024-04-07 14:04:31 +02:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-27 11:43:25 +02:00
|
|
|
|
public void OnSlotFilled(RequestEvent requestEvent, EthAddress host, BigInteger slotIndex)
|
2024-04-07 14:04:31 +02:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-27 11:43:25 +02:00
|
|
|
|
public void OnSlotFreed(RequestEvent requestEvent, BigInteger slotIndex)
|
2024-04-07 14:04:31 +02:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-17 15:34:08 +02:00
|
|
|
|
private int[] GetInsightCounts(Configuration config)
|
2024-04-07 14:04:31 +02:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2024-06-17 15:34:08 +02:00
|
|
|
|
var tokens = config.MarketInsights.Split(';').ToArray();
|
2024-04-07 14:04:31 +02:00
|
|
|
|
return tokens.Select(t => Convert.ToInt32(t)).ToArray();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2024-06-17 15:34:08 +02:00
|
|
|
|
log.Error($"Exception when parsing MarketInsights config parameters: {ex}");
|
2024-04-07 14:04:31 +02:00
|
|
|
|
}
|
2024-06-17 15:34:08 +02:00
|
|
|
|
return Array.Empty<int>();
|
2024-06-14 11:05:29 +02:00
|
|
|
|
}
|
2024-04-07 14:04:31 +02:00
|
|
|
|
}
|
|
|
|
|
}
|