npm

@multiversx/sdk-epoch-watcher
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published
MultiversX

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;
}

Package Sidebar

Install

npm i @multiversx/sdk-epoch-watcher

Weekly Downloads

40

Version

1.0.2

License

GPL-3.0-or-later

Unpacked Size

6.19 kB

Total Files

4

Last publish

Collaborators

  • dragosrebegea
  • arhtudormorar
  • radumojic
  • tanghel
  • cipriand
  • ccorcoveanu
  • valentinlup
  • andreibancioiu
  • titel
  • lucian.mincu