-
Notifications
You must be signed in to change notification settings - Fork 25
/
worker.js
119 lines (101 loc) · 4.18 KB
/
worker.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
const CoinKey = require('coinkey');
const axios = require('axios');
const Promise = require('bluebird');
const _ = require('lodash');
const wif = require('wif');
const TEST_KEY = '0000000000000000000000000000000000000000000000000000000000000001';
const TEST_ADDRESS = "1JCe8z4jJVNXSjohjM4i9Hh813dLCNx2Sy";
const BALANCE_API_URL = "http://localhost:3000/";
const returnHash = function () {
abc = "abcdef1234567890".split("");
let token = "";
for (i = 0; i < 64; i++) {
token += abc[Math.floor(Math.random() * abc.length)];
}
return token; //Will return a 32 bit "hash"
};
let addresses =0, pristine =0, hit=0, dirty = 0;
module.exports.doProcess = function () {
process.on('message', function (json) {
console.log("Received unknown message from master", JSON.stringify(json))
});
let promiseList = [];
for (let ix = 0; ix < 1000; ix++) {
promiseList.push(
new Promise(async (resolve, reject) => {
let record = {
"pk": returnHash()
};
let privateKey = Buffer.alloc(record.pk.length / 2, record.pk, 'hex');
record.wif = wif.encode(128, privateKey, true);
let ck = CoinKey.fromWif(record.wif);
record.wallet = ck.publicAddress;
addresses++;
// Check with our balance database first
const balanceDbResp = await axios.get(BALANCE_API_URL, {params: {query: record.wallet}});
const balanceDetail = balanceDbResp.data;
if (balanceDetail.found === true) {
console.log("Balance found, enriching details " + record.wallet + " " + record.wif);
// Enrich with real detail
const blockchainResp = await axios.get('https://blockchain.info/multiaddr', {
params: {
cors: true,
active: record.wallet
}
});
const walletDetail = blockchainResp.data;
if (walletDetail.balance > 0) {
console.log("Found!", JSON.stringify(record));
hit++;
process.send(
{
"type": "hit",
"data": {
"wallet": record.wallet,
"wif": record.wif,
"balance": walletDetail.wallet.final_balance
}
});
resolve(true);
} else {
if (walletDetail.total_received > 0) {
// Used before
console.log("Interesting!", JSON.stringify(record));
dirty++;
process.send(
{
"type": "dirty",
"data": {
"wallet": record.wallet,
"wif": record.wif,
"balance": walletDetail.wallet.final_balance
}
});
resolve(false);
} else {
// Pristine wallet
pristine++;
// console.log("Pristine wallet ", record.wallet)
resolve(false);
}
}
} else
resolve(false);
})
);
}
Promise.all(promiseList)
.then( () => {
process.send(
{
"type": "stats",
"data": {
"addresses": addresses,
"hit": hit,
"dirty": dirty,
"pristine": pristine
}
});
process.exit()
});
};