|
@@ -19,7 +19,7 @@ import { AccountId, Header } from "@polkadot/types/interfaces";
|
|
// functions
|
|
// functions
|
|
import * as announce from "./lib/announcements";
|
|
import * as announce from "./lib/announcements";
|
|
import * as get from "./lib/getters";
|
|
import * as get from "./lib/getters";
|
|
-import { parseArgs, printStatus, passedTime, exit } from "./lib/util";
|
|
|
|
|
|
+import { parseArgs, printStatus, passedTime } from "./lib/util";
|
|
import moment from "moment";
|
|
import moment from "moment";
|
|
|
|
|
|
const opts: Options = parseArgs(process.argv.slice(2));
|
|
const opts: Options = parseArgs(process.argv.slice(2));
|
|
@@ -53,8 +53,6 @@ client.on("message", async (msg) => {
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
-let lastHeartbeat: number = moment().valueOf();
|
|
|
|
-
|
|
|
|
// send to telegram and discord
|
|
// send to telegram and discord
|
|
const sendMessage = (msg: { tg: string; discord: string }, channel: any) => {
|
|
const sendMessage = (msg: { tg: string; discord: string }, channel: any) => {
|
|
if (msg.tg === "") return;
|
|
if (msg.tg === "") return;
|
|
@@ -93,10 +91,13 @@ const main = async () => {
|
|
let council: Council = { round: 0, last: "" };
|
|
let council: Council = { round: 0, last: "" };
|
|
let blocks: Block[] = [];
|
|
let blocks: Block[] = [];
|
|
let lastEra = 0;
|
|
let lastEra = 0;
|
|
|
|
+ let timestamp = await get.timestamp(api);
|
|
|
|
+ let duration = 0;
|
|
|
|
+ let lastHeartbeat = timestamp;
|
|
let lastBlock: Block = {
|
|
let lastBlock: Block = {
|
|
id: 0,
|
|
id: 0,
|
|
- duration: 6000,
|
|
|
|
- timestamp: lastHeartbeat,
|
|
|
|
|
|
+ duration: 0,
|
|
|
|
+ timestamp: 0,
|
|
stake: 0,
|
|
stake: 0,
|
|
noms: 0,
|
|
noms: 0,
|
|
vals: 0,
|
|
vals: 0,
|
|
@@ -116,8 +117,6 @@ const main = async () => {
|
|
let proposals: Proposals = { last: 0, current: 0, active: [], executing: [] };
|
|
let proposals: Proposals = { last: 0, current: 0, active: [], executing: [] };
|
|
let lastProposalUpdate = 0;
|
|
let lastProposalUpdate = 0;
|
|
|
|
|
|
- if (opts.channel) channels[0] = await get.currentChannelId(api);
|
|
|
|
-
|
|
|
|
if (opts.forum) {
|
|
if (opts.forum) {
|
|
posts[0] = await get.currentPostId(api);
|
|
posts[0] = await get.currentPostId(api);
|
|
threads[0] = await get.currentThreadId(api);
|
|
threads[0] = await get.currentThreadId(api);
|
|
@@ -137,8 +136,8 @@ const main = async () => {
|
|
const id = header.number.toNumber();
|
|
const id = header.number.toNumber();
|
|
|
|
|
|
if (lastBlock.id === id) return;
|
|
if (lastBlock.id === id) return;
|
|
- const timestamp = (await api.query.timestamp.now()).toNumber();
|
|
|
|
- const duration = timestamp - lastBlock.timestamp;
|
|
|
|
|
|
+ timestamp = await get.timestamp(api);
|
|
|
|
+ duration = lastBlock.timestamp ? timestamp - lastBlock.timestamp : 0;
|
|
|
|
|
|
// update validators and nominators every era
|
|
// update validators and nominators every era
|
|
const era = Number(await api.query.staking.currentEra());
|
|
const era = Number(await api.query.staking.currentEra());
|
|
@@ -174,7 +173,7 @@ const main = async () => {
|
|
reward,
|
|
reward,
|
|
issued,
|
|
issued,
|
|
};
|
|
};
|
|
- blocks = blocks.concat(block);
|
|
|
|
|
|
+ if (duration) blocks = blocks.concat(block);
|
|
|
|
|
|
// heartbeat
|
|
// heartbeat
|
|
if (timestamp > lastHeartbeat + heartbeat) {
|
|
if (timestamp > lastHeartbeat + heartbeat) {
|
|
@@ -201,18 +200,6 @@ const main = async () => {
|
|
discordChannels.council
|
|
discordChannels.council
|
|
);
|
|
);
|
|
|
|
|
|
- if (opts.channel) {
|
|
|
|
- channels[1] = await get.currentChannelId(api);
|
|
|
|
- if (channels[1] > channels[0])
|
|
|
|
- announce.channels(
|
|
|
|
- api,
|
|
|
|
- channels,
|
|
|
|
- sendMessage,
|
|
|
|
- discordChannels.channels
|
|
|
|
- );
|
|
|
|
- channels[0] = channels[1];
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
if (opts.proposals) {
|
|
if (opts.proposals) {
|
|
proposals.current = await get.proposalCount(api);
|
|
proposals.current = await get.proposalCount(api);
|
|
|
|
|
|
@@ -245,5 +232,5 @@ const main = async () => {
|
|
};
|
|
};
|
|
main().catch((error) => {
|
|
main().catch((error) => {
|
|
console.log(error);
|
|
console.log(error);
|
|
- exit(log);
|
|
|
|
|
|
+ process.exit();
|
|
});
|
|
});
|