From acc9526cd5d8ce0102d480235677677fc1f3ae1d Mon Sep 17 00:00:00 2001 From: benbierens Date: Mon, 29 Jan 2024 11:02:47 -0500 Subject: [PATCH] Extracts reward config from bot and rewarder --- TestNetRewarder/RewardConfig.cs | 50 -------- TestNetRewarder/TestNetRewarder.csproj | 16 --- Tools/BiblioTech/BiblioTech.csproj | 3 +- Tools/BiblioTech/Rewards/RewardsApi.cs | 24 +--- Tools/BiblioTech/Rewards/RewardsRepo.cs | 48 ------- Tools/BiblioTech/Rewards/RoleController.cs | 118 ++++++++++++------ Tools/DiscordRewards/CheckConfig.cs | 21 ++++ .../DiscordRewards/DiscordRewards.csproj | 3 +- .../GiveRewardsCommand.cs | 7 +- Tools/DiscordRewards/RewardConfig.cs | 18 +++ Tools/DiscordRewards/RewardRepo.cs | 53 ++++++++ .../GethConnector}/GethConnector.cs | 0 Tools/GethConnector/GethConnector.csproj | 15 +++ .../GethConnector}/GethInput.cs | 0 .../TestNetRewarder}/BotClient.cs | 2 +- .../TestNetRewarder}/ChainState.cs | 0 .../TestNetRewarder}/Checks.cs | 40 +++++- .../TestNetRewarder}/Configuration.cs | 0 .../TestNetRewarder}/HistoricState.cs | 0 .../TestNetRewarder}/Processor.cs | 30 ++++- .../TestNetRewarder}/Program.cs | 1 + Tools/TestNetRewarder/TestNetRewarder.csproj | 17 +++ .../TestNetRewarder}/TimeSegmenter.cs | 0 cs-codex-dist-testing.sln | 31 +++-- 24 files changed, 294 insertions(+), 203 deletions(-) delete mode 100644 TestNetRewarder/RewardConfig.cs delete mode 100644 TestNetRewarder/TestNetRewarder.csproj delete mode 100644 Tools/BiblioTech/Rewards/RewardsRepo.cs create mode 100644 Tools/DiscordRewards/CheckConfig.cs rename GethConnector/GethConnector.csproj => Tools/DiscordRewards/DiscordRewards.csproj (57%) rename Tools/{BiblioTech/Rewards => DiscordRewards}/GiveRewardsCommand.cs (67%) create mode 100644 Tools/DiscordRewards/RewardConfig.cs create mode 100644 Tools/DiscordRewards/RewardRepo.cs rename {GethConnector => Tools/GethConnector}/GethConnector.cs (100%) create mode 100644 Tools/GethConnector/GethConnector.csproj rename {GethConnector => Tools/GethConnector}/GethInput.cs (100%) rename {TestNetRewarder => Tools/TestNetRewarder}/BotClient.cs (97%) rename {TestNetRewarder => Tools/TestNetRewarder}/ChainState.cs (100%) rename {TestNetRewarder => Tools/TestNetRewarder}/Checks.cs (69%) rename {TestNetRewarder => Tools/TestNetRewarder}/Configuration.cs (100%) rename {TestNetRewarder => Tools/TestNetRewarder}/HistoricState.cs (100%) rename {TestNetRewarder => Tools/TestNetRewarder}/Processor.cs (65%) rename {TestNetRewarder => Tools/TestNetRewarder}/Program.cs (99%) create mode 100644 Tools/TestNetRewarder/TestNetRewarder.csproj rename {TestNetRewarder => Tools/TestNetRewarder}/TimeSegmenter.cs (100%) diff --git a/TestNetRewarder/RewardConfig.cs b/TestNetRewarder/RewardConfig.cs deleted file mode 100644 index 9906359..0000000 --- a/TestNetRewarder/RewardConfig.cs +++ /dev/null @@ -1,50 +0,0 @@ -using Utils; - -namespace TestNetRewarder -{ - public class RewardConfig - { - public RewardConfig(ulong rewardId, ICheck check) - { - RewardId = rewardId; - Check = check; - } - - public ulong RewardId { get; } - public ICheck Check { get; } - } - - public class RewardRepo - { - public RewardConfig[] Rewards { get; } = new RewardConfig[] - { - // Filled any slot - new RewardConfig(123, new FilledAnySlotCheck()), - - // Finished any slot - new RewardConfig(124, new FinishedSlotCheck( - minSize: 0.Bytes(), - minDuration: TimeSpan.Zero)), - - // Finished a sizable slot - new RewardConfig(125, new FinishedSlotCheck( - minSize: 1.GB(), - minDuration: TimeSpan.FromHours(24.0))), - - // Posted any contract - new RewardConfig(126, new PostedContractCheck()), - - // Started any contract - new RewardConfig(127, new StartedContractCheck( - minNumberOfHosts: 1, - minSlotSize: 0.Bytes(), - minDuration: TimeSpan.Zero)), - - // Started a sizable contract - new RewardConfig(127, new StartedContractCheck( - minNumberOfHosts: 4, - minSlotSize: 1.GB(), - minDuration: TimeSpan.FromHours(24.0))) - }; - } -} diff --git a/TestNetRewarder/TestNetRewarder.csproj b/TestNetRewarder/TestNetRewarder.csproj deleted file mode 100644 index 75b2ee1..0000000 --- a/TestNetRewarder/TestNetRewarder.csproj +++ /dev/null @@ -1,16 +0,0 @@ - - - - Exe - net7.0 - enable - enable - - - - - - - - - diff --git a/Tools/BiblioTech/BiblioTech.csproj b/Tools/BiblioTech/BiblioTech.csproj index c941a71..9eb33a4 100644 --- a/Tools/BiblioTech/BiblioTech.csproj +++ b/Tools/BiblioTech/BiblioTech.csproj @@ -10,8 +10,9 @@ - + + diff --git a/Tools/BiblioTech/Rewards/RewardsApi.cs b/Tools/BiblioTech/Rewards/RewardsApi.cs index 17d4362..b534490 100644 --- a/Tools/BiblioTech/Rewards/RewardsApi.cs +++ b/Tools/BiblioTech/Rewards/RewardsApi.cs @@ -1,4 +1,5 @@ -using Newtonsoft.Json; +using DiscordRewards; +using Newtonsoft.Json; using System.Net; using TaskFactory = Utils.TaskFactory; @@ -79,31 +80,10 @@ namespace BiblioTech.Rewards var rewards = JsonConvert.DeserializeObject(content); if (rewards != null) { - AttachUsers(rewards); await ProcessRewards(rewards); } } - private void AttachUsers(GiveRewardsCommand rewards) - { - foreach (var reward in rewards.Rewards) - { - reward.Users = reward.UserAddresses.Select(GetUserFromAddress).Where(u => u != null).Cast().ToArray(); - } - } - - private UserData? GetUserFromAddress(string address) - { - try - { - return Program.UserRepo.GetUserDataForAddress(new GethPlugin.EthAddress(address)); - } - catch - { - return null; - } - } - private async Task ProcessRewards(GiveRewardsCommand rewards) { await roleController.GiveRewards(rewards); diff --git a/Tools/BiblioTech/Rewards/RewardsRepo.cs b/Tools/BiblioTech/Rewards/RewardsRepo.cs deleted file mode 100644 index bbff34a..0000000 --- a/Tools/BiblioTech/Rewards/RewardsRepo.cs +++ /dev/null @@ -1,48 +0,0 @@ -namespace BiblioTech.Rewards -{ - public class RewardsRepo - { - private static string Tag => RoleController.UsernameTag; - - public RoleRewardConfig[] Rewards { get; } - - public RewardsRepo() - { - Rewards = new[] - { - // Join reward - new RoleRewardConfig(1187039439558541498, $"Congratulations {Tag}, you got the test-reward!"), - - //// Hosting: - //// Filled any slot: - //new RoleRewardConfig(1187039439558541498, $"Congratulations {Tag}, you got the test-reward!"), - - //// Finished any slot: - //new RoleRewardConfig(1187039439558541498, $"Congratulations {Tag}, you got the test-reward!"), - - //// Finished a min-256MB min-8h slot: - //new RoleRewardConfig(1187039439558541498, $"Congratulations {Tag}, you got the test-reward!"), - - //// Finished a min-64GB min-24h slot: - //new RoleRewardConfig(1187039439558541498, $"Congratulations {Tag}, you got the test-reward!"), - - //// Oops: - //// Missed a storage proof: - //new RoleRewardConfig(1187039439558541498, $"Congratulations {Tag}, you got the test-reward!"), - - //// Clienting: - //// Posted any contract: - //new RoleRewardConfig(1187039439558541498, $"Congratulations {Tag}, you got the test-reward!"), - - //// Posted any contract that reached started state: - //new RoleRewardConfig(1187039439558541498, $"Congratulations {Tag}, you got the test-reward!"), - - //// Started a contract with min-4 hosts, min-256MB per host, min-8h duration: - //new RoleRewardConfig(1187039439558541498, $"Congratulations {Tag}, you got the test-reward!"), - - //// Started a contract with min-4 hosts, min-64GB per host, min-24h duration: - //new RoleRewardConfig(1187039439558541498, $"Congratulations {Tag}, you got the test-reward!"), - }; - } - } -} diff --git a/Tools/BiblioTech/Rewards/RoleController.cs b/Tools/BiblioTech/Rewards/RoleController.cs index 63274fd..e59e804 100644 --- a/Tools/BiblioTech/Rewards/RoleController.cs +++ b/Tools/BiblioTech/Rewards/RoleController.cs @@ -1,14 +1,14 @@ using Discord; using Discord.WebSocket; +using DiscordRewards; namespace BiblioTech.Rewards { public class RoleController : IDiscordRoleController { - public const string UsernameTag = ""; private readonly DiscordSocketClient client; private readonly SocketTextChannel? rewardsChannel; - private readonly RewardsRepo repo = new RewardsRepo(); + private readonly RewardRepo repo = new RewardRepo(); public RoleController(DiscordSocketClient client) { @@ -30,7 +30,7 @@ namespace BiblioTech.Rewards LookUpAllRoles(guild, rewards), rewardsChannel); - await context.ProcessGiveRewardsCommand(rewards); + await context.ProcessGiveRewardsCommand(LookUpUsers(rewards)); } private async Task> LoadAllUsers(SocketGuild guild) @@ -47,19 +47,19 @@ namespace BiblioTech.Rewards return result; } - private Dictionary LookUpAllRoles(SocketGuild guild, GiveRewardsCommand rewards) + private Dictionary LookUpAllRoles(SocketGuild guild, GiveRewardsCommand rewards) { - var result = new Dictionary(); + var result = new Dictionary(); foreach (var r in rewards.Rewards) { - var role = repo.Rewards.SingleOrDefault(rr => rr.RoleId == r.RewardId); - if (role == null) + if (!result.ContainsKey(r.RewardId)) { - Program.Log.Log($"No RoleReward is configured for reward with id '{r.RewardId}'."); - } - else - { - if (role.SocketRole == null) + var rewardConfig = repo.Rewards.SingleOrDefault(rr => rr.RoleId == r.RewardId); + if (rewardConfig == null) + { + Program.Log.Log($"No Reward is configured for id '{r.RewardId}'."); + } + else { var socketRole = guild.GetRole(r.RewardId); if (socketRole == null) @@ -68,48 +68,99 @@ namespace BiblioTech.Rewards } else { - role.SocketRole = socketRole; + result.Add(r.RewardId, new RoleReward(socketRole, rewardConfig)); } } - result.Add(role.RoleId, role); } } return result; } + private UserReward[] LookUpUsers(GiveRewardsCommand rewards) + { + return rewards.Rewards.Select(LookUpUserData).ToArray(); + } + + private UserReward LookUpUserData(RewardUsersCommand command) + { + return new UserReward(command, + command.UserAddresses + .Select(LookUpUserDataForAddress) + .Where(d => d != null) + .Cast() + .ToArray()); + } + + private UserData? LookUpUserDataForAddress(string address) + { + try + { + return Program.UserRepo.GetUserDataForAddress(new GethPlugin.EthAddress(address)); + } + catch (Exception ex) + { + Program.Log.Error("Error during UserData lookup: " + ex); + return null; + } + } + private SocketGuild GetGuild() { return client.Guilds.Single(g => g.Name == Program.Config.ServerName); } } + public class RoleReward + { + public RoleReward(SocketRole socketRole, RewardConfig reward) + { + SocketRole = socketRole; + Reward = reward; + } + + public SocketRole SocketRole { get; } + public RewardConfig Reward { get; } + } + + public class UserReward + { + public UserReward(RewardUsersCommand rewardCommand, UserData[] users) + { + RewardCommand = rewardCommand; + Users = users; + } + + public RewardUsersCommand RewardCommand { get; } + public UserData[] Users { get; } + } + public class RewardContext { private readonly Dictionary users; - private readonly Dictionary roles; + private readonly Dictionary roles; private readonly SocketTextChannel? rewardsChannel; - public RewardContext(Dictionary users, Dictionary roles, SocketTextChannel? rewardsChannel) + public RewardContext(Dictionary users, Dictionary roles, SocketTextChannel? rewardsChannel) { this.users = users; this.roles = roles; this.rewardsChannel = rewardsChannel; } - public async Task ProcessGiveRewardsCommand(GiveRewardsCommand rewards) + public async Task ProcessGiveRewardsCommand(UserReward[] rewards) { - foreach (var rewardCommand in rewards.Rewards) + foreach (var rewardCommand in rewards) { - if (roles.ContainsKey(rewardCommand.RewardId)) + if (roles.ContainsKey(rewardCommand.RewardCommand.RewardId)) { - var role = roles[rewardCommand.RewardId]; + var role = roles[rewardCommand.RewardCommand.RewardId]; await ProcessRewardCommand(role, rewardCommand); } } } - private async Task ProcessRewardCommand(RoleRewardConfig role, RewardUsersCommand reward) + private async Task ProcessRewardCommand(RoleReward role, UserReward reward) { foreach (var user in reward.Users) { @@ -117,7 +168,7 @@ namespace BiblioTech.Rewards } } - private async Task GiveReward(RoleRewardConfig role, UserData user) + private async Task GiveReward(RoleReward role, UserData user) { if (!users.ContainsKey(user.DiscordId)) { @@ -128,9 +179,9 @@ namespace BiblioTech.Rewards var guildUser = users[user.DiscordId]; var alreadyHas = guildUser.RoleIds.ToArray(); - if (alreadyHas.Any(r => r == role.RoleId)) return; + if (alreadyHas.Any(r => r == role.Reward.RoleId)) return; - await GiveRole(guildUser, role.SocketRole!); + await GiveRole(guildUser, role.SocketRole); await SendNotification(role, user, guildUser); await Task.Delay(1000); } @@ -148,33 +199,20 @@ namespace BiblioTech.Rewards } } - private async Task SendNotification(RoleRewardConfig reward, UserData userData, IGuildUser user) + private async Task SendNotification(RoleReward reward, UserData userData, IGuildUser user) { try { if (userData.NotificationsEnabled && rewardsChannel != null) { - var msg = reward.Message.Replace(RoleController.UsernameTag, $"<@{user.Id}>"); + var msg = reward.Reward.Message.Replace(RewardConfig.UsernameTag, $"<@{user.Id}>"); await rewardsChannel.SendMessageAsync(msg); } } catch (Exception ex) { - Program.Log.Error($"Failed to notify user '{user.DisplayName}' about role '{reward.SocketRole!.Name}': {ex}"); + Program.Log.Error($"Failed to notify user '{user.DisplayName}' about role '{reward.SocketRole.Name}': {ex}"); } } } - - public class RoleRewardConfig - { - public RoleRewardConfig(ulong roleId, string message) - { - RoleId = roleId; - Message = message; - } - - public ulong RoleId { get; } - public string Message { get; } - public SocketRole? SocketRole { get; set; } - } } diff --git a/Tools/DiscordRewards/CheckConfig.cs b/Tools/DiscordRewards/CheckConfig.cs new file mode 100644 index 0000000..9c4fccb --- /dev/null +++ b/Tools/DiscordRewards/CheckConfig.cs @@ -0,0 +1,21 @@ +using Utils; + +namespace DiscordRewards +{ + public class CheckConfig + { + public CheckType Type { get; set; } + public ulong MinNumberOfHosts { get; set; } + public ByteSize MinSlotSize { get; set; } = 0.Bytes(); + public TimeSpan MinDuration { get; set; } = TimeSpan.Zero; + } + + public enum CheckType + { + Uninitialized, + FilledSlot, + FinishedSlot, + PostedContract, + StartedContract, + } +} diff --git a/GethConnector/GethConnector.csproj b/Tools/DiscordRewards/DiscordRewards.csproj similarity index 57% rename from GethConnector/GethConnector.csproj rename to Tools/DiscordRewards/DiscordRewards.csproj index b1bdda3..71c56d4 100644 --- a/GethConnector/GethConnector.csproj +++ b/Tools/DiscordRewards/DiscordRewards.csproj @@ -7,8 +7,7 @@ - - + diff --git a/Tools/BiblioTech/Rewards/GiveRewardsCommand.cs b/Tools/DiscordRewards/GiveRewardsCommand.cs similarity index 67% rename from Tools/BiblioTech/Rewards/GiveRewardsCommand.cs rename to Tools/DiscordRewards/GiveRewardsCommand.cs index 494285b..03bc835 100644 --- a/Tools/BiblioTech/Rewards/GiveRewardsCommand.cs +++ b/Tools/DiscordRewards/GiveRewardsCommand.cs @@ -1,6 +1,4 @@ -using Newtonsoft.Json; - -namespace BiblioTech.Rewards +namespace DiscordRewards { public class GiveRewardsCommand { @@ -11,8 +9,5 @@ namespace BiblioTech.Rewards { public ulong RewardId { get; set; } public string[] UserAddresses { get; set; } = Array.Empty(); - - [JsonIgnore] - public UserData[] Users { get; set; } = Array.Empty(); } } diff --git a/Tools/DiscordRewards/RewardConfig.cs b/Tools/DiscordRewards/RewardConfig.cs new file mode 100644 index 0000000..dda0dfe --- /dev/null +++ b/Tools/DiscordRewards/RewardConfig.cs @@ -0,0 +1,18 @@ +namespace DiscordRewards +{ + public class RewardConfig + { + public const string UsernameTag = ""; + + public RewardConfig(ulong roleId, string message, CheckConfig checkConfig) + { + RoleId = roleId; + Message = message; + CheckConfig = checkConfig; + } + + public ulong RoleId { get; } + public string Message { get; } + public CheckConfig CheckConfig { get; } + } +} diff --git a/Tools/DiscordRewards/RewardRepo.cs b/Tools/DiscordRewards/RewardRepo.cs new file mode 100644 index 0000000..61656eb --- /dev/null +++ b/Tools/DiscordRewards/RewardRepo.cs @@ -0,0 +1,53 @@ +using Utils; + +namespace DiscordRewards +{ + public class RewardRepo + { + private static string Tag => RewardConfig.UsernameTag; + + public RewardConfig[] Rewards { get; } = new RewardConfig[] + { + // Filled any slot + new RewardConfig(123, "Filled a slot", new CheckConfig + { + Type = CheckType.FilledSlot + }), + + // Finished any slot + new RewardConfig(124, "Finished any slot", new CheckConfig + { + Type = CheckType.FinishedSlot + }), + + // Finished a sizable slot + new RewardConfig(125, "Finished sizable slot", new CheckConfig + { + Type = CheckType.FinishedSlot, + MinSlotSize = 1.GB(), + MinDuration = TimeSpan.FromHours(24.0), + }), + + // Posted any contract + new RewardConfig(126, "Posted any contract", new CheckConfig + { + Type = CheckType.PostedContract + }), + + // Started any contract + new RewardConfig(127, "Started any contract", new CheckConfig + { + Type = CheckType.StartedContract + }), + + // Started a sizable contract + new RewardConfig(125, "Started sizable contract", new CheckConfig + { + Type = CheckType.FinishedSlot, + MinNumberOfHosts = 4, + MinSlotSize = 1.GB(), + MinDuration = TimeSpan.FromHours(24.0), + }) + }; + } +} diff --git a/GethConnector/GethConnector.cs b/Tools/GethConnector/GethConnector.cs similarity index 100% rename from GethConnector/GethConnector.cs rename to Tools/GethConnector/GethConnector.cs diff --git a/Tools/GethConnector/GethConnector.csproj b/Tools/GethConnector/GethConnector.csproj new file mode 100644 index 0000000..57715aa --- /dev/null +++ b/Tools/GethConnector/GethConnector.csproj @@ -0,0 +1,15 @@ + + + + net7.0 + enable + enable + + + + + + + + + diff --git a/GethConnector/GethInput.cs b/Tools/GethConnector/GethInput.cs similarity index 100% rename from GethConnector/GethInput.cs rename to Tools/GethConnector/GethInput.cs diff --git a/TestNetRewarder/BotClient.cs b/Tools/TestNetRewarder/BotClient.cs similarity index 97% rename from TestNetRewarder/BotClient.cs rename to Tools/TestNetRewarder/BotClient.cs index 6907fae..91e6c83 100644 --- a/TestNetRewarder/BotClient.cs +++ b/Tools/TestNetRewarder/BotClient.cs @@ -1,4 +1,4 @@ -using BiblioTech.Rewards; +using DiscordRewards; using Logging; using Newtonsoft.Json; diff --git a/TestNetRewarder/ChainState.cs b/Tools/TestNetRewarder/ChainState.cs similarity index 100% rename from TestNetRewarder/ChainState.cs rename to Tools/TestNetRewarder/ChainState.cs diff --git a/TestNetRewarder/Checks.cs b/Tools/TestNetRewarder/Checks.cs similarity index 69% rename from TestNetRewarder/Checks.cs rename to Tools/TestNetRewarder/Checks.cs index 8563cf7..43102e0 100644 --- a/TestNetRewarder/Checks.cs +++ b/Tools/TestNetRewarder/Checks.cs @@ -1,4 +1,5 @@ -using GethPlugin; +using CodexContractsPlugin.Marketplace; +using GethPlugin; using NethereumWorkflow; using Utils; @@ -54,9 +55,44 @@ namespace TestNetRewarder public class PostedContractCheck : ICheck { + private readonly ulong minNumberOfHosts; + private readonly ByteSize minSlotSize; + private readonly TimeSpan minDuration; + + public PostedContractCheck(ulong minNumberOfHosts, ByteSize minSlotSize, TimeSpan minDuration) + { + this.minNumberOfHosts = minNumberOfHosts; + this.minSlotSize = minSlotSize; + this.minDuration = minDuration; + } + public EthAddress[] Check(ChainState state) { - return state.NewRequests.Select(r => r.ClientAddress).ToArray(); + return state.NewRequests + .Where(r => + MeetsNumSlotsRequirement(r) && + MeetsSizeRequirement(r) && + MeetsDurationRequirement(r)) + .Select(r => r.ClientAddress) + .ToArray(); + } + + private bool MeetsNumSlotsRequirement(Request r) + { + return r.Ask.Slots >= minNumberOfHosts; + } + + private bool MeetsSizeRequirement(Request r) + { + var slotSize = r.Ask.SlotSize.ToDecimal(); + decimal min = minSlotSize.SizeInBytes; + return slotSize >= min; + } + + private bool MeetsDurationRequirement(Request r) + { + var duration = TimeSpan.FromSeconds((double)r.Ask.Duration); + return duration >= minDuration; } } diff --git a/TestNetRewarder/Configuration.cs b/Tools/TestNetRewarder/Configuration.cs similarity index 100% rename from TestNetRewarder/Configuration.cs rename to Tools/TestNetRewarder/Configuration.cs diff --git a/TestNetRewarder/HistoricState.cs b/Tools/TestNetRewarder/HistoricState.cs similarity index 100% rename from TestNetRewarder/HistoricState.cs rename to Tools/TestNetRewarder/HistoricState.cs diff --git a/TestNetRewarder/Processor.cs b/Tools/TestNetRewarder/Processor.cs similarity index 65% rename from TestNetRewarder/Processor.cs rename to Tools/TestNetRewarder/Processor.cs index a1418e3..e56486b 100644 --- a/TestNetRewarder/Processor.cs +++ b/Tools/TestNetRewarder/Processor.cs @@ -1,4 +1,5 @@ -using BiblioTech.Rewards; +using DiscordRewards; +using GethPlugin; using Logging; using Newtonsoft.Json; using Utils; @@ -60,15 +61,38 @@ namespace TestNetRewarder private void ProcessReward(List outgoingRewards, RewardConfig reward, ChainState chainState) { - var winningAddresses = reward.Check.Check(chainState); + var winningAddresses = PerformCheck(reward, chainState); if (winningAddresses.Any()) { outgoingRewards.Add(new RewardUsersCommand { - RewardId = reward.RewardId, + RewardId = reward.RoleId, UserAddresses = winningAddresses.Select(a => a.Address).ToArray() }); } } + + private EthAddress[] PerformCheck(RewardConfig reward, ChainState chainState) + { + var check = GetCheck(reward.CheckConfig); + return check.Check(chainState); + } + + private ICheck GetCheck(CheckConfig config) + { + switch (config.Type) + { + case CheckType.FilledSlot: + return new FilledAnySlotCheck(); + case CheckType.FinishedSlot: + return new FinishedSlotCheck(config.MinSlotSize, config.MinDuration); + case CheckType.PostedContract: + return new PostedContractCheck(config.MinNumberOfHosts, config.MinSlotSize, config.MinDuration); + case CheckType.StartedContract: + return new StartedContractCheck(config.MinNumberOfHosts, config.MinSlotSize, config.MinDuration); + } + + throw new Exception("Unknown check type: " + config.Type); + } } } diff --git a/TestNetRewarder/Program.cs b/Tools/TestNetRewarder/Program.cs similarity index 99% rename from TestNetRewarder/Program.cs rename to Tools/TestNetRewarder/Program.cs index 6090f79..3d10cff 100644 --- a/TestNetRewarder/Program.cs +++ b/Tools/TestNetRewarder/Program.cs @@ -1,4 +1,5 @@ using ArgsUniform; +using GethConnector; using Logging; using Utils; diff --git a/Tools/TestNetRewarder/TestNetRewarder.csproj b/Tools/TestNetRewarder/TestNetRewarder.csproj new file mode 100644 index 0000000..2b3bd49 --- /dev/null +++ b/Tools/TestNetRewarder/TestNetRewarder.csproj @@ -0,0 +1,17 @@ + + + + Exe + net7.0 + enable + enable + + + + + + + + + + diff --git a/TestNetRewarder/TimeSegmenter.cs b/Tools/TestNetRewarder/TimeSegmenter.cs similarity index 100% rename from TestNetRewarder/TimeSegmenter.cs rename to Tools/TestNetRewarder/TimeSegmenter.cs diff --git a/cs-codex-dist-testing.sln b/cs-codex-dist-testing.sln index f5074ed..bf199b1 100644 --- a/cs-codex-dist-testing.sln +++ b/cs-codex-dist-testing.sln @@ -53,9 +53,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DeployAndRunPlugin", "Proje EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FrameworkTests", "Tests\FrameworkTests\FrameworkTests.csproj", "{25E72004-4D71-4D1E-A193-FC125D12FF96}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestNetRewarder", "TestNetRewarder\TestNetRewarder.csproj", "{27B56A82-E8CE-4B50-9746-D574BAD646A2}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DiscordRewards", "Tools\DiscordRewards\DiscordRewards.csproj", "{497352BE-0A1D-4D83-8E21-A07B4A80F2F3}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GethConnector", "GethConnector\GethConnector.csproj", "{04F2D26E-0768-4F93-9A1A-834089646B56}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GethConnector", "Tools\GethConnector\GethConnector.csproj", "{41811923-AF3A-4CC4-B508-D90EC2AFEC55}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestNetRewarder", "Tools\TestNetRewarder\TestNetRewarder.csproj", "{570C0DBE-0EF1-47B5-9A3B-E1F7895722A5}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -147,14 +149,18 @@ Global {25E72004-4D71-4D1E-A193-FC125D12FF96}.Debug|Any CPU.Build.0 = Debug|Any CPU {25E72004-4D71-4D1E-A193-FC125D12FF96}.Release|Any CPU.ActiveCfg = Release|Any CPU {25E72004-4D71-4D1E-A193-FC125D12FF96}.Release|Any CPU.Build.0 = Release|Any CPU - {27B56A82-E8CE-4B50-9746-D574BAD646A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {27B56A82-E8CE-4B50-9746-D574BAD646A2}.Debug|Any CPU.Build.0 = Debug|Any CPU - {27B56A82-E8CE-4B50-9746-D574BAD646A2}.Release|Any CPU.ActiveCfg = Release|Any CPU - {27B56A82-E8CE-4B50-9746-D574BAD646A2}.Release|Any CPU.Build.0 = Release|Any CPU - {04F2D26E-0768-4F93-9A1A-834089646B56}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {04F2D26E-0768-4F93-9A1A-834089646B56}.Debug|Any CPU.Build.0 = Debug|Any CPU - {04F2D26E-0768-4F93-9A1A-834089646B56}.Release|Any CPU.ActiveCfg = Release|Any CPU - {04F2D26E-0768-4F93-9A1A-834089646B56}.Release|Any CPU.Build.0 = Release|Any CPU + {497352BE-0A1D-4D83-8E21-A07B4A80F2F3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {497352BE-0A1D-4D83-8E21-A07B4A80F2F3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {497352BE-0A1D-4D83-8E21-A07B4A80F2F3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {497352BE-0A1D-4D83-8E21-A07B4A80F2F3}.Release|Any CPU.Build.0 = Release|Any CPU + {41811923-AF3A-4CC4-B508-D90EC2AFEC55}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {41811923-AF3A-4CC4-B508-D90EC2AFEC55}.Debug|Any CPU.Build.0 = Debug|Any CPU + {41811923-AF3A-4CC4-B508-D90EC2AFEC55}.Release|Any CPU.ActiveCfg = Release|Any CPU + {41811923-AF3A-4CC4-B508-D90EC2AFEC55}.Release|Any CPU.Build.0 = Release|Any CPU + {570C0DBE-0EF1-47B5-9A3B-E1F7895722A5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {570C0DBE-0EF1-47B5-9A3B-E1F7895722A5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {570C0DBE-0EF1-47B5-9A3B-E1F7895722A5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {570C0DBE-0EF1-47B5-9A3B-E1F7895722A5}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -181,8 +187,9 @@ Global {3E38A906-C2FC-43DC-8CA2-FC07C79CF3CA} = {7591C5B3-D86E-4AE4-8ED2-B272D17FE7E3} {1CC5AF82-8924-4C7E-BFF1-3125D86E53FB} = {8F1F1C2A-E313-4E0C-BE40-58FB0BA91124} {25E72004-4D71-4D1E-A193-FC125D12FF96} = {88C2A621-8A98-4D07-8625-7900FC8EF89E} - {27B56A82-E8CE-4B50-9746-D574BAD646A2} = {7591C5B3-D86E-4AE4-8ED2-B272D17FE7E3} - {04F2D26E-0768-4F93-9A1A-834089646B56} = {7591C5B3-D86E-4AE4-8ED2-B272D17FE7E3} + {497352BE-0A1D-4D83-8E21-A07B4A80F2F3} = {7591C5B3-D86E-4AE4-8ED2-B272D17FE7E3} + {41811923-AF3A-4CC4-B508-D90EC2AFEC55} = {7591C5B3-D86E-4AE4-8ED2-B272D17FE7E3} + {570C0DBE-0EF1-47B5-9A3B-E1F7895722A5} = {7591C5B3-D86E-4AE4-8ED2-B272D17FE7E3} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {237BF0AA-9EC4-4659-AD9A-65DEB974250C}