-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
76 lines (64 loc) · 1.89 KB
/
Copy pathindex.js
File metadata and controls
76 lines (64 loc) · 1.89 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
const net = require('net')
const fs = require('fs')
const Web3 = require('web3')
const snapshotBlock = process.argv[2] || "5500000" // ETC block
// const ipcPath = process.env["HOME"] + "/.local/share/io.parity.ethereum/jsonrpc.ipc";
const ipcPath = "/parity/jsonrpc.ipc"
let web3 = new Web3();
web3.setProvider(new web3.providers.IpcProvider(ipcPath, net));
let snapshot = []
let accounts_count = 0
let accounts_checked = 0
const getAccounts = (accountOffset, callback) => {
return web3.parity.listAccounts(
300, accountOffset, "latest", function (err, result) {
if (err) {
console.log(err)
process.exit(1)
}
callback(result)
}
)
}
const getBalance = (account) => {
web3.eth.getBalance(account, web3.toHex(snapshotBlock), (err, result) => {
if (err) {
console.log(err)
process.exit(1)
}
let balance = result.toString(10);
if (balance === "0")
return
accounts_count++
snapshot.push({"address": account, "balance": balance})
})
}
const writeFile = () => {
let stream = fs.createWriteStream("snapshot.txt", {flags:'a'})
for (var i = 0, len = snapshot.length; i < len; i++) {
let account = snapshot.shift()
stream.write(`${i},${account.address},${account.balance}\n`)
}
console.log(`Account #${accounts_count} ${new Date().toISOString()}`)
stream.end()
}
const getBalances = (accounts) => {
if (accounts.length === 0) {
writeFile()
process.exit()
}
for (var i = 0, len = accounts.length; i < len; i++) {
accounts_checked++
let account = accounts[i]
getBalance(account)
if (i === accounts.length - 1) {
console.log(`Last address: ${account} - Accounts checked ${accounts_checked} - Accounts count ${accounts_count}`)
writeFile()
makeSnapshot(account)
}
}
}
const makeSnapshot = (accountOffset) => {
getAccounts(accountOffset, getBalances)
}
makeSnapshot(null)