fixed bugs
This commit is contained in:
parent
ca02d2c11b
commit
3b7c7dff29
@ -46,5 +46,6 @@ BTC: 1KRotMnQpxu3sePQnsVLRy3EraRFYfJQFR
|
|||||||
|
|
||||||
License
|
License
|
||||||
-------
|
-------
|
||||||
node-stratum is released under the GNU General Public License v2
|
Released under the GNU General Public License v2
|
||||||
|
|
||||||
http://www.gnu.org/licenses/gpl-2.0.html
|
http://www.gnu.org/licenses/gpl-2.0.html
|
||||||
|
|||||||
42
daemon.js
42
daemon.js
@ -10,6 +10,7 @@ function DaemonInterface(options){
|
|||||||
|
|
||||||
//private members
|
//private members
|
||||||
var _this = this;
|
var _this = this;
|
||||||
|
this.options = options;
|
||||||
|
|
||||||
(function init(){
|
(function init(){
|
||||||
isOnline(function(online){
|
isOnline(function(online){
|
||||||
@ -38,7 +39,7 @@ function DaemonInterface(options){
|
|||||||
}
|
}
|
||||||
|
|
||||||
function isOnline(callback){
|
function isOnline(callback){
|
||||||
this.cmd('getinfo', [], function(error, result){
|
cmd('getinfo', [], function(error, result){
|
||||||
if (error)
|
if (error)
|
||||||
callback(false);
|
callback(false);
|
||||||
else
|
else
|
||||||
@ -46,24 +47,7 @@ function DaemonInterface(options){
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function cmd(method, params, callback){
|
||||||
//public members
|
|
||||||
|
|
||||||
this.isOnline = isOnline;
|
|
||||||
|
|
||||||
this.start = function(){
|
|
||||||
var cmdArgs = [
|
|
||||||
'-rpcport=' + this.options.port,
|
|
||||||
'-rpcuser=' + this.options.user,
|
|
||||||
'-rpcpassword=' + this.options.password,
|
|
||||||
'-blocknotify=' + this.options.blocknotify
|
|
||||||
];
|
|
||||||
var child = cp.spawn(this.options.bin, cmdArgs, { detached: true, stdio: [ 'ignore', 'ignore', 'ignore' ] });
|
|
||||||
child.unref();
|
|
||||||
console.log('started daemon');
|
|
||||||
};
|
|
||||||
|
|
||||||
this.cmd = function(method, params, callback){
|
|
||||||
|
|
||||||
var requestJson = JSON.stringify({
|
var requestJson = JSON.stringify({
|
||||||
id: Date.now() + Math.floor(Math.random() * 10),
|
id: Date.now() + Math.floor(Math.random() * 10),
|
||||||
@ -73,9 +57,9 @@ function DaemonInterface(options){
|
|||||||
|
|
||||||
var options = {
|
var options = {
|
||||||
hostname: 'localhost',
|
hostname: 'localhost',
|
||||||
port: this.options.port,
|
port: _this.options.port,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
auth: this.options.user + ':' + this.options.password,
|
auth: _this.options.user + ':' + _this.options.password,
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Length': requestJson.length
|
'Content-Length': requestJson.length
|
||||||
}
|
}
|
||||||
@ -103,6 +87,22 @@ function DaemonInterface(options){
|
|||||||
req.end(requestJson);
|
req.end(requestJson);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//public members
|
||||||
|
|
||||||
|
this.isOnline = isOnline;
|
||||||
|
this.cmd = cmd;
|
||||||
|
this.start = function(){
|
||||||
|
var cmdArgs = [
|
||||||
|
'-rpcport=' + _this.options.port,
|
||||||
|
'-rpcuser=' + _this.options.user,
|
||||||
|
'-rpcpassword=' + _this.options.password,
|
||||||
|
'-blocknotify=' + _this.options.blocknotify
|
||||||
|
];
|
||||||
|
var child = cp.spawn(_this.options.bin, cmdArgs, { detached: true, stdio: [ 'ignore', 'ignore', 'ignore' ] });
|
||||||
|
child.unref();
|
||||||
|
console.log('started daemon');
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
DaemonInterface.prototype.__proto__ = events.EventEmitter.prototype;
|
DaemonInterface.prototype.__proto__ = events.EventEmitter.prototype;
|
||||||
|
|||||||
48
pool.js
48
pool.js
@ -1,4 +1,5 @@
|
|||||||
var net = require('net');
|
var net = require('net');
|
||||||
|
var events = require('events');
|
||||||
|
|
||||||
var bignum = require('bignum');
|
var bignum = require('bignum');
|
||||||
|
|
||||||
@ -10,47 +11,50 @@ var coinbase = require('./coinbase.js');
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
exports.pool = function pool(coin){
|
var pool = module.exports = function pool(coin){
|
||||||
|
|
||||||
coin.jobManager = new jobManager({
|
var _this = this;
|
||||||
|
|
||||||
|
this.jobManager = new jobManager({
|
||||||
algorithm: coin.options.algorithm,
|
algorithm: coin.options.algorithm,
|
||||||
address: coin.options.address
|
address: coin.options.address
|
||||||
});
|
});
|
||||||
coin.jobManager.on('newBlock', function(blockTemplate){
|
this.jobManager.on('newBlock', function(blockTemplate){
|
||||||
coin.stratumServer.broadcastMiningJobs(blockTemplate.getJobParams());
|
_this.stratumServer.broadcastMiningJobs(blockTemplate.getJobParams());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
coin.daemon = new daemon.interface(coin.options.daemon);
|
this.daemon = new daemon.interface(coin.options.daemon);
|
||||||
coin.daemon.on('online', function(){
|
this.daemon.on('online', function(){
|
||||||
coin.daemon.cmd(
|
this.cmd(
|
||||||
'getblocktemplate',
|
'getblocktemplate',
|
||||||
[{"capabilities": [ "coinbasetxn", "workid", "coinbase/append" ]}],
|
[{"capabilities": [ "coinbasetxn", "workid", "coinbase/append" ]}],
|
||||||
function(error, response){
|
function(error, response){
|
||||||
coin.jobManager.newTemplate(response.result);
|
_this.jobManager.newTemplate(response.result);
|
||||||
console.log(coin.jobManager.currentJob.getJobParams());
|
console.log(_this.jobManager.currentJob.getJobParams());
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}).on('startFailed', function(){
|
}).on('startFailed', function(){
|
||||||
console.log('Failed to start daemon for ' + coin.name);
|
console.log('Failed to start daemon for ' + coin.name);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
coin.stratumServer = new stratum.Server({
|
this.stratumServer = new stratum.Server({
|
||||||
port: 3333
|
port: 3333
|
||||||
});
|
});
|
||||||
coin.stratumServer.on('client', function(client){
|
this.stratumServer.on('client', function(client){
|
||||||
client.on('subscription', function(params, result){
|
client.on('subscription', function(params, result){
|
||||||
var extraNonce = coin.jobManager.extraNonceCounter.next();
|
var extraNonce = _this.jobManager.extraNonceCounter.next();
|
||||||
var extraNonce2Size = coinbase.extranonce_size - coin.jobManager.extraNonceCounter.size();
|
var extraNonce2Size = coinbase.extranonce_size - _this.jobManager.extraNonceCounter.size();
|
||||||
result(extraNonce, extraNonce2Size);
|
result(extraNonce, extraNonce2Size);
|
||||||
client.sendDifficulty(1);
|
this.sendDifficulty(1);
|
||||||
client.sendMiningJob(coin.jobManager.currentJob.getJobParams());
|
this.sendMiningJob(_this.jobManager.currentJob.getJobParams());
|
||||||
}).on('authorize', function(params, result){
|
}).on('authorize', function(params, result){
|
||||||
result(true);
|
result(true);
|
||||||
}).on('submit', function(params, result){
|
}).on('submit', function(params, result){
|
||||||
|
|
||||||
result(true);
|
result(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
pool.prototype.__proto__ = events.EventEmitter.prototype;
|
||||||
12
util.js
12
util.js
@ -62,7 +62,7 @@ exports.uint256BufferFromHash = function(hex){
|
|||||||
|
|
||||||
var fromHex = new Buffer(hex, 'hex');
|
var fromHex = new Buffer(hex, 'hex');
|
||||||
|
|
||||||
if (buffer.length != 32){
|
if (fromHex.length != 32){
|
||||||
var empty = new Buffer(32);
|
var empty = new Buffer(32);
|
||||||
empty.fill(0);
|
empty.fill(0);
|
||||||
fromHex.copy(empty);
|
fromHex.copy(empty);
|
||||||
@ -77,16 +77,6 @@ exports.hexFromReversedBuffer = function(buffer){
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
exports.randomId = function(){
|
|
||||||
var text = "";
|
|
||||||
var possible = "abcdef0123456789";
|
|
||||||
|
|
||||||
for (var i = 0; i < 32; i++)
|
|
||||||
text += possible.charAt(Math.floor(Math.random() * possible.length));
|
|
||||||
|
|
||||||
return text;
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.uint256_from_compact = function(c){
|
exports.uint256_from_compact = function(c){
|
||||||
var nbytes = (c >> 24) & 0xFF;
|
var nbytes = (c >> 24) & 0xFF;
|
||||||
v = (c & 0xFFFFFF) << (8 * (nbytes - 3))
|
v = (c & 0xFFFFFF) << (8 * (nbytes - 3))
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user