-
Notifications
You must be signed in to change notification settings - Fork 0
/
blocks-latest-main.js
38 lines (29 loc) · 1.05 KB
/
blocks-latest-main.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
const blocks = require('./blocks-module');
const fs = require("fs");
/** START Program. */
const args = process.argv.slice(2);
const dbPath = args[0];
const CSV_PATH = "csv_blocks/";
main = function () {
const writeStream = fs.createWriteStream(CSV_PATH + 'blocks.csv');
console.time("Blocks-latest")
/** Iterate blocks from latest. */
let tasks = 0;
let end = false;
blocks.iterateBlocksLatest((err, block, blockHash) => {
if (err || !block) {
console.log(err || `BLOCK DONE`)
console.timeEnd('Blocks-latest');
end = true;
if (tasks === 0) writeStream.end(); // close only if all lines are written
} else {
tasks++;
blocks.addCsvLineBlock(writeStream, block, ()=>{
if (--tasks === 0 && end) writeStream.end(); // close only if all lines are written and all tasks processed
});
}
});
console.log("All processing submitted, please wait results.");
}
/** Init with DB path. */
blocks.init(dbPath, main);