Merge pull request #172 from lubuzzo/dev

Generate a new address after submit a block
This commit is contained in:
Michael Polzer 2019-03-24 18:56:07 +01:00 committed by GitHub
commit 0af3101931
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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));