-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkForBalance.js
64 lines (60 loc) · 1.54 KB
/
checkForBalance.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
60
61
62
63
64
import Web3 from "web3";
import fs from "fs";
import shell from "shelljs";
const providerRPC = "http://localhost:8545/";
const web3 = new Web3(providerRPC);
function read(fileIndex) {
return JSON.parse(
"[".concat(
fs
.readFileSync("./data/addresses/" + fileIndex + ".txt", "utf8")
.concat("]")
)
);
}
function printProgress(i, files, j, total) {
process.stdout.clearLine();
process.stdout.cursorTo(0);
process.stdout.write(
"Working on file " +
i +
"/" +
files +
", Progress: " +
((j / total) * 100).toFixed(2) +
"%"
);
}
async function checkAdresses(start, fileIndex) {
shell.echo("Starting to fetch from " + start + " to " + fileIndex);
for (let i = start; i <= fileIndex; i++) {
let data = read(i);
if (data.length > 0) {
shell.echo("Data fetched " + i);
} else {
shell.echo("Error with " + i);
}
for (let j = 0; j < data.length; j++) {
// printProgress(i, fileIndex, j, data.length);
const address = data[j].address;
const balance = await web3.eth.getBalance(address);
if (balance > 0)
fs.appendFileSync(
"./data/result.txt",
JSON.stringify(data[j]),
null,
2
);
}
}
shell.echo("Finished " + start + " to " + fileIndex);
}
try {
const indexes = process.argv.slice(2);
const start = indexes[0];
const fileIndex = indexes[1];
if (!start || !fileIndex) throw "Invalid input!";
await checkAdresses(start, fileIndex);
} catch (e) {
shell.echo(e.toString());
}