diff --git a/lib/pool.js b/lib/pool.js index 11363d0..a6422b1 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,13 @@ var pool = module.exports = function pool(options, authorizeFn){ }); _this.daemon.once('online', function(){ - finishedCallback(); + 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));