2024-05-31 09:19:50 +00:00
|
|
|
|
using CodexContractsPlugin.Marketplace;
|
|
|
|
|
using Logging;
|
|
|
|
|
|
|
|
|
|
namespace CodexContractsPlugin.ChainMonitor
|
|
|
|
|
{
|
|
|
|
|
public interface IChainStateRequest
|
|
|
|
|
{
|
|
|
|
|
Request Request { get; }
|
|
|
|
|
RequestState State { get; }
|
|
|
|
|
DateTime ExpiryUtc { get; }
|
|
|
|
|
DateTime FinishedUtc { get; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class ChainStateRequest : IChainStateRequest
|
|
|
|
|
{
|
|
|
|
|
private readonly ILog log;
|
|
|
|
|
|
|
|
|
|
public ChainStateRequest(ILog log, Request request, RequestState state)
|
|
|
|
|
{
|
|
|
|
|
this.log = log;
|
|
|
|
|
Request = request;
|
|
|
|
|
State = state;
|
|
|
|
|
|
|
|
|
|
ExpiryUtc = request.Block.Utc + TimeSpan.FromSeconds((double)request.Expiry);
|
|
|
|
|
FinishedUtc = request.Block.Utc + TimeSpan.FromSeconds((double)request.Ask.Duration);
|
|
|
|
|
|
2024-06-10 12:04:25 +00:00
|
|
|
|
log.Log($"Created as {State}.");
|
2024-05-31 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Request Request { get; }
|
|
|
|
|
public RequestState State { get; private set; }
|
|
|
|
|
public DateTime ExpiryUtc { get; }
|
|
|
|
|
public DateTime FinishedUtc { get; }
|
|
|
|
|
|
|
|
|
|
public void UpdateState(RequestState newState)
|
|
|
|
|
{
|
2024-06-10 12:04:25 +00:00
|
|
|
|
Log($"Transit: {State} -> {newState}");
|
2024-05-31 09:19:50 +00:00
|
|
|
|
State = newState;
|
|
|
|
|
}
|
2024-06-10 12:04:25 +00:00
|
|
|
|
|
|
|
|
|
public void Log(string msg)
|
|
|
|
|
{
|
|
|
|
|
log.Log($"Request '{Request.Id}': {msg}");
|
|
|
|
|
}
|
2024-05-31 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|