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
This commit is contained in:
lubuzzo 2019-03-24 12:33:58 -03:00
parent eec9fc9d67
commit 6f43936a76

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