Moved blocknotify related code out of this repo into the portal repo where it is more appropriately used
This commit is contained in:
parent
16008d8559
commit
06e882d80e
35
README.md
35
README.md
@ -42,9 +42,8 @@ Features
|
||||
|
||||
#### Under development
|
||||
* Skein (Skeincoin) algorithm
|
||||
* Max (Maxcoin) algorithm
|
||||
* Keccak (Maxcoin) algorithm
|
||||
* P2P functionality for highly efficient block updates from daemon as a peer node
|
||||
* Clustering to take advantage of multiple CPU cores
|
||||
|
||||
#### To do
|
||||
* Statistics module
|
||||
@ -146,18 +145,18 @@ var pool = stratum.createPool({
|
||||
host: "localhost",
|
||||
port: 19333,
|
||||
|
||||
/* Found in src as the PROTOCOL_VERSION variable, for example:
|
||||
https://github.com/litecoin-project/litecoin/blob/85f303d883ffff35238eaea5174b780c950c0ae4/src/version.h#L28
|
||||
*/
|
||||
protocolVersion: 70002,
|
||||
|
||||
/* Magic value is different for main/testnet and for each coin. It is found in the daemon
|
||||
source code as the pchMessageStart variable. For example, litecoin mainnet:
|
||||
http://github.com/litecoin-project/litecoin/blob/85f303d883ffff35238eaea5174b780c950c0ae4/src/main.cpp#L3059
|
||||
And for litecoin testnet:
|
||||
http://github.com/litecoin-project/litecoin/blob/85f303d883ffff35238eaea5174b780c950c0ae4/src/main.cpp#L2722-L2725
|
||||
*/
|
||||
magic: "fcc1b7dc"
|
||||
magic: "fcc1b7dc",
|
||||
|
||||
/* Found in src as the PROTOCOL_VERSION variable, for example:
|
||||
https://github.com/litecoin-project/litecoin/blob/85f303d883ffff35238eaea5174b780c950c0ae4/src/version.h#L28
|
||||
*/
|
||||
protocolVersion: 70002
|
||||
}
|
||||
|
||||
}, function(ip, workerName, password, callback){ //stratum authorization function
|
||||
@ -217,26 +216,6 @@ pool.start();
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
#### [Optional, recommended] Setting up blocknotify
|
||||
* For stratum initialization options set `blockNotifyListener.enabled` to true
|
||||
* Set the `blockNotifyListener.port` and `blockNotifyListener.password`
|
||||
* For the blocknotify arguments in your daemon startup parameters or conf file, use:
|
||||
|
||||
```
|
||||
[path to blockNotify.js]
|
||||
[pool host]:[pool blockNotifyListener port]
|
||||
[blockNotifyListener password]
|
||||
[coin symbol set in coin's json config]
|
||||
%s"
|
||||
```
|
||||
|
||||
* Example: `dogecoind -blocknotify="scripts/blockNotify.js localhost:8117 mySuperSecurePassword doge %s"`
|
||||
* If your daemon is on a different host you will have to copy over `scripts/blockNotify.js`
|
||||
|
||||
|
||||
|
||||
Credits
|
||||
-------
|
||||
* [vekexasia](https://github.com/vekexasia) - co-developer & great tester
|
||||
|
||||
46
lib/index.js
46
lib/index.js
@ -9,52 +9,6 @@ var index = module.exports = function index(options){
|
||||
var _this = this;
|
||||
this.pools = [];
|
||||
|
||||
var emitLog = function(text){
|
||||
_this.emit('log', text);
|
||||
};
|
||||
|
||||
if (options.blockNotifyListener.enabled){
|
||||
SetupBlockListener();
|
||||
}
|
||||
|
||||
|
||||
function SetupBlockListener(){
|
||||
console.log("Block listener is enabled, starting server on port " + options.blockNotifyListener.port);
|
||||
var blockNotifyServer = net.createServer(function(c) {
|
||||
emitLog('Block listener has incoming connection');
|
||||
var data = '';
|
||||
c.on('data', function(d){
|
||||
emitLog('Block listener received blocknotify data');
|
||||
data += d;
|
||||
if (data.slice(-1) === '\n'){
|
||||
c.end();
|
||||
}
|
||||
});
|
||||
c.on('end', function() {
|
||||
|
||||
emitLog('Block listener connection ended');
|
||||
|
||||
var message = JSON.parse(data);
|
||||
if (message.password === options.blockNotifyListener.password){
|
||||
|
||||
for (var i = 0; i < this.pools.length; i++){
|
||||
if (this.pools[i].options.coin.symbol === message.coin){
|
||||
this.pools[i].processBlockNotify(message.blockHash)
|
||||
return;
|
||||
}
|
||||
}
|
||||
emitLog('Block listener could not find pool to notify');
|
||||
}
|
||||
else
|
||||
emitLog('Block listener received notification with incorrect password');
|
||||
|
||||
});
|
||||
});
|
||||
blockNotifyServer.listen(options.blockNotifyListener.port, function() {
|
||||
emitLog('Block notify listener server started on port ' + options.blockNotifyListener.port)
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
this.createPool = function(poolOptions, authorizeFn){
|
||||
var newPool = new pool(poolOptions, authorizeFn);
|
||||
|
||||
@ -448,4 +448,5 @@ var pool = module.exports = function pool(options, authorizeFn){
|
||||
}
|
||||
|
||||
};
|
||||
pool.prototype.__proto__ = events.EventEmitter.prototype;
|
||||
pool.prototype.__proto__ = events.EventEmitter.prototype;
|
||||
pool.daemon = daemon;
|
||||
@ -1,38 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
/**
|
||||
* This script should be hooked to the coin daemon as follow:
|
||||
*
|
||||
* litecoind -blocknotify="/path/to/this/script/blockNotify.js localhost:8117 password litecoin %s"
|
||||
*
|
||||
* The above will send tell litecoin to launch this script with those parameters every time
|
||||
* a block is found.
|
||||
* This script will then send the blockhash along with other informations to a listening tcp socket
|
||||
**/
|
||||
|
||||
var net = require('net');
|
||||
var config = process.argv[1];
|
||||
var parts = config.split(':');
|
||||
var host = parts[0];
|
||||
var port = parts[1];
|
||||
var password = process.argv[2];
|
||||
var coin = process.argv[3];
|
||||
var blockHash = process.argv[4];
|
||||
|
||||
var client = net.connect(port, host, function() {
|
||||
console.log('client connected');
|
||||
client.write(JSON.stringify({
|
||||
password: password,
|
||||
coin: coin,
|
||||
blockHash: blockHash
|
||||
}) + '\n');
|
||||
});
|
||||
|
||||
client.on('data', function(data) {
|
||||
console.log(data.toString());
|
||||
//client.end();
|
||||
});
|
||||
|
||||
client.on('end', function() {
|
||||
console.log('client disconnected');
|
||||
//process.exit();
|
||||
});
|
||||
Loading…
Reference in New Issue
Block a user