forked from jazarja/bithack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
35 lines (29 loc) · 1.06 KB
/
index.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
const cluster = require('cluster');
const numCPUs = require('os').cpus().length;
const Database = require('better-sqlite3');
const db = new Database('bithack.db', {});
if (cluster.isMaster) {
for (let i = 0; i < numCPUs; i++) {
cluster.fork();
}
Object.keys(cluster.workers).forEach(function (id) {
console.log("Worker running with ID : " + cluster.workers[id].process.pid);
cluster.workers[id].on('message', function(json){
if (json.type==="hit")
{
let stmt = db.prepare("INSERT INTO result VALUES (@wallet, @wif, @balance)");
stmt.run(json.data);
} else
{
console.log("Received unknown message from worker", JSON.stringify(json));
}
});
// cluster.workers[id].send({type:"message", "message" : "Hello"});
});
cluster.on('exit', function (worker, code, signal) {
console.log('Worker ' + worker.process.pid + ' has died');
});
} else {
const worker = require("./worker");
worker.doProcess();
}