-
Notifications
You must be signed in to change notification settings - Fork 36
/
fetchRemarks.ts
46 lines (41 loc) · 1.1 KB
/
fetchRemarks.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { BlockCalls } from "./types";
import { deeplog, getBlockCallsFromSignedBlock } from "../tools/utils";
import { ApiPromise } from "@polkadot/api";
export default async (
api: ApiPromise,
from: number,
to: number,
prefixes: string[],
ss58Format = 2
): Promise<BlockCalls[]> => {
const bcs: BlockCalls[] = [];
for (let i = from; i <= to; i++) {
if (i % 1000 === 0) {
const event = new Date();
console.log(`Block ${i} at time ${event.toTimeString()}`);
if (i % 5000 === 0) {
console.log(`Currently at ${bcs.length} remarks.`);
}
}
const blockHash = await api.rpc.chain.getBlockHash(i);
const block = await api.rpc.chain.getBlock(blockHash);
if (block.block === undefined) {
console.error("block.block is undefined for block " + i);
deeplog(block);
continue;
}
const blockCalls = await getBlockCallsFromSignedBlock(
block,
prefixes,
api,
ss58Format
);
if (blockCalls.length) {
bcs.push({
block: i,
calls: blockCalls,
} as BlockCalls);
}
}
return bcs;
};