-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
59 lines (55 loc) · 1.93 KB
/
index.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import path from "path";
import fs from "fs";
import { setTimeout } from "timers/promises";
let blockHeight = 186905;
// Nakamoto went live on block 171832
const getBlockInfo = async (blockHeight) => {
try {
const response = await fetch(
`https://api.hiro.so/extended/v2/blocks/${blockHeight}`,
{
headers: {
"Content-Type": "application/json",
"X-API-Key": process.env.HIRO_API_KEY,
},
method: "GET",
}
);
if (response.status !== 200) {
console.info("Bad response...", response.status, "waiting to retry");
await setTimeout(30_000);
return getBlockInfo(blockHeight);
}
return response;
} catch (error) {
console.error("error", error, "retrying in 1 second");
await setTimeout(1000);
return getBlockInfo(blockHeight);
}
};
(async () => {
fs.writeFileSync(
path.resolve("results.csv"),
"block,tenure_height,txs,read_count,read_length,runtime,write_count,write_length\n"
);
while (blockHeight > 1000) {
const response = await getBlockInfo(blockHeight);
const responseBody = await response.json();
const txCount = responseBody.tx_count;
const tenureHeight = responseBody.tenure_height;
const readCount = responseBody.execution_cost_read_count;
const readLength = responseBody.execution_cost_read_length;
const runtime = responseBody.execution_cost_runtime;
const writeCount = responseBody.execution_cost_write_count;
const writeLength = responseBody.execution_cost_write_length;
process.stdout.write(
`Block ${blockHeight}, Tenure ${tenureHeight}: ${txCount}, ${readCount}, ${readLength}, ${runtime}, ${writeCount}, ${writeLength}\n`
);
fs.appendFileSync(
path.resolve("results.csv"),
`${blockHeight},${tenureHeight},${txCount},${readCount},${readLength},${runtime},${writeCount},${writeLength}\n`
);
blockHeight = blockHeight - 1;
await setTimeout(100);
}
})();