-
Notifications
You must be signed in to change notification settings - Fork 395
/
Copy pathindex.js
50 lines (47 loc) · 1.39 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const server = require('./server');
const puppeteer = require('./puppeteer');
const defaults = require('../config/defaults');
const createProxy = require('coin-hive-stratum');
module.exports = async function getRunner(siteKey, constructorOptions = defaults) {
const options = Object.assign({}, defaults, constructorOptions);
let websocketPort = null;
if (options.pool) {
const proxy = createProxy({
log: false,
host: options.pool.host,
port: options.pool.port,
pass: options.pool.pass || 'x'
});
websocketPort = options.port + 1;
proxy.listen(websocketPort);
}
const miner = await new Promise((resolve, reject) => {
const minerServer = server({
minerUrl: options.minerUrl,
websocketPort: websocketPort
}).listen(options.port, options.host, async err => {
if (err) {
return reject(err);
}
return resolve(
puppeteer({
siteKey,
interval: options.interval,
port: options.port,
host: options.host,
throttle: options.throttle,
threads: options.threads,
server: minerServer,
proxy: options.proxy,
username: options.username,
url: options.puppeteerUrl,
devFee: options.devFee,
pool: options.pool,
launch: options.launch
})
);
});
});
await miner.init();
return miner;
};