Refactored config options

This commit is contained in:
Matt 2014-02-27 16:59:49 -07:00
parent 08fe9ab18d
commit 7f500fc3df
7 changed files with 149 additions and 34 deletions

7
coins/darkcoin.json Normal file
View File

@ -0,0 +1,7 @@
{
"name": "Darkcoin",
"symbol": "drk",
"algorithm": "x11",
"reward": "POW",
"txMessages": false
}

7
coins/litecoin.json Normal file
View File

@ -0,0 +1,7 @@
{
"name": "Litecoin",
"symbol": "ltc",
"algorithm": "scrypt",
"reward": "POW",
"txMessages": false
}

7
coins/skeincoin.json Normal file
View File

@ -0,0 +1,7 @@
{
"name": "Skeincoin",
"symbol": "skc",
"algorithm": "skein",
"reward": "POW",
"txMessages": false
}

40
init.js
View File

@ -35,13 +35,30 @@ stratum.on('log', function(logText){
});
fs.readdirSync('coins').forEach(function(file){
var coinProfiles = (function(){
var profiles = {};
fs.readdirSync('coins').forEach(function(file){
var coinProfile = JSON.parse(JSON.minify(fs.readFileSync('coins/' + file, {encoding: 'utf8'})));
profiles[coinProfile.name.toLowerCase()] = coinProfile;
});
return profiles;
})();
var coinOptions = JSON.parse(JSON.minify(fs.readFileSync('coins/' + file, {encoding: 'utf8'})));
fs.readdirSync('pool_configs').forEach(function(file){
var poolOptions = JSON.parse(JSON.minify(fs.readFileSync('pool_configs/' + file, {encoding: 'utf8'})));
if (poolOptions.disabled) return;
if (!(poolOptions.coin.toLowerCase() in coinProfiles)){
logError(poolOptions.coin, 'system', 'could not find coin profile');
return;
}
poolOptions.coin = coinProfiles[poolOptions.coin.toLowerCase()];
var authorizeFN = function (ip, workerName, password, callback) {
// Default implementation just returns true
logDebug(coinOptions.name, 'client', "Authorize ["+ip+"] "+workerName+":"+password);
logDebug(poolOptions.coin.name, 'client', "Authorize ["+ip+"] "+workerName+":"+password);
callback({
error: null,
authorized: true,
@ -50,28 +67,29 @@ fs.readdirSync('coins').forEach(function(file){
};
var pool = stratum.createPool(coinOptions, authorizeFN);
var pool = stratum.createPool(poolOptions, authorizeFN);
pool.on('share', function(isValidShare, isValidBlock, data){
var shareData = JSON.stringify(data);
if (data.solution && !isValidBlock)
logDebug(coinOptions.name, 'client', 'We thought a block solution was found but it was rejected by the daemon, share data: ' + shareData);
logDebug(poolOptions.coin.name, 'client', 'We thought a block solution was found but it was rejected by the daemon, share data: ' + shareData);
else if (isValidBlock)
logDebug(coinOptions.name, 'client', 'Block found, share data: ' + shareData);
logDebug(poolOptions.coin.name, 'client', 'Block found, share data: ' + shareData);
else if (isValidShare)
logDebug(coinOptions.name, 'client', 'Valid share submitted, share data: ' + shareData);
logDebug(poolOptions.coin.name, 'client', 'Valid share submitted, share data: ' + shareData);
else
logDebug(coinOptions.name, 'client', 'Invalid share submitted, share data: ' + shareData)
logDebug(poolOptions.coin.name, 'client', 'Invalid share submitted, share data: ' + shareData)
}).on('log', function(severity, logKey, logText) {
if (severity == 'debug') {
logDebug(coinOptions.name, logKey, logText);
logDebug(poolOptions.coin.name, logKey, logText);
} else if (severity == 'warning') {
logWarning(coinOptions.name, logKey, logText);
logWarning(poolOptions.coin.name, logKey, logText);
} else if (severity == 'error') {
logError(coinOptions.name, logKey, logText);
logError(poolOptions.coin.name, logKey, logText);
}
});
pool.start();

View File

@ -1,37 +1,30 @@
{
"name": "Litecoin",
"symbol": "ltc",
"algorithm": "scrypt",
"reward": "POW",
"txMessages": false,
"address": "mi4iBXbBsydtcc5yFmsff2zCFVX4XG7qJc",
"stratumPort": 3334,
"difficulty": 8,
"blockRefreshInterval": 1000,
"daemon": [
"disabled": true,
"coin": "darkcoin",
"pool": {
"address": "XjkzAVe3zywGhDFSbJtqUN6xeKP37PSNSh",
"stratumPort": 3336,
"difficulty": 0.005,
"blockRefreshInterval": 1000
},
"daemons": [
{
"host": "localhost",
"port": 19332,
"user": "litecoinrpc",
"password": "testnet"
},
{
"host": "localhost",
"port": 19344,
"user": "litecoinrpc",
"password": "testnet"
"port": 15342,
"user": "darkcoinrpc1",
"password": "drkpass"
}
],
"varDiff": {
"enabled": true,
"minDifficulty": 16,
"enabled": false,
"minDifficulty": 1,
"maxDifficulty": 1000,
"targetTime": 30,
"retargetTime": 120,
"variancePercent": 20
},
"p2p": {
"enabled": true,
"enabled": false,
"host": "localhost",
"port": 19333,
@ -40,7 +33,7 @@
*/
"protocolVersion": 70002,
/* Magic value is different for main/testnet and for each coin. It is found in the daemon
/* Magic value is different for main/testnet and for each coins. It is found in the daemon
source code as the pchMessageStart variable. For example, litecoin mainnet:
http://github.com/litecoin-project/litecoin/blob/85f303d883ffff35238eaea5174b780c950c0ae4/src/main.cpp#L3059
And for litecoin testnet:

View File

@ -0,0 +1,39 @@
{
"disabled": false,
"coin": "litecoin",
"pool": {
"address": "mi4iBXbBsydtcc5yFmsff2zCFVX4XG7qJc",
"stratumPort": 3334,
"difficulty": 8,
"blockRefreshInterval": 1000
},
"daemons": [
{
"host": "localhost",
"port": 19332,
"user": "litecoinrpc",
"password": "testnet"
},
{
"host": "localhost",
"port": 19344,
"user": "litecoinrpc",
"password": "testnet"
}
],
"varDiff": {
"enabled": true,
"minDifficulty": 16,
"maxDifficulty": 1000,
"targetTime": 30,
"retargetTime": 120,
"variancePercent": 20
},
"p2p": {
"enabled": true,
"host": "localhost",
"port": 19333,
"protocolVersion": 70002,
"magic": "fcc1b7dc"
}
}

View File

@ -0,0 +1,44 @@
{
"disabled": true,
"coin": "skeincoin",
"pool": {
"address": "SUxtDjHYijztRKjbnBkvEbA3mQ5wFeS72H",
"stratumPort": 3336,
"difficulty": 0.005,
"blockRefreshInterval": 1000
},
"daemons": [
{
"host": "localhost",
"port": 15347,
"user": "skeincoinrpc1",
"password": "skcpass"
}
],
"varDiff": {
"enabled": false,
"minDifficulty": 16,
"maxDifficulty": 1000,
"targetTime": 30,
"retargetTime": 120,
"variancePercent": 20
},
"p2p": {
"enabled": false,
"host": "localhost",
"port": 19333,
/* Found in src as the PROTOCOL_VERSION variable, for example:
https://github.com/litecoin-project/litecoin/blob/85f303d883ffff35238eaea5174b780c950c0ae4/src/version.h#L28
*/
"protocolVersion": 70002,
/* Magic value is different for main/testnet and for each coins. It is found in the daemon
source code as the pchMessageStart variable. For example, litecoin mainnet:
http://github.com/litecoin-project/litecoin/blob/85f303d883ffff35238eaea5174b780c950c0ae4/src/main.cpp#L3059
And for litecoin testnet:
http://github.com/litecoin-project/litecoin/blob/85f303d883ffff35238eaea5174b780c950c0ae4/src/main.cpp#L2722-L2725
*/
"magic": "fcc1b7dc"
}
}