Removes ChangedEvents field from chain-state, not necessary
This commit is contained in:
parent
525fdcf4a7
commit
1dbb749732
|
@ -20,7 +20,6 @@ namespace TestNetRewarder
|
||||||
|
|
||||||
StartedRequests = historicState.StorageRequests.Where(r => r.RecentlyStarted).ToArray();
|
StartedRequests = historicState.StorageRequests.Where(r => r.RecentlyStarted).ToArray();
|
||||||
FinishedRequests = historicState.StorageRequests.Where(r => r.RecentlyFinished).ToArray();
|
FinishedRequests = historicState.StorageRequests.Where(r => r.RecentlyFinished).ToArray();
|
||||||
ChangedRequests = historicState.StorageRequests.Where(r => r.RecentlyChanged).ToArray();
|
|
||||||
RequestFulfilledEvents = contracts.GetRequestFulfilledEvents(blockRange);
|
RequestFulfilledEvents = contracts.GetRequestFulfilledEvents(blockRange);
|
||||||
RequestCancelledEvents = contracts.GetRequestCancelledEvents(blockRange);
|
RequestCancelledEvents = contracts.GetRequestCancelledEvents(blockRange);
|
||||||
SlotFilledEvents = contracts.GetSlotFilledEvents(blockRange);
|
SlotFilledEvents = contracts.GetSlotFilledEvents(blockRange);
|
||||||
|
@ -31,7 +30,6 @@ namespace TestNetRewarder
|
||||||
public StorageRequest[] AllRequests => historicState.StorageRequests;
|
public StorageRequest[] AllRequests => historicState.StorageRequests;
|
||||||
public StorageRequest[] StartedRequests { get; private set; }
|
public StorageRequest[] StartedRequests { get; private set; }
|
||||||
public StorageRequest[] FinishedRequests { get; private set; }
|
public StorageRequest[] FinishedRequests { get; private set; }
|
||||||
public StorageRequest[] ChangedRequests { get; private set; }
|
|
||||||
public RequestFulfilledEventDTO[] RequestFulfilledEvents { get; }
|
public RequestFulfilledEventDTO[] RequestFulfilledEvents { get; }
|
||||||
public RequestCancelledEventDTO[] RequestCancelledEvents { get; }
|
public RequestCancelledEventDTO[] RequestCancelledEvents { get; }
|
||||||
public SlotFilledEventDTO[] SlotFilledEvents { get; }
|
public SlotFilledEventDTO[] SlotFilledEvents { get; }
|
||||||
|
@ -41,7 +39,7 @@ namespace TestNetRewarder
|
||||||
{
|
{
|
||||||
var entries = new List<StringBlockNumberPair>();
|
var entries = new List<StringBlockNumberPair>();
|
||||||
|
|
||||||
entries.AddRange(ChangedRequests.Select(ToPair));
|
entries.AddRange(NewRequests.Select(ToPair));
|
||||||
entries.AddRange(RequestFulfilledEvents.Select(ToPair));
|
entries.AddRange(RequestFulfilledEvents.Select(ToPair));
|
||||||
entries.AddRange(RequestCancelledEvents.Select(ToPair));
|
entries.AddRange(RequestCancelledEvents.Select(ToPair));
|
||||||
entries.AddRange(SlotFilledEvents.Select(ToPair));
|
entries.AddRange(SlotFilledEvents.Select(ToPair));
|
||||||
|
@ -52,44 +50,46 @@ namespace TestNetRewarder
|
||||||
return entries.Select(ToLine).ToArray();
|
return entries.Select(ToLine).ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
private StringBlockNumberPair ToPair(StorageRequest r)
|
private StringBlockNumberPair ToPair(Request r)
|
||||||
{
|
{
|
||||||
return new StringBlockNumberPair(JsonConvert.SerializeObject(r), r.Request.BlockNumber);
|
return new StringBlockNumberPair("NewRequest", JsonConvert.SerializeObject(r), r.BlockNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
private StringBlockNumberPair ToPair(RequestFulfilledEventDTO r)
|
private StringBlockNumberPair ToPair(RequestFulfilledEventDTO r)
|
||||||
{
|
{
|
||||||
return new StringBlockNumberPair(JsonConvert.SerializeObject(r), r.BlockNumber);
|
return new StringBlockNumberPair("Fulfilled", JsonConvert.SerializeObject(r), r.BlockNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
private StringBlockNumberPair ToPair(RequestCancelledEventDTO r)
|
private StringBlockNumberPair ToPair(RequestCancelledEventDTO r)
|
||||||
{
|
{
|
||||||
return new StringBlockNumberPair(JsonConvert.SerializeObject(r), r.BlockNumber);
|
return new StringBlockNumberPair("Cancelled", JsonConvert.SerializeObject(r), r.BlockNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
private StringBlockNumberPair ToPair(SlotFilledEventDTO r)
|
private StringBlockNumberPair ToPair(SlotFilledEventDTO r)
|
||||||
{
|
{
|
||||||
return new StringBlockNumberPair(JsonConvert.SerializeObject(r), r.BlockNumber);
|
return new StringBlockNumberPair("SlotFilled", JsonConvert.SerializeObject(r), r.BlockNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
private StringBlockNumberPair ToPair(SlotFreedEventDTO r)
|
private StringBlockNumberPair ToPair(SlotFreedEventDTO r)
|
||||||
{
|
{
|
||||||
return new StringBlockNumberPair(JsonConvert.SerializeObject(r), r.BlockNumber);
|
return new StringBlockNumberPair("SlotFreed", JsonConvert.SerializeObject(r), r.BlockNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
private string ToLine(StringBlockNumberPair pair)
|
private string ToLine(StringBlockNumberPair pair)
|
||||||
{
|
{
|
||||||
return $"[{pair.Number}] {pair.Str}";
|
return $"[{pair.Number}]({pair.Name}) {pair.Str}";
|
||||||
}
|
}
|
||||||
|
|
||||||
public class StringBlockNumberPair
|
public class StringBlockNumberPair
|
||||||
{
|
{
|
||||||
public StringBlockNumberPair(string str, ulong number)
|
public StringBlockNumberPair(string name, string str, ulong number)
|
||||||
{
|
{
|
||||||
|
Name = name;
|
||||||
Str = str;
|
Str = str;
|
||||||
Number = number;
|
Number = number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string Name { get; }
|
||||||
public string Str { get; }
|
public string Str { get; }
|
||||||
public ulong Number { get; }
|
public ulong Number { get; }
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,8 +28,6 @@ namespace TestNetRewarder
|
||||||
r.State == RequestState.Finished ||
|
r.State == RequestState.Finished ||
|
||||||
r.State == RequestState.Failed
|
r.State == RequestState.Failed
|
||||||
);
|
);
|
||||||
|
|
||||||
foreach (var r in storageRequests) r.IsNew = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,13 +37,11 @@ namespace TestNetRewarder
|
||||||
{
|
{
|
||||||
Request = request;
|
Request = request;
|
||||||
Hosts = Array.Empty<EthAddress>();
|
Hosts = Array.Empty<EthAddress>();
|
||||||
IsNew = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Request Request { get; }
|
public Request Request { get; }
|
||||||
public EthAddress[] Hosts { get; private set; }
|
public EthAddress[] Hosts { get; private set; }
|
||||||
public RequestState State { get; private set; }
|
public RequestState State { get; private set; }
|
||||||
public bool IsNew { get; set; }
|
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public bool RecentlyStarted { get; private set; }
|
public bool RecentlyStarted { get; private set; }
|
||||||
|
@ -53,9 +49,6 @@ namespace TestNetRewarder
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public bool RecentlyFinished { get; private set; }
|
public bool RecentlyFinished { get; private set; }
|
||||||
|
|
||||||
[JsonIgnore]
|
|
||||||
public bool RecentlyChanged { get; private set; }
|
|
||||||
|
|
||||||
public void Update(ICodexContracts contracts)
|
public void Update(ICodexContracts contracts)
|
||||||
{
|
{
|
||||||
var newHosts = GetHosts(contracts);
|
var newHosts = GetHosts(contracts);
|
||||||
|
@ -70,27 +63,10 @@ namespace TestNetRewarder
|
||||||
State == RequestState.Started &&
|
State == RequestState.Started &&
|
||||||
newState == RequestState.Finished;
|
newState == RequestState.Finished;
|
||||||
|
|
||||||
RecentlyChanged =
|
|
||||||
IsNew ||
|
|
||||||
State != newState ||
|
|
||||||
HostsChanged(newHosts);
|
|
||||||
|
|
||||||
State = newState;
|
State = newState;
|
||||||
Hosts = newHosts;
|
Hosts = newHosts;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool HostsChanged(EthAddress[] newHosts)
|
|
||||||
{
|
|
||||||
if (newHosts.Length != Hosts.Length) return true;
|
|
||||||
|
|
||||||
foreach (var newHost in newHosts)
|
|
||||||
{
|
|
||||||
if (!Hosts.Contains(newHost)) return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private EthAddress[] GetHosts(ICodexContracts contracts)
|
private EthAddress[] GetHosts(ICodexContracts contracts)
|
||||||
{
|
{
|
||||||
var result = new List<EthAddress>();
|
var result = new List<EthAddress>();
|
||||||
|
|
Loading…
Reference in New Issue