From 7f500fc3dfac4de25effff42e2baa36194d4088e Mon Sep 17 00:00:00 2001 From: Matt Date: Thu, 27 Feb 2014 16:59:49 -0700 Subject: [PATCH] Refactored config options --- coins/darkcoin.json | 7 +++ coins/litecoin.json | 7 +++ coins/skeincoin.json | 7 +++ init.js | 40 ++++++++++++----- .../darkcoin_example.json | 39 +++++++--------- pool_configs/litecoin_testnet_example.json | 39 ++++++++++++++++ pool_configs/skeincoin_example.json | 44 +++++++++++++++++++ 7 files changed, 149 insertions(+), 34 deletions(-) create mode 100644 coins/darkcoin.json create mode 100644 coins/litecoin.json create mode 100644 coins/skeincoin.json rename coins/litecoin_testnet_example.json => pool_configs/darkcoin_example.json (61%) create mode 100644 pool_configs/litecoin_testnet_example.json create mode 100644 pool_configs/skeincoin_example.json diff --git a/coins/darkcoin.json b/coins/darkcoin.json new file mode 100644 index 0000000..cecede4 --- /dev/null +++ b/coins/darkcoin.json @@ -0,0 +1,7 @@ +{ + "name": "Darkcoin", + "symbol": "drk", + "algorithm": "x11", + "reward": "POW", + "txMessages": false +} \ No newline at end of file diff --git a/coins/litecoin.json b/coins/litecoin.json new file mode 100644 index 0000000..3420aa9 --- /dev/null +++ b/coins/litecoin.json @@ -0,0 +1,7 @@ +{ + "name": "Litecoin", + "symbol": "ltc", + "algorithm": "scrypt", + "reward": "POW", + "txMessages": false +} \ No newline at end of file diff --git a/coins/skeincoin.json b/coins/skeincoin.json new file mode 100644 index 0000000..cff9be6 --- /dev/null +++ b/coins/skeincoin.json @@ -0,0 +1,7 @@ +{ + "name": "Skeincoin", + "symbol": "skc", + "algorithm": "skein", + "reward": "POW", + "txMessages": false +} \ No newline at end of file diff --git a/init.js b/init.js index 7931aa2..f5efea6 100644 --- a/init.js +++ b/init.js @@ -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(); diff --git a/coins/litecoin_testnet_example.json b/pool_configs/darkcoin_example.json similarity index 61% rename from coins/litecoin_testnet_example.json rename to pool_configs/darkcoin_example.json index 21d7e0d..70aebc3 100644 --- a/coins/litecoin_testnet_example.json +++ b/pool_configs/darkcoin_example.json @@ -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: diff --git a/pool_configs/litecoin_testnet_example.json b/pool_configs/litecoin_testnet_example.json new file mode 100644 index 0000000..59d8b58 --- /dev/null +++ b/pool_configs/litecoin_testnet_example.json @@ -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" + } +} \ No newline at end of file diff --git a/pool_configs/skeincoin_example.json b/pool_configs/skeincoin_example.json new file mode 100644 index 0000000..e585181 --- /dev/null +++ b/pool_configs/skeincoin_example.json @@ -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" + } +} \ No newline at end of file