-
Notifications
You must be signed in to change notification settings - Fork 0
/
balance.js
54 lines (47 loc) · 1.35 KB
/
balance.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
const readline = require("readline");
const fs = require("fs");
const util = require("util");
const axios = require("axios");
const appendFileAsync = util.promisify(fs.appendFile);
const filePath = "public_key.txt"; // Replace with the path to your file
const filePath1 = "balance.json";
async function getBalance(publicKeys) {
try {
const response = await axios.get(
`https://blockchain.info/balance?active=${publicKeys}`
);
return response.data;
} catch (error) {
console.error(error);
throw error;
}
}
const rl = readline.createInterface({
input: fs.createReadStream(filePath),
output: process.stdout,
terminal: false,
});
let i = 0;
let publicKeys = [];
rl.on("line", async (line) => {
// This callback function is called for each line in the file
const data = JSON.parse(line);
i++;
publicKeys.push(data.publicKey); // Use data.publicKey instead of data['publicKey']
console.log(i);
if (i === 1000) {
const keys = publicKeys.join("|");
i = 0;
publicKeys = [];
try {
const walletInfo = await getBalance(keys);
await appendFileAsync(filePath1, JSON.stringify(walletInfo) + "\n");
} catch (error) {
console.error(error);
}
}
});
rl.on("close", () => {
// This callback is called when the reading is finished or the reader is closed
console.log("Finished reading lines.");
});