Merge pull request #172 from lubuzzo/dev
Generate a new address after submit a block
This commit is contained in:
commit
0af3101931
22
lib/pool.js
22
lib/pool.js
@ -20,6 +20,9 @@ var pool = module.exports = function pool(options, authorizeFn){
|
|||||||
var _this = this;
|
var _this = this;
|
||||||
var blockPollingIntervalId;
|
var blockPollingIntervalId;
|
||||||
|
|
||||||
|
if (!(options.address)) {
|
||||||
|
_this.newAddressOnNewBlock = true;
|
||||||
|
}
|
||||||
|
|
||||||
var emitLog = function(text) { _this.emit('log', 'debug' , text); };
|
var emitLog = function(text) { _this.emit('log', 'debug' , text); };
|
||||||
var emitWarningLog = function(text) { _this.emit('log', 'warning', 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
|
Coin daemons either use submitblock or getblocktemplate for submitting new blocks
|
||||||
*/
|
*/
|
||||||
function SubmitBlock(blockHex, callback){
|
function SubmitBlock(blockHex, callback){
|
||||||
|
|
||||||
var rpcCommand, rpcArgs;
|
var rpcCommand, rpcArgs;
|
||||||
if (options.hasSubmitMethod){
|
if (options.hasSubmitMethod){
|
||||||
rpcCommand = 'submitblock';
|
rpcCommand = 'submitblock';
|
||||||
@ -234,6 +236,16 @@ var pool = module.exports = function pool(options, authorizeFn){
|
|||||||
rpcArgs = [{'mode': 'submit', 'data': blockHex}];
|
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,
|
_this.daemon.cmd(rpcCommand,
|
||||||
rpcArgs,
|
rpcArgs,
|
||||||
@ -350,7 +362,13 @@ var pool = module.exports = function pool(options, authorizeFn){
|
|||||||
});
|
});
|
||||||
|
|
||||||
_this.daemon.once('online', function(){
|
_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){
|
}).on('connectionFailed', function(error){
|
||||||
emitErrorLog('Failed to connect daemon(s): ' + JSON.stringify(error));
|
emitErrorLog('Failed to connect daemon(s): ' + JSON.stringify(error));
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user