diff --git a/blockTemplate.js b/blockTemplate.js index ba2392b..2c9304b 100644 --- a/blockTemplate.js +++ b/blockTemplate.js @@ -44,6 +44,12 @@ var BlockTemplate = module.exports = function BlockTemplate(jobId, rpcData, publ extraNoncePlaceholder ); + /** + * Checks if the rpcData provided as argument contains the same previousblockhash of the current job. + **/ + this.isRPCDataFromSameBlock = function(rpcData) { + return this.rpcData.previousblockhash == rpcData.previousblockhash; + } this.serializeCoinbase = function(extraNonce1, extraNonce2){ return Buffer.concat([ this.generationTransaction.coinbase[0], @@ -71,7 +77,7 @@ var BlockTemplate = module.exports = function BlockTemplate(jobId, rpcData, publ this.serializeBlock = function(header, coinbase){ return Buffer.concat([ header, - util.varIntBuffer(this.rpcData.transaction.length + 1), + util.varIntBuffer(this.rpcData.transactions.length + 1), coinbase, this.transactionData ]); diff --git a/coins/dogecoin.json b/coins/dogecoin.json index bc2c10a..eb87631 100644 --- a/coins/dogecoin.json +++ b/coins/dogecoin.json @@ -3,13 +3,13 @@ "symbol": "doge", "algorithm": "scrypt", "reward": "POW", - "address": "DDt79i6P3Wro3SD3HSnkRLpMgUGUGdiNhS", + "address": "mkLyYQ5U8aFQ8aDAF1GS9zXStTzi3m29Tg", "stratumPort": 3334, "difficulty": 8, "daemon": { "host": "localhost", - "port": 8332, - "user": "test", - "password": "test" + "port": 19334, + "user": "testnet", + "password": "AHhQYqfSZqzQvkSXAtHtDAbKaZaoPih3wfmJfgCtjRx9" } -} \ No newline at end of file +} diff --git a/config.json b/config.json index 8da2b88..feffc01 100644 --- a/config.json +++ b/config.json @@ -1,6 +1,6 @@ { "blockNotifyListener": { - "enabled": true, + "enabled": false, "port": 8117, "password": "test" } diff --git a/daemon.js b/daemon.js index cc243e1..1453da8 100644 --- a/daemon.js +++ b/daemon.js @@ -55,6 +55,11 @@ function DaemonInterface(options){ params: params }); + if (method == 'submitblock') { + console.log("SUBMITBLOCK daemon"); + console.log(requestJson); + } + var options = { hostname: 'localhost', port: _this.options.port, diff --git a/init.js b/init.js index 95706f3..6e94338 100644 --- a/init.js +++ b/init.js @@ -42,6 +42,7 @@ fs.readdir(confFolder, function(err, files){ if (config.blockNotifyListener.enabled){ + console.log("ENABLED"); var blockNotifyServer = net.createServer(function(c) { console.log('server connected'); var data = ''; @@ -69,4 +70,16 @@ if (config.blockNotifyListener.enabled){ }); }); blockNotifyServer.listen(config.blockNotifyListener.port, function() {}); +} else { + console.log("NOT ENABLED"); + // If blockNotifyListener isn't enabled then we need to set up some polling parameters. + var pollingTime = typeof(config.blockPollingTime) === 'undefined' ? 5000 : parseInt(config.blockPollingTime, 10); + setInterval( + function () { + coins.forEach(function(coin) { + //coin.pool. + }); + }, + pollingTime + ); } diff --git a/jobManager.js b/jobManager.js index 266e304..ac64689 100644 --- a/jobManager.js +++ b/jobManager.js @@ -145,8 +145,8 @@ var JobManager = module.exports = function JobManager(options){ var headerBigNum = bignum.fromBuffer(headerHash, {endian: 'little', size: 32}); if (job.target.ge(headerBigNum)){ - var blockHex = job.serializeBlock(headerBuffer, coinbaseBuffer); - _this.emit('blockFound', blockHex); + var blockBuf = job.serializeBlock(headerBuffer, coinbaseBuffer); + _this.emit('blockFound', blockBuf.toString('hex')); } var targetUser = bignum(diffDividend / difficulty); diff --git a/pool.js b/pool.js index 51bfbc9..00514bb 100644 --- a/pool.js +++ b/pool.js @@ -24,20 +24,25 @@ var pool = module.exports = function pool(coin){ _this.stratumServer.broadcastMiningJobs(blockTemplate.getJobParams()); }).on('blockFound', function(blockHex){ - if (coin.options.hasSubmitMethod) + if (coin.options.hasSubmitMethod) { _this.daemon.cmd('submitblock', [blockHex], function(error, result){ - + console.log(JSON.stringify(error)); + console.log(JSON.stringify(result)); + console.log("submitblock", JSON.stringify(error), JSON.stringify(result)); } ); - else + } else { _this.daemon.cmd('getblocktemplate', [{'mode': 'submit', 'data': blockHex}], function(error, result){ - + console.log(JSON.stringify(error)); + console.log(JSON.stringify(result)); + console.log("submitblockgetBlockTEmplate", JSON.stringify(error), JSON.stringify(result)); } ); + } }); console.log('Connecting to daemon for ' + coin.options.name); @@ -132,11 +137,11 @@ var pool = module.exports = function pool(coin){ } function GetBlockTemplate(callback){ + console.log("getBlockTemplate"); _this.daemon.cmd('getblocktemplate', [{"capabilities": [ "coinbasetxn", "workid", "coinbase/append" ]}], function(error, result){ if (error){ - console.log('getblocktemplate rpc error for ' + coin.options.name); callback(error); } else{ @@ -146,6 +151,13 @@ var pool = module.exports = function pool(coin){ ); } + this.processBlockPolling = function() { + GetBlockTemplate(function(error, result) { + console.log(JSON.stringify(result)); + _this.jobManager.newTemplate(result, publicKeyBuffer); + }); + } + this.processBlockNotify = function(blockHash){ if (blockHash !== _this.jobManager.currentJob.rpcData.previousblockhash){ GetBlockTemplate(function(error, result){