eazyminer
Version:
Easy to use npm NodeJS Monero Miner with C++, uses XMRIG for highspeed hashing.
150 lines (149 loc) • 4.6 kB
JavaScript
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Controller = void 0;
const osu = __importStar(require("node-os-utils"));
const cli_table_1 = __importDefault(require("cli-table"));
const xmrig_miner_1 = require("./utils/xmrig.miner");
const os_1 = require("os");
const cpu = osu.cpu;
const mem = osu.mem;
class Controller {
app;
_active = false;
_running = false;
_settings = {
maxCPU: 60,
maxGPU: 60,
maxRAM: 60,
tickInterval: 2000
};
#miners = [];
#tickInterval;
#system = {
cpu: [],
cpuLoad: 0,
freeMem: 0,
ram: {}
};
_status = {
coins: [
{
id: 'stratus',
total: 0
}
]
};
get status() {
return {
coins: [
{
id: 'stratus',
total: 0
}
],
active: this._active
};
}
constructor(app) {
this.app = app;
this.app = app;
this.init();
}
init() {
}
start() {
if (this._running) {
this.app.logger.info('Start: miner already running');
return;
}
this.app.logger.info('Starting miner');
this.#tickInterval = setInterval(() => this.tick(), this._settings.tickInterval);
this._running = true;
}
stop() {
this.app.logger.info('Stopping miner');
clearInterval(this.#tickInterval);
this.#tickInterval = null;
this._running = false;
this.#miners.forEach(miner => miner.stop());
}
reset() {
}
async tick() {
this.#system.cpuLoad = await cpu.usage();
this.#system.ram = await mem.info();
this.#system.cpu = (0, os_1.cpus)();
this.#system.freeMem = (0, os_1.freemem)();
// process.stdout.write('\x1b[H\x1b[2J')
// instantiate
var table = new cli_table_1.default({
head: ['TH 1 label', 'TH 2 label'],
colWidths: [100, 200]
});
// table is an Array, so you can `push`, `unshift`, `splice` and friends
table.push(['First value', 'Second value'], ['First value', 'Second value']);
if (!this._active) {
this._active = true;
this.#miners.forEach(miner => miner.start());
}
// if (this._settings.maxCPU > this._system.cpuLoad) {
// this._active = true;
// } else {
// this._active = false;
// }
// if (this._active) {
// this._miners.forEach(miner => miner.start());
// } else {
// this._miners.forEach(miner => miner.stop());
// }
this._status.coins[0].total = 0;
}
updateSettings(settings) {
Object.assign(this._settings, settings);
console.log(this._settings);
}
loadMiner(name) {
const miner = new xmrig_miner_1.XMRIGMiner(this.app);
this.#miners.push(miner);
}
removeMiner(name) {
const miner = this._getMiner(name);
miner.stop();
}
pauseMiner(name) {
this._getMiner(name).pause();
}
updateMiner(name, settings) {
this._getMiner(name).update(settings);
}
_getMiner(name) {
return this.#miners.find(miner => miner.name === name);
}
}
exports.Controller = Controller;