-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathminers.js
41 lines (33 loc) · 1.01 KB
/
miners.js
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
import { ethers } from "ethers";
// const sbchRpcUrl = 'https://rpc.smartbch.org';
const sbchRpcUrl = 'http://52.77.220.215:8545'; // archive node
const provider = new ethers.JsonRpcProvider(sbchRpcUrl);
async function main() {
const n = await provider.getBlockNumber();
const startH = Number(process.argv[2] || n);
const queueLen = 100;
const getBlock = asyncGetBlockFn(startH, n, queueLen);
for (let h = startH; h <= n; h++) {
const block = await getBlock(h);
console.log(`h: ${h}, miner: ${block.miner}, ts: ${block.timestamp}`);
}
}
function asyncGetBlockFn(firstH, lastH, queueLen) {
const queue = [];
return function(h) {
if (h == firstH) { // init queue
for (let i = 0; i <= queueLen; i++) {
queue.push(provider.getBlock(h + i));
}
} else if (h + queueLen <= lastH) {
queue.push(provider.getBlock(h + queueLen));
}
return queue.shift();
}
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});