Epoch Watcher
Description
Package for monitoring when an epoch changes.
The epoch watcher service must be called inside a scheduler task how often it's needed.
An external storage is needed for storing Elrond Stats data of current epoch. (e.g.: Redis)
Elrond Stats must be loaded from an instance of Elrond API, route: GET /stats
.
Usage
await new EpochWatcher({
getEpochWatcherInfo: () => redisClient.get(key),
setEpochWatcherInfo: (epochWatcherInfo) => redisClient.set(key, info, TTL), /* 1 day */,
loadElrondStats: () => elrondApi.getStats(),
callback: (info) => { console.log(`Epoch has changed. New epoch: ${info.newEpoch}.`); },
}).execute();
Models:
export class EpochChangedInfo {
newEpoch: number;
}
export class EpochWatcherInfo {
statsLoadTime: number;
timeLeftUntilEpochChange: number;
epoch: number;
}