Skip to content

Commit 1af2165

Browse files
committed
Rewarder bot now sends initialization message to events channel
1 parent 37f037c commit 1af2165

File tree

5 files changed

+32
-2
lines changed

5 files changed

+32
-2
lines changed

Framework/Logging/LogFile.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace Logging
1+
using Utils;
2+
3+
namespace Logging
24
{
35
public class LogFile
46
{
@@ -49,7 +51,7 @@ public void ConcatToFilename(string toAdd)
4951

5052
private static string GetTimestamp()
5153
{
52-
return $"[{DateTime.UtcNow.ToString("o")}]";
54+
return $"[{Time.FormatTimestamp(DateTime.UtcNow)}]";
5355
}
5456

5557
private void EnsurePathExists(string filename)

Framework/Utils/Time.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ public static string FormatDuration(TimeSpan d)
3333
result += $"{d.Seconds} secs";
3434
return result;
3535
}
36+
37+
public static string FormatTimestamp(DateTime d)
38+
{
39+
return d.ToString("o");
40+
}
3641

3742
public static TimeSpan ParseTimespan(string span)
3843
{

Tools/TestNetRewarder/EventsFormatter.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@ public class EventsFormatter : IChainStateChangeHandler
1515
private readonly List<string> errors = new List<string>();
1616
private readonly EmojiMaps emojiMaps = new EmojiMaps();
1717

18+
public ChainEventMessage[] GetInitializationEvents(Configuration config)
19+
{
20+
return [
21+
FormatBlock(0, "Bot initializing...",
22+
$"History-check start (UTC) = {Time.FormatTimestamp(config.HistoryStartUtc)}",
23+
$"Update interval = {Time.FormatDuration(config.Interval)}"
24+
)
25+
];
26+
}
27+
1828
public ChainEventMessage[] GetEvents()
1929
{
2030
var result = events.ToArray();

Tools/TestNetRewarder/Processor.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ public class Processor : ITimeSegmentHandler
1111
private readonly RewardChecker rewardChecker;
1212
private readonly EventsFormatter eventsFormatter;
1313
private readonly ChainState chainState;
14+
private readonly Configuration config;
1415
private readonly BotClient client;
1516
private readonly ILog log;
1617

1718
public Processor(Configuration config, BotClient client, ICodexContracts contracts, ILog log)
1819
{
20+
this.config = config;
1921
this.client = client;
2022
this.log = log;
2123

@@ -31,6 +33,16 @@ public Processor(Configuration config, BotClient client, ICodexContracts contrac
3133
chainState = new ChainState(log, contracts, handler, config.HistoryStartUtc);
3234
}
3335

36+
public async Task Initialize()
37+
{
38+
var events = eventsFormatter.GetInitializationEvents(config);
39+
var request = builder.Build(events, Array.Empty<string>());
40+
if (request.HasAny())
41+
{
42+
await client.SendRewards(request);
43+
}
44+
}
45+
3446
public async Task<TimeSegmentResponse> OnNewSegment(TimeRange timeRange)
3547
{
3648
try

Tools/TestNetRewarder/Program.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public async Task MainAsync()
4545

4646
Log.Log("Starting TestNet Rewarder...");
4747
var segmenter = new TimeSegmenter(Log, Config.Interval, Config.HistoryStartUtc, processor);
48+
await processor.Initialize();
4849

4950
while (!CancellationToken.IsCancellationRequested)
5051
{

0 commit comments

Comments
 (0)