1 | "use strict";
|
2 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
3 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
4 | };
|
5 | Object.defineProperty(exports, "__esModule", { value: true });
|
6 | const dayjs_1 = __importDefault(require("dayjs"));
|
7 | const managers_1 = require("../managers");
|
8 | class 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 | }
|
41 | exports.Slots = Slots;
|
42 |
|
\ | No newline at end of file |