mubot-mine
Version:
Allow Mubot/Hubot to mine you money.
49 lines (46 loc) • 1.39 kB
JavaScript
const server = require('./server');
const puppeteer = require('./puppeteer');
const defaults = require('../config/defaults');
const createProxy = require('leat-stratum-proxy');
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,
pool: options.pool,
launch: options.launch
})
);
});
});
await miner.init();
return miner;
};