cs-codex-dist-tests/ProjectPlugins/CodexContractsPlugin/ChainMonitor/ChainEvents.cs

77 lines
2.7 KiB
C#
Raw Permalink Normal View History

2024-05-31 08:16:57 +00:00
using CodexContractsPlugin.Marketplace;
using System.Collections.Generic;
2024-05-31 08:16:57 +00:00
using Utils;
namespace CodexContractsPlugin.ChainMonitor
{
public class ChainEvents
{
2024-05-31 08:16:57 +00:00
private ChainEvents(
BlockInterval blockInterval,
Request[] requests,
RequestFulfilledEventDTO[] fulfilled,
RequestCancelledEventDTO[] cancelled,
2024-08-21 11:59:54 +00:00
RequestFailedEventDTO[] failed,
2024-05-31 08:16:57 +00:00
SlotFilledEventDTO[] slotFilled,
SlotFreedEventDTO[] slotFreed,
SlotReservationsFullEventDTO[] slotReservationsFull
2024-05-31 08:16:57 +00:00
)
{
BlockInterval = blockInterval;
Requests = requests;
Fulfilled = fulfilled;
Cancelled = cancelled;
2024-08-21 11:59:54 +00:00
Failed = failed;
2024-05-31 08:16:57 +00:00
SlotFilled = slotFilled;
SlotFreed = slotFreed;
SlotReservationsFull = slotReservationsFull;
All = ConcatAll<IHasBlock>(requests, fulfilled, cancelled, failed, slotFilled, SlotFreed, SlotReservationsFull);
2024-05-31 08:16:57 +00:00
}
public BlockInterval BlockInterval { get; }
public Request[] Requests { get; }
public RequestFulfilledEventDTO[] Fulfilled { get; }
public RequestCancelledEventDTO[] Cancelled { get; }
2024-08-21 11:59:54 +00:00
public RequestFailedEventDTO[] Failed { get; }
2024-05-31 08:16:57 +00:00
public SlotFilledEventDTO[] SlotFilled { get; }
public SlotFreedEventDTO[] SlotFreed { get; }
public SlotReservationsFullEventDTO[] SlotReservationsFull { get; }
public IHasBlock[] All { get; }
2024-05-31 08:16:57 +00:00
public static ChainEvents FromBlockInterval(ICodexContracts contracts, BlockInterval blockInterval)
{
return FromContractEvents(contracts.GetEvents(blockInterval));
}
public static ChainEvents FromTimeRange(ICodexContracts contracts, TimeRange timeRange)
{
return FromContractEvents(contracts.GetEvents(timeRange));
}
2024-05-31 08:16:57 +00:00
public static ChainEvents FromContractEvents(ICodexContractsEvents events)
{
return new ChainEvents(
events.BlockInterval,
events.GetStorageRequests(),
events.GetRequestFulfilledEvents(),
events.GetRequestCancelledEvents(),
2024-08-21 11:59:54 +00:00
events.GetRequestFailedEvents(),
2024-05-31 08:16:57 +00:00
events.GetSlotFilledEvents(),
events.GetSlotFreedEvents(),
events.GetSlotReservationsFull()
2024-05-31 08:16:57 +00:00
);
}
private T[] ConcatAll<T>(params T[][] arrays)
{
var result = Array.Empty<T>();
foreach (var array in arrays)
{
result = result.Concat(array).ToArray();
}
return result;
}
}
}