This commit is contained in:
Matthew Little 2014-01-10 18:18:23 -05:00
parent 1e9b72f6e4
commit b41dd96826
4 changed files with 95 additions and 37 deletions

View File

@ -45,7 +45,29 @@ Requirements
Installation
------------
* ....
* For each coin you would like to start a pool server for, create a file in the "coins" directory titled "(name of coin).json"
Example configuration for dogecoin.json
```javascript
{
"name": "Dogecoin",
"symbol": "doge",
"algorithm": "scrypt",
"reward": "POW",
"address": "DDt79i6P3Wro3SD3HSnkRLpMgUGUGdiNhS",
"stratumPort": 3333,
"difficulty": 8,
"daemon": {
"bin": "dogecoind",
"port": 8332,
"user": "test",
"password": "test",
"blocknotify": "blockNotify.js doge %s",
"startIfOffline": true
}
}
```
* To start the poolserver run init.js
`node init.js`
Credits

32
init.js
View File

@ -1,4 +1,6 @@
var net = require('net');
var fs = require('fs');
var path = require('path');
var bignum = require('bignum');
@ -10,6 +12,10 @@ function Coin(options){
}
Coin.prototype = {};
var coins = [];
/*
var coins = [
new Coin({
name: 'Dogecoin',
@ -28,12 +34,32 @@ var coins = [
startIfOffline: true
}
})
];
];*/
coins.forEach(function(coin){
coin.pool = new pool(coin);
var logRef = console.log;
console.log = function(s){
var time = new Date().toISOString();
logRef(time + ': ' + s);
};
var confFolder = 'coins';
fs.readdir(confFolder, function(err, files){
if (err) throw err;
files.forEach(function(file){
var filePath = confFolder + '/' + file;
if (path.extname(filePath) !== '.json') return;
fs.readFile(filePath, {encoding: 'utf8'}, function(err, data){
if (err) throw err;
var coinJson = JSON.parse(data)
var coin = new Coin(coinJson);
console.log('Starting pool for ' + coin.options.name);
coin.pool = new pool(coin);
coins.push(coin);
});
});
});

72
pool.js
View File

@ -40,7 +40,7 @@ var pool = module.exports = function pool(coin){
);
});
console.log('Connecting to daemon for ' + coin.options.name);
this.daemon = new daemon.interface(coin.options.daemon);
this.daemon.on('online', function(){
async.parallel({
@ -89,7 +89,7 @@ var pool = module.exports = function pool(coin){
}
}, function(err, results){
if (err) return;
console.log('Connected to daemon for ' + coin.options.name);
coin.options.hasSubmitMethod = results.submitMethod;
publicKeyBuffer = coin.options.reward === 'POW' ?
@ -98,6 +98,8 @@ var pool = module.exports = function pool(coin){
_this.jobManager.newTemplate(results.rpcTemplate, publicKeyBuffer);
StartStatumServer();
});
}).on('startFailed', function(){
@ -105,36 +107,42 @@ var pool = module.exports = function pool(coin){
});
this.stratumServer = new stratum.Server({
port: coin.options.stratumPort
});
this.stratumServer.on('client', function(client){
client.on('subscription', function(params, resultCallback){
var extraNonce = _this.jobManager.extraNonceCounter.next();
var extraNonce2Size = _this.jobManager.extraNonce2Size;
resultCallback(null,
extraNonce,
extraNonce2Size
);
this.sendDifficulty(coin.options.difficulty);
this.sendMiningJob(_this.jobManager.currentJob.getJobParams());
}).on('authorize', function(params, resultCallback){
resultCallback(null, true);
}).on('submit', function(params, resultCallback){
var result =_this.jobManager.processShare(
params.jobId,
client.difficulty,
client.extraNonce1,
params.extraNonce2,
params.nTime,
params.nonce
);
if (result.error){
resultCallback(result.error);
return;
}
resultCallback(null, true);
function StartStatumServer(){
console.log('Stratum server starting on port ' + coin.options.stratumPort + ' for ' + coin.options.name);
this.stratumServer = new stratum.Server({
port: coin.options.stratumPort
});
});
this.stratumServer.on('started', function(){
console.log('Stratum server started on port ' + coin.options.stratumPort + ' for ' + coin.options.name);
}).on('client', function(client){
client.on('subscription', function(params, resultCallback){
var extraNonce = _this.jobManager.extraNonceCounter.next();
var extraNonce2Size = _this.jobManager.extraNonce2Size;
resultCallback(null,
extraNonce,
extraNonce2Size
);
this.sendDifficulty(coin.options.difficulty);
this.sendMiningJob(_this.jobManager.currentJob.getJobParams());
}).on('authorize', function(params, resultCallback){
resultCallback(null, true);
}).on('submit', function(params, resultCallback){
var result =_this.jobManager.processShare(
params.jobId,
client.difficulty,
client.extraNonce1,
params.extraNonce2,
params.nTime,
params.nonce
);
if (result.error){
resultCallback(result.error);
return;
}
resultCallback(null, true);
});
});
}
};
pool.prototype.__proto__ = events.EventEmitter.prototype;

View File

@ -205,7 +205,9 @@ var StratumServer = exports.Server = function StratumServer(options){
stratumClients[subscriptionId] = client;
_this.emit('client', client);
});
_socketServer.listen(options.port, function(){});
_socketServer.listen(options.port, function(){
_this.emit('started');
});
})();