From 6f43936a763c3499beec0617897a7ec958136b05 Mon Sep 17 00:00:00 2001 From: lubuzzo Date: Sun, 24 Mar 2019 12:33:58 -0300 Subject: [PATCH 1/2] Generate a new address after submit a block - Pool will generate a new address on the startup and after a block be submitted - So, pool owner will have a better privacity - once, every single block will be find by a different address --- lib/pool.js | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/pool.js b/lib/pool.js index 11363d0..025fe39 100644 --- a/lib/pool.js +++ b/lib/pool.js @@ -20,6 +20,9 @@ var pool = module.exports = function pool(options, authorizeFn){ var _this = this; var blockPollingIntervalId; + if (!(options.address)) { + _this.newAddressOnNewBlock = true; + } var emitLog = function(text) { _this.emit('log', 'debug' , text); }; var emitWarningLog = function(text) { _this.emit('log', 'warning', text); }; @@ -223,7 +226,6 @@ var pool = module.exports = function pool(options, authorizeFn){ Coin daemons either use submitblock or getblocktemplate for submitting new blocks */ function SubmitBlock(blockHex, callback){ - var rpcCommand, rpcArgs; if (options.hasSubmitMethod){ rpcCommand = 'submitblock'; @@ -234,6 +236,16 @@ var pool = module.exports = function pool(options, authorizeFn){ rpcArgs = [{'mode': 'submit', 'data': blockHex}]; } + if (_this.newAddressOnNewBlock) { + _this.daemon.cmd('getnewaddress', [], function(results) { + + options.poolAddressScript = (function(){ + return util.addressToScript(options.network, results[0].response); + })(); + + options.address = results[0].response; + }); + } _this.daemon.cmd(rpcCommand, rpcArgs, @@ -350,7 +362,14 @@ var pool = module.exports = function pool(options, authorizeFn){ }); _this.daemon.once('online', function(){ - finishedCallback(); + + if (!(options.address)) { + _this.daemon.cmd('getnewaddress', [], function(results) { + options.address = results[0].response; + finishedCallback(); + }) + } + }).on('connectionFailed', function(error){ emitErrorLog('Failed to connect daemon(s): ' + JSON.stringify(error)); From 9b4b7dfac52e97a7e9442c0de21fc4eb8faeee3d Mon Sep 17 00:00:00 2001 From: lubuzzo Date: Sun, 24 Mar 2019 13:03:36 -0300 Subject: [PATCH 2/2] Fixed a issue when user explicity specify the address --- lib/pool.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/pool.js b/lib/pool.js index 025fe39..a6422b1 100644 --- a/lib/pool.js +++ b/lib/pool.js @@ -362,14 +362,13 @@ var pool = module.exports = function pool(options, authorizeFn){ }); _this.daemon.once('online', function(){ - - if (!(options.address)) { + if (options.address == false) { _this.daemon.cmd('getnewaddress', [], function(results) { options.address = results[0].response; finishedCallback(); }) } - + finishedCallback(); }).on('connectionFailed', function(error){ emitErrorLog('Failed to connect daemon(s): ' + JSON.stringify(error));