UNPKG

1.49 kBJavaScriptView Raw
1"use strict";
2var __importDefault = (this && this.__importDefault) || function (mod) {
3 return (mod && mod.__esModule) ? mod : { "default": mod };
4};
5Object.defineProperty(exports, "__esModule", { value: true });
6const dayjs_1 = __importDefault(require("dayjs"));
7const managers_1 = require("../managers");
8class Slots {
9 static getTime(time) {
10 if (time === undefined) {
11 time = dayjs_1.default().valueOf();
12 }
13 const start = dayjs_1.default(managers_1.configManager.getMilestone(1).epoch).valueOf();
14 return Math.floor((time - start) / 1000);
15 }
16 static getTimeInMsUntilNextSlot() {
17 const nextSlotTime = this.getSlotTime(this.getNextSlot());
18 const now = this.getTime();
19 return (nextSlotTime - now) * 1000;
20 }
21 static getSlotNumber(epoch) {
22 if (epoch === undefined) {
23 epoch = this.getTime();
24 }
25 return Math.floor(epoch / managers_1.configManager.getMilestone(1).blocktime);
26 }
27 static getSlotTime(slot) {
28 return slot * managers_1.configManager.getMilestone(1).blocktime;
29 }
30 static getNextSlot() {
31 return this.getSlotNumber() + 1;
32 }
33 static isForgingAllowed(epoch) {
34 if (epoch === undefined) {
35 epoch = this.getTime();
36 }
37 const blockTime = managers_1.configManager.getMilestone(1).blocktime;
38 return epoch % blockTime < blockTime / 2;
39 }
40}
41exports.Slots = Slots;
42//# sourceMappingURL=slots.js.map
\No newline at end of file