added blocknotify functionality
This commit is contained in:
parent
f6b512168b
commit
43517a8824
@ -88,12 +88,12 @@ Installation
|
|||||||
[path to blockNotify.js]
|
[path to blockNotify.js]
|
||||||
[pool host]:[pool blockNotifyListener port]
|
[pool host]:[pool blockNotifyListener port]
|
||||||
[blockNotifyListener password]
|
[blockNotifyListener password]
|
||||||
[coin symbole set in coin's json config]
|
[coin symbol set in coin's json config]
|
||||||
%s"
|
%s"
|
||||||
```
|
```
|
||||||
|
|
||||||
* Example: `dogecoind -blocknotify="blockNotify.js localhost:8117 mySuperSecurePassword doge %s"`
|
* Example: `dogecoind -blocknotify="blockNotify.js localhost:8117 mySuperSecurePassword doge %s"`
|
||||||
* If your daemon is on a different host you will have to copy the `blockNotify.js` to it
|
* If your daemon is on a different host you will have to copy over `blockNotify.js`
|
||||||
|
|
||||||
* To start the poolserver run:
|
* To start the poolserver run:
|
||||||
|
|
||||||
|
|||||||
@ -14,6 +14,7 @@ var client = net.connect(port, host, function() {
|
|||||||
console.log('client connected');
|
console.log('client connected');
|
||||||
client.write(JSON.stringify({
|
client.write(JSON.stringify({
|
||||||
password: password,
|
password: password,
|
||||||
|
coin: coin,
|
||||||
blockHash: blockHash
|
blockHash: blockHash
|
||||||
}) + '\n');
|
}) + '\n');
|
||||||
});
|
});
|
||||||
|
|||||||
11
init.js
11
init.js
@ -54,6 +54,17 @@ if (config.blockNotifyListener.enabled){
|
|||||||
});
|
});
|
||||||
c.on('end', function() {
|
c.on('end', function() {
|
||||||
console.log(data);
|
console.log(data);
|
||||||
|
|
||||||
|
var message = JSON.parse(data);
|
||||||
|
if (message.password === config.blockNotifyListener.password){
|
||||||
|
coins.forEach(function(coin){
|
||||||
|
if (coin.options.symbol === message.coin){
|
||||||
|
coin.pool.processBlockNotify(message.blockHash);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
console.log('server disconnected');
|
console.log('server disconnected');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
44
pool.js
44
pool.js
@ -44,21 +44,7 @@ var pool = module.exports = function pool(coin){
|
|||||||
this.daemon = new daemon.interface(coin.options.daemon);
|
this.daemon = new daemon.interface(coin.options.daemon);
|
||||||
this.daemon.on('online', function(){
|
this.daemon.on('online', function(){
|
||||||
async.parallel({
|
async.parallel({
|
||||||
rpcTemplate: function(callback){
|
rpcTemplate: GetBlockTemplate,
|
||||||
_this.daemon.cmd('getblocktemplate',
|
|
||||||
[{"capabilities": [ "coinbasetxn", "workid", "coinbase/append" ]}],
|
|
||||||
function(error, result){
|
|
||||||
if (error){
|
|
||||||
console.log('getblocktemplate rpc error for ' + coin.options.name);
|
|
||||||
callback(error);
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
//result = JSON.parse(fs.readFileSync('example.json'));
|
|
||||||
callback(null, result);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
},
|
|
||||||
addressInfo: function(callback){
|
addressInfo: function(callback){
|
||||||
_this.daemon.cmd('validateaddress',
|
_this.daemon.cmd('validateaddress',
|
||||||
[coin.options.address],
|
[coin.options.address],
|
||||||
@ -144,5 +130,33 @@ var pool = module.exports = function pool(coin){
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function GetBlockTemplate(callback){
|
||||||
|
_this.daemon.cmd('getblocktemplate',
|
||||||
|
[{"capabilities": [ "coinbasetxn", "workid", "coinbase/append" ]}],
|
||||||
|
function(error, result){
|
||||||
|
if (error){
|
||||||
|
console.log('getblocktemplate rpc error for ' + coin.options.name);
|
||||||
|
callback(error);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
callback(null, result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.processBlockNotify = function(blockHash){
|
||||||
|
if (blockHash !== _this.jobManager.currentJob.rpcData.previousblockhash){
|
||||||
|
GetBlockTemplate(function(error, result){
|
||||||
|
if (error){
|
||||||
|
console.log('Error getting block template for ' + coin.options.name);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_this.jobManager.newTemplate(result, publicKeyBuffer);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
pool.prototype.__proto__ = events.EventEmitter.prototype;
|
pool.prototype.__proto__ = events.EventEmitter.prototype;
|
||||||
Loading…
Reference in New Issue
Block a user