Improve event logging
This commit is contained in:
parent
ae25b58610
commit
24cf6c70b8
|
@ -1,5 +1,6 @@
|
||||||
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
|
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
|
||||||
using GethPlugin;
|
using GethPlugin;
|
||||||
|
using NethereumWorkflow.BlockUtils;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace CodexContractsPlugin.Marketplace
|
namespace CodexContractsPlugin.Marketplace
|
||||||
|
@ -7,7 +8,7 @@ namespace CodexContractsPlugin.Marketplace
|
||||||
public partial class Request : RequestBase
|
public partial class Request : RequestBase
|
||||||
{
|
{
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public ulong BlockNumber { get; set; }
|
public BlockTimeEntry Block { get; set; }
|
||||||
public byte[] RequestId { get; set; }
|
public byte[] RequestId { get; set; }
|
||||||
|
|
||||||
public EthAddress ClientAddress { get { return new EthAddress(Client); } }
|
public EthAddress ClientAddress { get { return new EthAddress(Client); } }
|
||||||
|
@ -16,26 +17,26 @@ namespace CodexContractsPlugin.Marketplace
|
||||||
public partial class RequestFulfilledEventDTO
|
public partial class RequestFulfilledEventDTO
|
||||||
{
|
{
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public ulong BlockNumber { get; set; }
|
public BlockTimeEntry Block { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public partial class RequestCancelledEventDTO
|
public partial class RequestCancelledEventDTO
|
||||||
{
|
{
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public ulong BlockNumber { get; set; }
|
public BlockTimeEntry Block { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public partial class SlotFilledEventDTO
|
public partial class SlotFilledEventDTO
|
||||||
{
|
{
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public ulong BlockNumber { get; set; }
|
public BlockTimeEntry Block { get; set; }
|
||||||
public EthAddress Host { get; set; }
|
public EthAddress Host { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public partial class SlotFreedEventDTO
|
public partial class SlotFreedEventDTO
|
||||||
{
|
{
|
||||||
[JsonIgnore]
|
[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.
|
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
|
||||||
|
|
|
@ -23,7 +23,10 @@ namespace BiblioTech.Rewards
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Program.Averages = cmd.Averages;
|
if (cmd.Averages != null && cmd.Averages.Any())
|
||||||
|
{
|
||||||
|
Program.Averages = cmd.Averages;
|
||||||
|
}
|
||||||
await Program.RoleDriver.GiveRewards(cmd);
|
await Program.RoleDriver.GiveRewards(cmd);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|
|
@ -24,6 +24,16 @@ namespace BiblioTech.Rewards
|
||||||
{
|
{
|
||||||
Program.Log.Log($"Processing rewards command: '{JsonConvert.SerializeObject(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();
|
var guild = GetGuild();
|
||||||
// We load all role and user information first,
|
// We load all role and user information first,
|
||||||
// so we don't ask the server for the same info multiple times.
|
// so we don't ask the server for the same info multiple times.
|
||||||
|
@ -33,7 +43,6 @@ namespace BiblioTech.Rewards
|
||||||
rewardsChannel);
|
rewardsChannel);
|
||||||
|
|
||||||
await context.ProcessGiveRewardsCommand(LookUpUsers(rewards));
|
await context.ProcessGiveRewardsCommand(LookUpUsers(rewards));
|
||||||
await ProcessChainEvents(rewards.EventsOverview);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private SocketTextChannel? GetChannel(string name)
|
private SocketTextChannel? GetChannel(string name)
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
using CodexContractsPlugin.Marketplace;
|
using DiscordRewards;
|
||||||
using DiscordRewards;
|
|
||||||
using Logging;
|
using Logging;
|
||||||
using Newtonsoft.Json;
|
|
||||||
using System.Net.Http.Json;
|
using System.Net.Http.Json;
|
||||||
|
|
||||||
namespace TestNetRewarder
|
namespace TestNetRewarder
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
using CodexContractsPlugin;
|
using CodexContractsPlugin;
|
||||||
using CodexContractsPlugin.Marketplace;
|
using CodexContractsPlugin.Marketplace;
|
||||||
|
using NethereumWorkflow.BlockUtils;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Utils;
|
using Utils;
|
||||||
|
|
||||||
|
@ -8,6 +9,29 @@ namespace TestNetRewarder
|
||||||
public class ChainState
|
public class ChainState
|
||||||
{
|
{
|
||||||
private readonly HistoricState historicState;
|
private readonly HistoricState historicState;
|
||||||
|
private readonly string[] colorIcons = new[]
|
||||||
|
{
|
||||||
|
"🔴",
|
||||||
|
"🟠",
|
||||||
|
"🟡",
|
||||||
|
"🟢",
|
||||||
|
"🔵",
|
||||||
|
"🟣",
|
||||||
|
"🟤",
|
||||||
|
"⚫",
|
||||||
|
"⚪",
|
||||||
|
"🟥",
|
||||||
|
"🟧",
|
||||||
|
"🟨",
|
||||||
|
"🟩",
|
||||||
|
"🟦",
|
||||||
|
"🟪",
|
||||||
|
"🟫",
|
||||||
|
"⬛",
|
||||||
|
"⬜",
|
||||||
|
"🔶",
|
||||||
|
"🔷"
|
||||||
|
};
|
||||||
|
|
||||||
public ChainState(HistoricState historicState, ICodexContracts contracts, BlockInterval blockRange)
|
public ChainState(HistoricState historicState, ICodexContracts contracts, BlockInterval blockRange)
|
||||||
{
|
{
|
||||||
|
@ -52,46 +76,59 @@ namespace TestNetRewarder
|
||||||
|
|
||||||
private StringBlockNumberPair ToPair(Request r)
|
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)
|
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)
|
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)
|
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)
|
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)
|
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 class StringBlockNumberPair
|
||||||
{
|
{
|
||||||
public StringBlockNumberPair(string name, string str, ulong number)
|
public StringBlockNumberPair(string name, string str, BlockTimeEntry block, byte[] requestId)
|
||||||
{
|
{
|
||||||
Name = name;
|
Name = name;
|
||||||
Str = str;
|
Str = str;
|
||||||
Number = number;
|
Block = block;
|
||||||
|
RequestId = requestId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Name { get; }
|
public string Name { get; }
|
||||||
public string Str { get; }
|
public string Str { get; }
|
||||||
public ulong Number { get; }
|
public BlockTimeEntry Block { get; }
|
||||||
|
public byte[] RequestId { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class StringUtcComparer : IComparer<StringBlockNumberPair>
|
public class StringUtcComparer : IComparer<StringBlockNumberPair>
|
||||||
|
@ -101,7 +138,7 @@ namespace TestNetRewarder
|
||||||
if (x == null && y == null) return 0;
|
if (x == null && y == null) return 0;
|
||||||
if (x == null) return 1;
|
if (x == null) return 1;
|
||||||
if (y == null) return -1;
|
if (y == null) return -1;
|
||||||
return x.Number.CompareTo(y.Number);
|
return x.Block.BlockNumber.CompareTo(y.Block.BlockNumber);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue