s-nomp/init.js

81 lines
2.3 KiB
JavaScript
Raw Normal View History

2014-02-20 15:13:50 -08:00
var fs = require('fs');
var posix = require('posix');
var Stratum = require('stratum-pool');
var PoolLogger = require('./libs/logutils.js');
JSON.minify = JSON.minify || require("node-json-minify");
2014-02-20 15:13:50 -08:00
try{
posix.setrlimit('nofile', { soft: 100000 });
}
catch(e){
console.error(e);
}
var loggerInstance = new PoolLogger({
'default': true,
'keys': {
//'client' : 'warning',
'system' : true,
'submitblock' : true
}
});
2014-01-13 17:32:54 -08:00
var logDebug = loggerInstance.logDebug;
var logWarning = loggerInstance.logWarning;
var logError = loggerInstance.logError;
2014-01-13 17:32:54 -08:00
var config = JSON.parse(JSON.minify(fs.readFileSync("config.json", {encoding: 'utf8'})));
2014-01-13 17:32:54 -08:00
var stratum = new Stratum(config);
stratum.on('log', function(logText){
logDebug(logText);
2014-01-13 17:32:54 -08:00
});
fs.readdirSync('coins').forEach(function(file){
var coinOptions = JSON.parse(JSON.minify(fs.readFileSync('coins/' + file, {encoding: 'utf8'})));
2014-01-13 17:32:54 -08:00
var authorizeFN = function (ip, workerName, password, callback) {
// Default implementation just returns true
logDebug(coinOptions.name, 'client', "Authorize ["+ip+"] "+workerName+":"+password);
2014-01-13 17:32:54 -08:00
callback({
error: null,
authorized: true,
disconnect: false
});
};
var pool = stratum.createPool(coinOptions, authorizeFN);
pool.on('share', function(isValidShare, isValidBlock, data){
var shareData = JSON.stringify(data);
if (isValidBlock)
logDebug(coinOptions.name, 'client', 'Block found, share data: ' + shareData);
else if (isValidShare)
logDebug(coinOptions.name, 'client', 'Valid share submitted, share data: ' + shareData);
else if (data.solution)
logDebug(coinOptions.name, 'client', 'We thought a block solution was found but it was rejected by the daemon, share data: ' + shareData);
2014-01-13 17:32:54 -08:00
else
logDebug(coinOptions.name, 'client', 'Invalid share submitted, share data: ' + shareData)
}).on('log', function(severity, logKey, logText) {
if (severity == 'debug') {
logDebug(coinOptions.name, logKey, logText);
} else if (severity == 'warning') {
logWarning(coinOptions.name, logKey, logText);
} else if (severity == 'error') {
logError(coinOptions.name, logKey, logText);
}
});
pool.start();
2014-01-13 17:32:54 -08:00
});