From 4fdd4fcf51f59ac573b3feb3d8365dfa5a3f40e2 Mon Sep 17 00:00:00 2001 From: Andrea Baccega Date: Thu, 13 Feb 2014 22:23:51 +0100 Subject: [PATCH] Fixed a couple of bugs that were preventing the thing to start in case of POS --- lib/pool.js | 52 +++++++++++++++++++++++++++++++--------------------- lib/util.js | 2 +- 2 files changed, 32 insertions(+), 22 deletions(-) diff --git a/lib/pool.js b/lib/pool.js index 5c08be0..2f0c96b 100644 --- a/lib/pool.js +++ b/lib/pool.js @@ -81,6 +81,10 @@ var pool = module.exports = function pool(options, authorizeFn){ _this.daemon.cmd('submitblock', [blockHex], function(error, result){ + console.log(JSON.stringify([error,result])); + emitLog('submitblock', JSON.stringify([error,result])); + + if (error) emitErrorLog('submitblock', 'rpc error when submitting block with submitblock') else @@ -92,6 +96,7 @@ var pool = module.exports = function pool(options, authorizeFn){ _this.daemon.cmd('getblocktemplate', [{'mode': 'submit', 'data': blockHex}], function(error, result){ + console.log(error, result); if (error) emitErrorLog('submitblock', 'rpc error when submitting block with getblocktemplate') else @@ -182,32 +187,37 @@ var pool = module.exports = function pool(options, authorizeFn){ emitLog('system','Connected to daemon'); options.hasSubmitMethod = results.submitMethod; + if (options.reward === 'POS' && typeof(results.addressInfo.pubkey) == 'undefined') { + // address provided is not of the wallet. + emitErrorLog('system', 'The address provided is not from the daemon wallet.'); + return; + } else { + publicKeyBuffer = options.reward === 'POW' ? + util.script_to_address(results.addressInfo.address) : + util.script_to_pubkey(results.addressInfo.pubkey); - publicKeyBuffer = options.reward === 'POW' ? - util.script_to_address(results.addressInfo.address) : - util.script_to_pubkey(results.addressInfo.pubkey); + if (options.difficulty > results.networkDifficulty && options.difficulty > 16){ + var newDiff = results.networkDifficulty > 16 ? results.networkDifficulty : 16; + emitWarningLog('system', 'pool difficulty was set higher than network difficulty of ' + results.networkDifficulty); + emitWarningLog('system', 'lowering pool diff from ' + options.difficulty + ' to ' + newDiff); - if (options.difficulty > results.networkDifficulty && options.difficulty > 16){ - var newDiff = results.networkDifficulty > 16 ? results.networkDifficulty : 16; - emitWarningLog('system', 'pool difficulty was set higher than network difficulty of ' + results.networkDifficulty); - emitWarningLog('system', 'lowering pool diff from ' + options.difficulty + ' to ' + newDiff); + options.difficulty = newDiff - options.difficulty = newDiff + if (options.varDiff.enabled) + _this.varDiff.setPoolDifficulty(options.difficulty); + } - if (options.varDiff.enabled) - _this.varDiff.setPoolDifficulty(options.difficulty); + GetBlockTemplate(function(error, result){ + if (error){ + console.error(error); + emitErrorLog('system', 'Error with initial getblocktemplate'); + } + else{ + SetupBlockPolling(); + StartStratumServer(); + } + }); } - - GetBlockTemplate(function(error, result){ - if (error){ - console.error(error); - emitErrorLog('system', 'Error with initial getblocktemplate'); - } - else{ - SetupBlockPolling(); - StartStratumServer(); - } - }); }); }).on('startFailed', function(){ diff --git a/lib/util.js b/lib/util.js index 9bd06aa..f916447 100644 --- a/lib/util.js +++ b/lib/util.js @@ -210,7 +210,7 @@ exports.address_to_pubkeyhash = function(addr){ */ exports.script_to_pubkey = function(key){ if (key.length === 66) key = new Buffer(key, 'hex'); - if (key !== 33) throw 'Invalid address'; + if (key.length !== 33) throw 'Invalid address'; var pubkey = new Buffer(35); pubkey[0] = 0x21; pubkey[34] = 0xac;