forked from jazarja/bithack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworker.js
More file actions
79 lines (68 loc) · 2.72 KB
/
worker.js
File metadata and controls
79 lines (68 loc) · 2.72 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
77
78
79
const CoinKey = require('coinkey');
const rp = require('request-promise');
const Promise = require('bluebird');
const HashTable = require('hashtable');
const _ = require('lodash');
const wif = require('wif');
const TEST_KEY = '0000000000000000000000000000000000000000000000000000000000000001';
const TEST_ADDRESS = "1JCe8z4jJVNXSjohjM4i9Hh813dLCNx2Sy";
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"
};
module.exports.doProcess = function () {
process.on('message', function (json) {
console.log("Received unknown message from master", JSON.stringify(json))
});
let hashtable = new HashTable();
let promiseList = [];
for (let ix = 0; ix < 100; ix++) {
promiseList.push(
new Promise(function (resolve, reject) {
let record = {
"pk": returnHash()
};
let privateKey = new Buffer(record.pk, 'hex');
record.wif = wif.encode(128, privateKey, true);
let ck = CoinKey.fromWif(record.wif);
record.wallet = ck.publicAddress;
resolve(record);
})
.then(function (record) {
return rp('https://blockchain.info/q/addressbalance/' + record.wallet)
.then(function (htmlString) {
hashtable.put(record.wallet, +(htmlString));
if (+(htmlString) > 0) {
console.log("Found!", JSON.stringify(record));
process.send(
{
"type": "hit",
"data": {
"wallet": record.wallet,
"wif": record.wif,
"balance": +(htmlString)
}
});
} else {
// console.log("No balance on ", record.wallet)
}
})
.catch(function (err) {
console.error(err);
});
})
);
}
Promise.all(promiseList)
.then(function () {
_.each(hashtable.keys(), function (key) {
console.log(key, hashtable.get(key))
});
console.log("DONE");
process.exit()
});
};