diff --git a/ProjectPlugins/CodexContractsPlugin/Marketplace/Customizations.cs b/ProjectPlugins/CodexContractsPlugin/Marketplace/Customizations.cs index 8e8edb2..68427b6 100644 --- a/ProjectPlugins/CodexContractsPlugin/Marketplace/Customizations.cs +++ b/ProjectPlugins/CodexContractsPlugin/Marketplace/Customizations.cs @@ -1,5 +1,6 @@ #pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. using GethPlugin; +using NethereumWorkflow.BlockUtils; using Newtonsoft.Json; namespace CodexContractsPlugin.Marketplace @@ -7,7 +8,7 @@ namespace CodexContractsPlugin.Marketplace public partial class Request : RequestBase { [JsonIgnore] - public ulong BlockNumber { get; set; } + public BlockTimeEntry Block { get; set; } public byte[] RequestId { get; set; } public EthAddress ClientAddress { get { return new EthAddress(Client); } } @@ -16,26 +17,26 @@ namespace CodexContractsPlugin.Marketplace public partial class RequestFulfilledEventDTO { [JsonIgnore] - public ulong BlockNumber { get; set; } + public BlockTimeEntry Block { get; set; } } public partial class RequestCancelledEventDTO { [JsonIgnore] - public ulong BlockNumber { get; set; } + public BlockTimeEntry Block { get; set; } } public partial class SlotFilledEventDTO { [JsonIgnore] - public ulong BlockNumber { get; set; } + public BlockTimeEntry Block { get; set; } public EthAddress Host { get; set; } } public partial class SlotFreedEventDTO { [JsonIgnore] - public ulong BlockNumber { get; set; } + public BlockTimeEntry Block { get; set; } } } #pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. diff --git a/Tools/BiblioTech/Rewards/RewardController.cs b/Tools/BiblioTech/Rewards/RewardController.cs index 6bf7b9f..99f73ee 100644 --- a/Tools/BiblioTech/Rewards/RewardController.cs +++ b/Tools/BiblioTech/Rewards/RewardController.cs @@ -23,7 +23,10 @@ namespace BiblioTech.Rewards { try { - Program.Averages = cmd.Averages; + if (cmd.Averages != null && cmd.Averages.Any()) + { + Program.Averages = cmd.Averages; + } await Program.RoleDriver.GiveRewards(cmd); } catch (Exception ex) diff --git a/Tools/BiblioTech/Rewards/RoleDriver.cs b/Tools/BiblioTech/Rewards/RoleDriver.cs index 303f069..6695af3 100644 --- a/Tools/BiblioTech/Rewards/RoleDriver.cs +++ b/Tools/BiblioTech/Rewards/RoleDriver.cs @@ -24,6 +24,16 @@ namespace BiblioTech.Rewards { Program.Log.Log($"Processing rewards command: '{JsonConvert.SerializeObject(rewards)}'"); + if (rewards.Rewards.Any()) + { + await ProcessRewards(rewards); + } + + await ProcessChainEvents(rewards.EventsOverview); + } + + private async Task ProcessRewards(GiveRewardsCommand rewards) + { var guild = GetGuild(); // We load all role and user information first, // so we don't ask the server for the same info multiple times. @@ -33,7 +43,6 @@ namespace BiblioTech.Rewards rewardsChannel); await context.ProcessGiveRewardsCommand(LookUpUsers(rewards)); - await ProcessChainEvents(rewards.EventsOverview); } private SocketTextChannel? GetChannel(string name) diff --git a/Tools/TestNetRewarder/BotClient.cs b/Tools/TestNetRewarder/BotClient.cs index 426c501..3ee1fb9 100644 --- a/Tools/TestNetRewarder/BotClient.cs +++ b/Tools/TestNetRewarder/BotClient.cs @@ -1,7 +1,5 @@ -using CodexContractsPlugin.Marketplace; -using DiscordRewards; +using DiscordRewards; using Logging; -using Newtonsoft.Json; using System.Net.Http.Json; namespace TestNetRewarder diff --git a/Tools/TestNetRewarder/ChainState.cs b/Tools/TestNetRewarder/ChainState.cs index b290e78..3f11449 100644 --- a/Tools/TestNetRewarder/ChainState.cs +++ b/Tools/TestNetRewarder/ChainState.cs @@ -1,5 +1,6 @@ using CodexContractsPlugin; using CodexContractsPlugin.Marketplace; +using NethereumWorkflow.BlockUtils; using Newtonsoft.Json; using Utils; @@ -8,6 +9,29 @@ namespace TestNetRewarder public class ChainState { private readonly HistoricState historicState; + private readonly string[] colorIcons = new[] + { + "🔴", + "🟠", + "🟡", + "🟢", + "🔵", + "🟣", + "🟤", + "⚫", + "⚪", + "🟥", + "🟧", + "🟨", + "🟩", + "🟦", + "🟪", + "🟫", + "⬛", + "⬜", + "🔶", + "🔷" + }; public ChainState(HistoricState historicState, ICodexContracts contracts, BlockInterval blockRange) { @@ -52,46 +76,59 @@ namespace TestNetRewarder private StringBlockNumberPair ToPair(Request r) { - return new StringBlockNumberPair("NewRequest", JsonConvert.SerializeObject(r), r.BlockNumber); + return new StringBlockNumberPair("NewRequest", JsonConvert.SerializeObject(r), r.Block, r.RequestId); } private StringBlockNumberPair ToPair(RequestFulfilledEventDTO r) { - return new StringBlockNumberPair("Fulfilled", JsonConvert.SerializeObject(r), r.BlockNumber); + return new StringBlockNumberPair("Fulfilled", JsonConvert.SerializeObject(r), r.Block, r.RequestId); } private StringBlockNumberPair ToPair(RequestCancelledEventDTO r) { - return new StringBlockNumberPair("Cancelled", JsonConvert.SerializeObject(r), r.BlockNumber); + return new StringBlockNumberPair("Cancelled", JsonConvert.SerializeObject(r), r.Block, r.RequestId); } private StringBlockNumberPair ToPair(SlotFilledEventDTO r) { - return new StringBlockNumberPair("SlotFilled", JsonConvert.SerializeObject(r), r.BlockNumber); + return new StringBlockNumberPair("SlotFilled", JsonConvert.SerializeObject(r), r.Block, r.RequestId); } private StringBlockNumberPair ToPair(SlotFreedEventDTO r) { - return new StringBlockNumberPair("SlotFreed", JsonConvert.SerializeObject(r), r.BlockNumber); + return new StringBlockNumberPair("SlotFreed", JsonConvert.SerializeObject(r), r.Block, r.RequestId); } private string ToLine(StringBlockNumberPair pair) { - return $"[{pair.Number}]({pair.Name}) {pair.Str}"; + var nl = Environment.NewLine; + var colorIcon = GetColorIcon(pair.RequestId); + return $"{colorIcon} {pair.Block} ({pair.Name}){nl}" + + $"```json{nl}" + + $"{pair.Str}{nl}" + + $"```"; + } + + private string GetColorIcon(byte[] requestId) + { + var index = requestId[0] % colorIcons.Length; + return colorIcons[index]; } public class StringBlockNumberPair { - public StringBlockNumberPair(string name, string str, ulong number) + public StringBlockNumberPair(string name, string str, BlockTimeEntry block, byte[] requestId) { Name = name; Str = str; - Number = number; + Block = block; + RequestId = requestId; } public string Name { get; } public string Str { get; } - public ulong Number { get; } + public BlockTimeEntry Block { get; } + public byte[] RequestId { get; } } public class StringUtcComparer : IComparer @@ -101,7 +138,7 @@ namespace TestNetRewarder if (x == null && y == null) return 0; if (x == null) return 1; if (y == null) return -1; - return x.Number.CompareTo(y.Number); + return x.Block.BlockNumber.CompareTo(y.Block.BlockNumber); } } }