Merge branch 'feature/bot-upgrade'
This commit is contained in:
commit
3fb1b212b6
|
@ -5,6 +5,8 @@ using Nethereum.ABI;
|
|||
using Nethereum.Hex.HexTypes;
|
||||
using Nethereum.Util;
|
||||
using NethereumWorkflow;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using Utils;
|
||||
|
||||
namespace CodexContractsPlugin
|
||||
|
@ -28,6 +30,7 @@ namespace CodexContractsPlugin
|
|||
SlotFreedEventDTO[] GetSlotFreedEvents(BlockInterval blockRange);
|
||||
}
|
||||
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
public enum RequestState
|
||||
{
|
||||
New,
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using KubernetesWorkflow;
|
||||
using CodexContractsPlugin.Marketplace;
|
||||
using KubernetesWorkflow;
|
||||
using KubernetesWorkflow.Types;
|
||||
using Logging;
|
||||
using Newtonsoft.Json;
|
||||
|
@ -53,7 +54,18 @@ namespace CodexContractsPlugin
|
|||
|
||||
var artifact = JObject.Parse(json);
|
||||
var abi = artifact["abi"];
|
||||
return abi!.ToString(Formatting.None);
|
||||
var byteCode = artifact["bytecode"];
|
||||
var abiResult = abi!.ToString(Formatting.None);
|
||||
var byteCodeResult = byteCode!.ToString(Formatting.None);
|
||||
|
||||
if (byteCodeResult
|
||||
.ToLowerInvariant()
|
||||
.Replace("\"", "") != MarketplaceDeploymentBase.BYTECODE.ToLowerInvariant())
|
||||
{
|
||||
throw new Exception("BYTECODE in CodexContractsPlugin does not match BYTECODE deployed by container. Update Marketplace.cs generated code?");
|
||||
}
|
||||
|
||||
return abiResult;
|
||||
}
|
||||
|
||||
private static string Retry(Func<string> fetch)
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -45,10 +45,17 @@ namespace BiblioTech.Rewards
|
|||
private async Task ProcessChainEvents(string[] eventsOverview)
|
||||
{
|
||||
if (eventsChannel == null || eventsOverview == null || !eventsOverview.Any()) return;
|
||||
foreach (var e in eventsOverview)
|
||||
await Task.Run(async () =>
|
||||
{
|
||||
await eventsChannel.SendMessageAsync(e);
|
||||
}
|
||||
foreach (var e in eventsOverview)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(e))
|
||||
{
|
||||
await eventsChannel.SendMessageAsync(e);
|
||||
await Task.Delay(3000);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private async Task<Dictionary<ulong, IGuildUser>> LoadAllUsers(SocketGuild guild)
|
||||
|
|
|
@ -11,6 +11,8 @@ namespace TestNetRewarder
|
|||
|
||||
public ChainState(HistoricState historicState, ICodexContracts contracts, BlockInterval blockRange)
|
||||
{
|
||||
this.historicState = historicState;
|
||||
|
||||
NewRequests = contracts.GetStorageRequests(blockRange);
|
||||
historicState.CleanUpOldRequests();
|
||||
historicState.ProcessNewRequests(NewRequests);
|
||||
|
@ -18,19 +20,16 @@ namespace TestNetRewarder
|
|||
|
||||
StartedRequests = historicState.StorageRequests.Where(r => r.RecentlyStarted).ToArray();
|
||||
FinishedRequests = historicState.StorageRequests.Where(r => r.RecentlyFinished).ToArray();
|
||||
ChangedRequests = historicState.StorageRequests.Where(r => r.RecentlyChanged).ToArray();
|
||||
RequestFulfilledEvents = contracts.GetRequestFulfilledEvents(blockRange);
|
||||
RequestCancelledEvents = contracts.GetRequestCancelledEvents(blockRange);
|
||||
SlotFilledEvents = contracts.GetSlotFilledEvents(blockRange);
|
||||
SlotFreedEvents = contracts.GetSlotFreedEvents(blockRange);
|
||||
this.historicState = historicState;
|
||||
}
|
||||
|
||||
public Request[] NewRequests { get; }
|
||||
public StorageRequest[] AllRequests => historicState.StorageRequests;
|
||||
public StorageRequest[] StartedRequests { get; private set; }
|
||||
public StorageRequest[] FinishedRequests { get; private set; }
|
||||
public StorageRequest[] ChangedRequests { get; private set; }
|
||||
public RequestFulfilledEventDTO[] RequestFulfilledEvents { get; }
|
||||
public RequestCancelledEventDTO[] RequestCancelledEvents { get; }
|
||||
public SlotFilledEventDTO[] SlotFilledEvents { get; }
|
||||
|
@ -40,7 +39,7 @@ namespace TestNetRewarder
|
|||
{
|
||||
var entries = new List<StringBlockNumberPair>();
|
||||
|
||||
entries.AddRange(ChangedRequests.Select(ToPair));
|
||||
entries.AddRange(NewRequests.Select(ToPair));
|
||||
entries.AddRange(RequestFulfilledEvents.Select(ToPair));
|
||||
entries.AddRange(RequestCancelledEvents.Select(ToPair));
|
||||
entries.AddRange(SlotFilledEvents.Select(ToPair));
|
||||
|
@ -51,44 +50,46 @@ namespace TestNetRewarder
|
|||
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)
|
||||
{
|
||||
return new StringBlockNumberPair(JsonConvert.SerializeObject(r), r.BlockNumber);
|
||||
return new StringBlockNumberPair("Fulfilled", JsonConvert.SerializeObject(r), r.BlockNumber);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
return new StringBlockNumberPair(JsonConvert.SerializeObject(r), r.BlockNumber);
|
||||
return new StringBlockNumberPair("SlotFilled", JsonConvert.SerializeObject(r), r.BlockNumber);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
return $"[{pair.Number}] {pair.Str}";
|
||||
return $"[{pair.Number}]({pair.Name}) {pair.Str}";
|
||||
}
|
||||
|
||||
public class StringBlockNumberPair
|
||||
{
|
||||
public StringBlockNumberPair(string str, ulong number)
|
||||
public StringBlockNumberPair(string name, string str, ulong number)
|
||||
{
|
||||
Name = name;
|
||||
Str = str;
|
||||
Number = number;
|
||||
}
|
||||
|
||||
public string Name { get; }
|
||||
public string Str { get; }
|
||||
public ulong Number { get; }
|
||||
}
|
||||
|
|
|
@ -28,8 +28,6 @@ namespace TestNetRewarder
|
|||
r.State == RequestState.Finished ||
|
||||
r.State == RequestState.Failed
|
||||
);
|
||||
|
||||
foreach (var r in storageRequests) r.IsNew = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -39,13 +37,11 @@ namespace TestNetRewarder
|
|||
{
|
||||
Request = request;
|
||||
Hosts = Array.Empty<EthAddress>();
|
||||
IsNew = true;
|
||||
}
|
||||
|
||||
public Request Request { get; }
|
||||
public EthAddress[] Hosts { get; private set; }
|
||||
public RequestState State { get; private set; }
|
||||
public bool IsNew { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public bool RecentlyStarted { get; private set; }
|
||||
|
@ -53,9 +49,6 @@ namespace TestNetRewarder
|
|||
[JsonIgnore]
|
||||
public bool RecentlyFinished { get; private set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public bool RecentlyChanged { get; private set; }
|
||||
|
||||
public void Update(ICodexContracts contracts)
|
||||
{
|
||||
var newHosts = GetHosts(contracts);
|
||||
|
@ -70,27 +63,10 @@ namespace TestNetRewarder
|
|||
State == RequestState.Started &&
|
||||
newState == RequestState.Finished;
|
||||
|
||||
RecentlyChanged =
|
||||
IsNew ||
|
||||
State != newState ||
|
||||
HostsChanged(newHosts);
|
||||
|
||||
State = newState;
|
||||
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)
|
||||
{
|
||||
var result = new List<EthAddress>();
|
||||
|
|
Loading…
Reference in New Issue