@multiversx/sdk-epoch-watcher
v1.0.2
Published
Real-time epoch-watcher
Downloads
286
Readme
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 MultiversX Stats data of current epoch. (e.g.: Redis)
MultiversX Stats must be loaded from an instance of MultiversX API, route: GET /stats
.
Usage
await new EpochWatcher({
getEpochWatcherInfo: () => redisClient.get(key),
setEpochWatcherInfo: (epochWatcherInfo) => redisClient.set(key, info, TTL), /* 1 day */,
loadMultiversXStats: () => multiversxApi.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;
}