From 43517a88242e60085a262fb3a5217ca6eff8d239 Mon Sep 17 00:00:00 2001 From: Matthew Little Date: Sat, 11 Jan 2014 14:25:57 -0500 Subject: [PATCH] added blocknotify functionality --- README.md | 4 ++-- blockNotify.js | 1 + init.js | 11 +++++++++++ pool.js | 44 +++++++++++++++++++++++++++++--------------- 4 files changed, 43 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 3c5598f..66cf3a1 100644 --- a/README.md +++ b/README.md @@ -88,12 +88,12 @@ Installation [path to blockNotify.js] [pool host]:[pool blockNotifyListener port] [blockNotifyListener password] - [coin symbole set in coin's json config] + [coin symbol set in coin's json config] %s" ``` * Example: `dogecoind -blocknotify="blockNotify.js localhost:8117 mySuperSecurePassword doge %s"` - * If your daemon is on a different host you will have to copy the `blockNotify.js` to it + * If your daemon is on a different host you will have to copy over `blockNotify.js` * To start the poolserver run: diff --git a/blockNotify.js b/blockNotify.js index a78d66d..deea49e 100644 --- a/blockNotify.js +++ b/blockNotify.js @@ -14,6 +14,7 @@ var client = net.connect(port, host, function() { console.log('client connected'); client.write(JSON.stringify({ password: password, + coin: coin, blockHash: blockHash }) + '\n'); }); diff --git a/init.js b/init.js index e21bd4e..95706f3 100644 --- a/init.js +++ b/init.js @@ -54,6 +54,17 @@ if (config.blockNotifyListener.enabled){ }); c.on('end', function() { console.log(data); + + var message = JSON.parse(data); + if (message.password === config.blockNotifyListener.password){ + coins.forEach(function(coin){ + if (coin.options.symbol === message.coin){ + coin.pool.processBlockNotify(message.blockHash); + return false; + } + }); + } + console.log('server disconnected'); }); }); diff --git a/pool.js b/pool.js index 4d2d560..51bfbc9 100644 --- a/pool.js +++ b/pool.js @@ -44,21 +44,7 @@ var pool = module.exports = function pool(coin){ this.daemon = new daemon.interface(coin.options.daemon); this.daemon.on('online', function(){ async.parallel({ - rpcTemplate: function(callback){ - _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{ - //result = JSON.parse(fs.readFileSync('example.json')); - callback(null, result); - } - } - ); - }, + rpcTemplate: GetBlockTemplate, addressInfo: function(callback){ _this.daemon.cmd('validateaddress', [coin.options.address], @@ -144,5 +130,33 @@ var pool = module.exports = function pool(coin){ }); }); } + + function GetBlockTemplate(callback){ + _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{ + callback(null, result); + } + } + ); + } + + this.processBlockNotify = function(blockHash){ + if (blockHash !== _this.jobManager.currentJob.rpcData.previousblockhash){ + GetBlockTemplate(function(error, result){ + if (error){ + console.log('Error getting block template for ' + coin.options.name); + return; + } + _this.jobManager.newTemplate(result, publicKeyBuffer); + }) + } + } + }; pool.prototype.__proto__ = events.EventEmitter.prototype; \ No newline at end of file