2
0
mirror of synced 2025-01-12 17:44:08 +00:00

75 lines
1.9 KiB
C#
Raw Normal View History

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;
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
{
private readonly List<MarketBuffer> buffers = new List<MarketBuffer>();
private readonly ILog log;
2024-04-07 14:04:31 +02:00
public MarketTracker(Configuration config, ILog log)
2024-04-07 14:04:31 +02:00
{
var intervals = GetInsightCounts(config);
2024-04-07 14:04:31 +02:00
foreach (var i in intervals)
2024-04-07 14:04:31 +02:00
{
buffers.Add(new MarketBuffer(
config.Interval * i
));
2024-04-07 14:04:31 +02:00
}
this.log = log;
2024-04-07 14:04:31 +02:00
}
public MarketAverage[] GetAverages()
2024-04-07 14:04:31 +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
}
public void OnNewRequest(RequestEvent requestEvent)
2024-04-07 14:04:31 +02:00
{
}
public void OnRequestFinished(RequestEvent requestEvent)
2024-04-07 14:04:31 +02:00
{
foreach (var b in buffers) b.Add(requestEvent);
2024-04-07 14:04:31 +02:00
}
public void OnRequestFulfilled(RequestEvent requestEvent)
2024-04-07 14:04:31 +02:00
{
}
public void OnRequestCancelled(RequestEvent requestEvent)
2024-04-07 14:04:31 +02:00
{
}
public void OnSlotFilled(RequestEvent requestEvent, EthAddress host, BigInteger slotIndex)
2024-04-07 14:04:31 +02:00
{
}
public void OnSlotFreed(RequestEvent requestEvent, BigInteger slotIndex)
2024-04-07 14:04:31 +02:00
{
}
private int[] GetInsightCounts(Configuration config)
2024-04-07 14:04:31 +02:00
{
try
{
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)
{
log.Error($"Exception when parsing MarketInsights config parameters: {ex}");
2024-04-07 14:04:31 +02:00
}
return Array.Empty<int>();
2024-06-14 11:05:29 +02:00
}
2024-04-07 14:04:31 +02:00
}
}