Skip to content

Commit

Permalink
syntax issues fixed by IDE
Browse files Browse the repository at this point in the history
  • Loading branch information
mutalisk999 committed Nov 27, 2021
1 parent 1f85956 commit 415ec38
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 40 deletions.
60 changes: 30 additions & 30 deletions lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var charts = require('./charts.js');
var authSid = Math.round(Math.random() * 10000000000) + '' + Math.round(Math.random() * 10000000000);

var logSystem = 'api';
var emailSystem = require('./email.js');
// var emailSystem = require('./email.js');
require('./exceptionWriter.js')(logSystem);

var redisCommands = [
Expand Down Expand Up @@ -86,7 +86,7 @@ function collectStats(){
var shares = minersHashrate[miner];
// Do not count the hashrates of individual workers. Instead
// only use the shares where miner == wallet address.
if (miner.indexOf('+') != -1) {
if (miner.indexOf('+') !== -1) {
totalShares += shares;
}
minersHashrate[miner] = Math.round(shares / config.api.hashrateWindow);
Expand All @@ -100,8 +100,8 @@ function collectStats(){
data.roundHashes = 0;

if (replies[5]){
for (var miner in replies[5]){
data.roundHashes += parseInt(replies[5][miner]);
for (var reply in replies[5]){
data.roundHashes += parseInt(replies[5][reply]);
}
}

Expand Down Expand Up @@ -268,7 +268,7 @@ function handleMinerStats(urlParts, response){
for (var i=0; i<replies[3].length; i++) {
var key = replies[3][i];
var nameOffset = key.indexOf('+');
if (nameOffset != -1) {
if (nameOffset !== -1) {
workers.push(key.substr(nameOffset + 1));
}
}
Expand Down Expand Up @@ -324,13 +324,13 @@ function handleSetMinerPayoutLevel(urlParts, response){
var level = urlParts.query.level;

// Check the minimal required parameters for this handle.
if (ip == undefined || address == undefined || level == undefined) {
if (ip === undefined || address === undefined || level === undefined) {
response.end(JSON.stringify({'status': 'parameters are incomplete'}));
return;
}

// Do not allow wildcards in the queries.
if (ip.indexOf('*') != -1 || address.indexOf('*') != -1) {
if (ip.indexOf('*') !== -1 || address.indexOf('*') !== -1) {
response.end(JSON.stringify({'status': 'remove the wildcard from your input'}));
return;
}
Expand All @@ -349,7 +349,7 @@ function handleSetMinerPayoutLevel(urlParts, response){
// Only do a modification if we have seen the IP address in
// combination with the wallet address.
minerSeenWithIPForAddress(address, ip, function (error, keys) {
if (keys.length == 0 || error) {
if (keys.length === 0 || error) {
response.end(JSON.stringify({'status': 'we haven\'t seen that IP for your etnx address'}));
return;
}
Expand Down Expand Up @@ -379,7 +379,7 @@ function handleGetMinerPayoutLevel(urlParts, response){

var address = urlParts.query.address;
// Check the minimal required parameters for this handle.
if (address == undefined) {
if (address === undefined) {
response.end(JSON.stringify({'status': 'parameters are incomplete'}));
return;
}
Expand All @@ -391,7 +391,7 @@ function handleGetMinerPayoutLevel(urlParts, response){
}
var tokens = value / config.coinUnits
response.end(JSON.stringify({'status': 'done', 'level': tokens}));
return;

});
}

Expand All @@ -410,44 +410,44 @@ function handleSetAddressEmail(urlParts, response){
var action = urlParts.query.action;

// Check the minimal required parameters for this handle.
if (address == undefined || action == undefined) {
if (address === undefined || action === undefined) {
response.end(JSON.stringify({'status': 'parameters are incomplete'}));
return;
}

// Do not allow wildcards in the queries.
if (ip.indexOf('*') != -1 || address.indexOf('*') != -1) {
if (ip.indexOf('*') !== -1 || address.indexOf('*') !== -1) {
response.end(JSON.stringify({'status': 'remove the wildcard from your input'}));
return;
}

// Now only do a modification if we have seen the IP address in combination
// with the wallet address.
minerSeenWithIPForAddress(address, ip, function (error, keys) {
if (keys.length == 0 || error) {
if (keys.length === 0 || error) {
response.end(JSON.stringify({'status': 'we haven\'t seen that IP for your etnx address'}));
return;
}

if (action == "upsert") {
if (email == undefined) {
if (action === "upsert") {
if (email === undefined) {
response.end(JSON.stringify({'status': 'email is missing'}));
return;
}
redisClient.hset(config.coin + ':notifications:', address, email, function(error, value){
if (error){
response.end(JSON.stringify({'status': 'woops something failed'}));
return;

}

// emailSystem.notifyAddress(address, 'Your email was registered', 'email_added');
});
log('info', logSystem, 'Added email ' + email + ' for address: ' + address);
} else if (action == "delete") {
} else if (action === "delete") {
redisClient.hdel(config.coin + ':notifications:', address, function(error, value){
if (error){
response.end(JSON.stringify({'status': 'woops something failed'}));
return;

}
});
log('info', logSystem, 'Removed email for address: ' + address);
Expand All @@ -468,7 +468,7 @@ function handleGetAddressEmail(urlParts, response){
var address = urlParts.query.address;

// Check the minimal required parameters for this handle.
if (address == undefined) {
if (address === undefined) {
response.end(JSON.stringify({'status': 'parameters are incomplete'}));
return;
}
Expand All @@ -479,7 +479,7 @@ function handleGetAddressEmail(urlParts, response){
return;
}
response.end(JSON.stringify({'email': value}));
return;

});
}

Expand Down Expand Up @@ -578,14 +578,14 @@ function authorize(request, response){
remoteAddress = request.headers['x-forwarded-for'];
}

if(remoteAddress == '127.0.0.1' || remoteAddress == '::ffff:127.0.0.1' || remoteAddress == '::1') {
if(remoteAddress === '127.0.0.1' || remoteAddress === '::ffff:127.0.0.1' || remoteAddress === '::1') {
return true;
}

response.setHeader('Access-Control-Allow-Origin', '*');

var cookies = parseCookies(request);
if(cookies.sid && cookies.sid == authSid) {
if(cookies.sid && cookies.sid === authSid) {
return true;
}

Expand Down Expand Up @@ -664,8 +664,8 @@ function handleAdminStats(response){
stats.totalWorkers++;
}

for (var i = 0; i < blocks.length; i++){
var block = blocks[i].split(':');
for (var j = 0; j < blocks.length; j++){
var block = blocks[j].split(':');
if (block[5]) {
stats.blocksUnlocked++;
stats.totalDiff += parseInt(block[2]);
Expand Down Expand Up @@ -784,9 +784,9 @@ function handleHealthRequest(response) {
}, function(error, result) {
var status = 'NOT OK';
if (result['monitoring']['daemon'] &&
result['monitoring']['daemon']['lastStatus'] == "ok" &&
result['monitoring']['daemon']['lastStatus'] === "ok" &&
result['monitoring']['wallet'] &&
result['monitoring']['wallet']['lastStatus'] == "ok") {
result['monitoring']['wallet']['lastStatus'] === "ok") {
status = 'OK';
}

Expand Down Expand Up @@ -867,7 +867,7 @@ function getLogFiles(callback) {
callback(error, logs);
});
}
if(config.api.ssl == true)
if(config.api.ssl === true)
{
var options = {
key: fs.readFileSync(config.api.sslkey),
Expand Down Expand Up @@ -901,7 +901,7 @@ if(config.api.ssl == true)
handleHealthRequest(response);
break;
case '/stats':
var deflate = request.headers['accept-encoding'] && request.headers['accept-encoding'].indexOf('deflate') != -1;
var deflate = request.headers['accept-encoding'] && request.headers['accept-encoding'].indexOf('deflate') !== -1;
var reply = deflate ? currentStatsCompressed : currentStats;
response.writeHead("200", {
'Access-Control-Allow-Origin': '*',
Expand Down Expand Up @@ -1020,7 +1020,7 @@ var server = http.createServer(function(request, response){
handleHealthRequest(response);
break;
case '/stats':
var deflate = request.headers['accept-encoding'] && request.headers['accept-encoding'].indexOf('deflate') != -1;
var deflate = request.headers['accept-encoding'] && request.headers['accept-encoding'].indexOf('deflate') !== -1;
var reply = deflate ? currentStatsCompressed : currentStats;
response.writeHead("200", {
'Access-Control-Allow-Origin': '*',
Expand Down Expand Up @@ -1113,7 +1113,7 @@ initMonitoring();
server.listen(config.api.port, function(){
log('info', logSystem, 'API started & listening on port %d', [config.api.port]);
});
if(config.api.ssl == true)
if(config.api.ssl === true)
{
server2.listen(config.api.sslport, function(){
log('info', logSystem, 'API started & listening on port %d', [config.api.sslport]);
Expand Down
2 changes: 1 addition & 1 deletion lib/apiInterfaces.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function jsonHttpRequest(host, port, data, callback, path){
}
};

var req = (port == 443 ? https : http).request(options, function(res){
var req = (port === 443 ? https : http).request(options, function(res){
var replyData = '';
res.setEncoding('utf8');
res.on('data', function(chunk){
Expand Down
3 changes: 1 addition & 2 deletions lib/blockUnlocker.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ function runInterval(){
return;
}
for (var i = 0; i < replies.length; i++){
var workerShares = replies[i];
blocks[i].workerShares = workerShares;
blocks[i].workerShares = replies[i];
}
callback(null, blocks);
});
Expand Down
14 changes: 7 additions & 7 deletions lib/pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ function jobRefresh(state){

switch(state){
case "check_force":
if(jobRefreshCounter % config.poolServer.blockRefreshForce == 0)
if(jobRefreshCounter % config.poolServer.blockRefreshForce === 0)
jobRefresh("get_template");
else
jobRefresh("check_count");
Expand All @@ -188,14 +188,14 @@ function jobRefresh(state){
return;
}

if(result.count == currentBlockHeight) {
if(result.count === currentBlockHeight) {
jobRefresh("check_hash");
return;
}

log('info', logSystem, 'Blockchain height changed to %d, updating template.', [currentBlockHeight]);
jobRefresh("get_template");
return;

});
break;

Expand All @@ -206,15 +206,15 @@ function jobRefresh(state){
return;
}

if(result == currentBlockHash) {
if(result === currentBlockHash) {
if(jobRefreshCompleteCallback != null)
jobRefreshCompleteCallback(true);
return;
}

log('info', logSystem, 'Blockchain hash changed to %s, updating template.', currentBlockHash);
jobRefresh("get_template");
return;

});
break;

Expand All @@ -231,7 +231,7 @@ function jobRefresh(state){
var buffer = new Buffer(result.blocktemplate_blob, 'hex');
var previous_hash = new Buffer(32);
buffer.copy(previous_hash,0,7,39);
if (!currentBlockTemplate || previous_hash.toString('hex') != currentBlockTemplate.previous_hash.toString('hex')){
if (!currentBlockTemplate || previous_hash.toString('hex') !== currentBlockTemplate.previous_hash.toString('hex')){
log('info', logSystem, 'New block to mine at height %d w/ difficulty of %d', [result.height, result.difficulty]);
processBlockTemplate(result);
}
Expand Down Expand Up @@ -592,7 +592,7 @@ function handleMinerMethod(method, params, ip, portData, sendReply, pushMessage)
// Grep the worker name.
// var workerNameCharPos = login.indexOf('+');
var workerNameCharPos = login.indexOf('.');
if (workerNameCharPos != -1) {
if (workerNameCharPos !== -1) {
workerName = login.substr(workerNameCharPos + 1);
login = login.substr(0, workerNameCharPos);
log('info', logSystem, 'Miner %s uses worker name: %s', [login, workerName]);
Expand Down

0 comments on commit 415ec38

Please sign in to comment.