Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
argv.server = argvCmd.server || argv.server;
argv.cpu = argvCmd.cpu || argv.cpu;
console.log(argv);
if (!argv.address) {
await logWithoutExit('Usage: node index.js --address=<address> [--name=] [--thread=] [--server=] [--percent=] [--cpu=]');
}
const address = argv.address;
let name = argv.name || '*';
// auto set name
if (name === '*') {
name = [ip.address(), os.platform(), os.arch(), os.release()].join(' ');
Log.w(`auto set name to ${name}`)
}
let thread = parseInt(argv.thread);
const max_thread = os.cpus().length;
if (thread > max_thread) {
Log.w(`thread ${thread} larger than CPU threads ${max_thread}, force thread to ${max_thread}`);
thread = max_thread;
}
if (thread === 0 || !Number.isInteger(thread)) {
thread = max_thread > 1 ? max_thread - 1 : 1;
Log.w(`auto set thread to ${thread}`);
}
if (thread < 0) {
thread = max_thread;
Log.w(`auto set thread to ${thread}`);
}</address>switchInedx = 0;
}
server = argv.server[switchInedx];
Log.w(`switch to server ${server}`);
} else {
server = argv.server;
}
const percent = parseFloat(argv.percent || 100);
const event = new EventEmitter();
// choose cpu version
let cpu;
if (argv.cpu && CPUType[argv.cpu]) {
Log.w('CPU type given by user, choose ' + argv.cpu + ' version.');
cpu = CPUType[argv.cpu];
} else {
cpu = await autoDetectCPU();
}
if (thread > 128) {
logWithoutExit('Error: thread too large');
} else if (thread <= 0) {
logWithoutExit('Error: thread too small');
} else if (address && address.length !== 44) {
logWithoutExit('Error: address format error');
} else if (name && name.length > 200) {
logWithoutExit('Error: name too long');
} else if (percent < 50 || percent > 100) {
logWithoutExit('Error: percent need between 50 to 100');
} else {let name = argv.name || '*';
// auto set name
if (name === '*') {
name = [ip.address(), os.platform(), os.arch(), os.release()].join(' ');
Log.w(`auto set name to ${name}`)
}
let thread = parseInt(argv.thread);
const max_thread = os.cpus().length;
if (thread > max_thread) {
Log.w(`thread ${thread} larger than CPU threads ${max_thread}, force thread to ${max_thread}`);
thread = max_thread;
}
if (thread === 0 || !Number.isInteger(thread)) {
thread = max_thread > 1 ? max_thread - 1 : 1;
Log.w(`auto set thread to ${thread}`);
}
if (thread < 0) {
thread = max_thread;
Log.w(`auto set thread to ${thread}`);
}
// switch server
let server;
if (typeof argv.server === 'object') {
if (switchInedx >= argv.server.length) {
switchInedx = 0;
}
server = argv.server[switchInedx];
Log.w(`switch to server ${server}`);
} else {
server = argv.server;autoRestartInterval = setInterval(() => {
if (miner && miner._hashrateValue <= 0.01) {
Log.w('Hashrate is zero');
zeroHashCount++;
} else {
zeroHashCount = 0;
}
if (zeroHashCount >= 3) {
Log.w('Restart beacuse of zero hashrate');
zeroHashCount = 0;
miner.delete();
switchInedx += 1;
main();
}
}, 20000);autoRestartInterval = setInterval(() => {
if (miner && miner._hashrateValue <= 0.01) {
Log.w('Hashrate is zero');
zeroHashCount++;
} else {
zeroHashCount = 0;
}
if (zeroHashCount >= 3) {
Log.w('Restart beacuse of zero hashrate');
zeroHashCount = 0;
miner.delete();
switchInedx += 1;
main();
}
}, 20000);