From 4f298c3ead7651646c27a30601fcdbf6512b367a Mon Sep 17 00:00:00 2001 From: ahmedbodi Date: Sat, 23 Jun 2018 23:19:35 +0100 Subject: [PATCH] Re-add support for pre V10 Codebase Coin Mining (#150) --- lib/daemon.js | 2 +- lib/pool.js | 23 ++++++++++++++++------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/lib/daemon.js b/lib/daemon.js index 30db842..fc4c257 100644 --- a/lib/daemon.js +++ b/lib/daemon.js @@ -37,7 +37,7 @@ function DaemonInterface(daemons, logger){ } function isOnline(callback){ - cmd('getnetworkinfo', [], function(results){ + cmd('getpeerinfo', [], function(results){ var allOnline = results.every(function(result){ return !results.error; }); diff --git a/lib/pool.js b/lib/pool.js index 72c057b..e5f52c9 100644 --- a/lib/pool.js +++ b/lib/pool.js @@ -146,7 +146,8 @@ var pool = module.exports = function pool(options, authorizeFn){ var generateProgress = function(){ - _this.daemon.cmd('getblockchaininfo', [], function(results) { + var cmd = options.coin.hasGetInfo ? 'getinfo' : 'getblockchaininfo'; + _this.daemon.cmd(cmd, [], function(results) { var blockCount = results.sort(function (a, b) { return b.response.blocks - a.response.blocks; })[0].response.blocks; @@ -369,12 +370,15 @@ var pool = module.exports = function pool(options, authorizeFn){ var batchRpcCalls = [ ['validateaddress', [options.address]], ['getdifficulty', []], - ['getblockchaininfo', []], - ['getnetworkinfo', []], ['getmininginfo', []], ['submitblock', []] ]; + if (options.coin.hasGetInfo) { + batchRpcCalls.push(['getinfo', []]); + } else { + batchRpcCalls.push(['getblockchaininfo', []], ['getnetworkinfo', []]); + } _this.daemon.batchCmd(batchRpcCalls, function(error, results){ if (error || !results){ emitErrorLog('Could not start pool, error with init batch RPC call: ' + JSON.stringify(error)); @@ -423,13 +427,18 @@ var pool = module.exports = function pool(options, authorizeFn){ } })(); - options.testnet = (rpcResults.getblockchaininfo.chain === 'test') ? true : false; + options.testnet = options.coin.hasGetInfo ? rpcResults.getinfo.testnet : (rpcResults.getblockchaininfo.chain === 'test') ? true : false; - options.protocolVersion = rpcResults.getnetworkinfo.protocolversion; + options.protocolVersion = options.coin.hasGetInfo ? rpcResults.getinfo.protocolversion : rpcResults.getnetworkinfo.protocolversion; + + var difficulty = options.coin.hasGetInfo ? rpcResults.getinfo.difficulty : rpcResults.getblockchaininfo.difficulty; + if (typeof(difficulty) == 'object') { + difficulty = difficulty['proof-of-work']; + } options.initStats = { - connections: rpcResults.getnetworkinfo.connections, - difficulty: rpcResults.getblockchaininfo.difficulty * algos[options.coin.algorithm].multiplier, + connections: (options.coin.hasGetInfo ? rpcResults.getinfo.connections : rpcResults.getnetworkinfo.connections), + difficulty: difficulty * algos[options.coin.algorithm].multiplier, networkHashRate: rpcResults.getmininginfo.networkhashps };