eazyminer
Version:
Easy to use npm NodeJS Monero Miner with C++, uses XMRIG for highspeed hashing.
84 lines (83 loc) • 2.79 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.XMRIGMiner = void 0;
const child_process_1 = require("child_process");
const os_1 = require("os");
const path_1 = require("path");
const fs_1 = require("fs");
const PLATFORM = (0, os_1.platform)().toLowerCase();
const XMRIG_PATH = (0, path_1.join)(__dirname, '../../../assets/miners/xmrig');
const LINUX_PATH = (0, path_1.join)(XMRIG_PATH, 'xmrig');
const WINDOWS_PATH = (0, path_1.join)(XMRIG_PATH, 'xmrig.exe');
const configPath = (0, path_1.join)(XMRIG_PATH, 'config.json');
const configBasePath = (0, path_1.join)(__dirname, '../../../config.base.json');
class XMRIGMiner {
app;
name = 'xmrig';
_initialized = false;
_miner = null;
_filePath;
_running = false;
_worker;
constructor(app) {
this.app = app;
this._init();
}
async _init() {
if (PLATFORM === 'linux') {
this._loadLinux();
}
else if (PLATFORM === 'win32') {
this._loadWindows();
}
else {
throw new Error('Unsopperted platform');
}
this._initialized = true;
}
start() {
if (this._running) {
console.info('XMRIG already running');
return;
}
this._running = true;
this._exec();
}
stop() {
if (this._worker) {
this._worker.kill();
this._worker = null;
}
}
getStatus() {
}
_loadLinux() {
// add execution rights
(0, fs_1.chmodSync)(LINUX_PATH, 754);
this._filePath = LINUX_PATH;
}
_loadWindows() {
this._filePath = WINDOWS_PATH;
}
_exec() {
this._updateConfig();
// start script
this._worker = (0, child_process_1.spawn)(this._filePath, [], { cwd: XMRIG_PATH });
// passthrough output
this._worker.stdout.on('data', data => this.app.logger.info(data));
this._worker.stderr.on('data', data => this.app.logger.error(data));
}
_updateConfig() {
const configBase = JSON.parse((0, fs_1.readFileSync)(configBasePath, 'utf-8'));
// merge given pools config with base configs
const pools = this.app.config.pools?.map(poolConfig => Object.assign({}, configBase.pools[0], poolConfig));
this.app.logger.info('XMRIG pools configuration');
this.app.logger.info(JSON.stringify(pools, null, 2));
configBase.pools = pools;
Object.assign(configBase.opencl, this.app.config.opencl);
Object.assign(configBase.cuda, this.app.config['cuda']);
console.log(2323, configBase, XMRIG_PATH);
(0, fs_1.writeFileSync)(configPath, JSON.stringify(configBase, null, 2));
}
}
exports.XMRIGMiner = XMRIGMiner;