Added reward to share emit (for payment processing ;) )

This commit is contained in:
Matt 2014-03-12 15:55:58 -06:00
parent 585baf7b92
commit 7cf448d1e2
3 changed files with 94 additions and 51 deletions

View File

@ -186,6 +186,7 @@ Listen to pool events
ip: '71.33.19.37', //ip address of client ip: '71.33.19.37', //ip address of client
worker: 'matt.worker1', //stratum worker name worker: 'matt.worker1', //stratum worker name
difficulty: 64, //stratum client difficulty difficulty: 64, //stratum client difficulty
reward: 5000000000, //the number of satoshis received as payment for solving this block
height: 443795, //block height height: 443795, //block height
networkDifficulty: 3349 //network difficulty for this block networkDifficulty: 3349 //network difficulty for this block

View File

@ -45,36 +45,14 @@ function DaemonInterface(options){
} }
/* Sends a JSON RPC (http://json-rpc.org/wiki/specification) command to every configured daemon. function performHttpRequest(instance, jsonData, callback){
The callback function is fired once with the result from each daemon unless streamResults is
set to true. */
function cmd(method, params, callback, streamResults){
var results = [];
async.each(instances, function(instance, eachCallback){
var itemFinished = function(error, result){
var returnObj = {error: error, response: result, instance: instance};
if (streamResults) callback(returnObj);
else results.push(returnObj);
eachCallback();
itemFinished = function(){};
};
var requestJson = JSON.stringify({
id: Date.now() + Math.floor(Math.random() * 10),
method: method,
params: params
});
var options = { var options = {
hostname: (typeof(instance.host) === 'undefined' ? 'localhost' : instance.host), hostname: (typeof(instance.host) === 'undefined' ? 'localhost' : instance.host),
port : instance.port, port : instance.port,
method : 'POST', method : 'POST',
auth : instance.user + ':' + instance.password, auth : instance.user + ':' + instance.password,
headers : { headers : {
'Content-Length': requestJson.length 'Content-Length': jsonData.length
} }
}; };
@ -83,8 +61,10 @@ function DaemonInterface(options){
res.setEncoding('utf8'); res.setEncoding('utf8');
res.on('data', function (chunk) { res.on('data', function (chunk) {
data += chunk; data += chunk;
}); });
res.on('end', function(){ res.on('end', function(){
var dataJson; var dataJson;
var parsingError; var parsingError;
try{ try{
@ -98,26 +78,86 @@ function DaemonInterface(options){
} }
else{ else{
parsingError = e; parsingError = e;
_this.emit('error', 'could not parse rpc data from method: ' + method + _this.emit('error', 'could not parse rpc data with request of: ' + jsonData +
' on instance ' + instance.index + ' data: ' + data); ' on instance ' + instance.index + ' data: ' + data);
} }
} }
if (typeof(dataJson) !== 'undefined') if (typeof(dataJson) !== 'undefined'){
itemFinished(dataJson.error, dataJson.result); callback(dataJson.error, dataJson);
}
else else
itemFinished(parsingError); callback(parsingError);
}); });
}); });
req.on('error', function(e) { req.on('error', function(e) {
if (e.code === 'ECONNREFUSED') if (e.code === 'ECONNREFUSED')
itemFinished({type: 'offline', message: e.message}, null); callback({type: 'offline', message: e.message}, null);
else else
itemFinished({type: 'request error', message: e.message}, null); callback({type: 'request error', message: e.message}, null);
});
req.end(jsonData);
};
//Performs a batch JSON-RPC command - only uses the first configured rpc daemon
/* First argument must have:
[
[ methodName, [params] ],
[ methodName, [params] ]
]
*/
function batchCmd(cmdArray, callback){
var requestJson = [];
for (var i = 0; i < cmdArray.length; i++){
requestJson.push({
method: cmdArray[i][0],
params: cmdArray[i][1],
id: Date.now() + Math.floor(Math.random() * 10) + i
});
}
var serializedRequest = JSON.stringify(requestJson);
performHttpRequest(instances[0], serializedRequest, function(error, result){
callback(error, result);
}, 'fuck');
}
/* Sends a JSON RPC (http://json-rpc.org/wiki/specification) command to every configured daemon.
The callback function is fired once with the result from each daemon unless streamResults is
set to true. */
function cmd(method, params, callback, streamResults){
var results = [];
async.each(instances, function(instance, eachCallback){
var itemFinished = function(error, result){
var returnObj = {error: error, response: result.result, instance: instance};
if (streamResults) callback(returnObj);
else results.push(returnObj);
eachCallback();
itemFinished = function(){};
};
var requestJson = JSON.stringify({
method: method,
params: params,
id: Date.now() + Math.floor(Math.random() * 10)
});
performHttpRequest(instance, requestJson, function(error, result){
itemFinished(error, result);
}); });
req.end(requestJson);
}, function(){ }, function(){
if (!streamResults){ if (!streamResults){
@ -133,6 +173,7 @@ function DaemonInterface(options){
this.init = init; this.init = init;
this.isOnline = isOnline; this.isOnline = isOnline;
this.cmd = cmd; this.cmd = cmd;
this.batchCmd = batchCmd;
} }
DaemonInterface.prototype.__proto__ = events.EventEmitter.prototype; DaemonInterface.prototype.__proto__ = events.EventEmitter.prototype;

View File

@ -270,6 +270,7 @@ var JobManager = module.exports = function JobManager(options){
worker: workerName, worker: workerName,
difficulty: difficulty, difficulty: difficulty,
height: job.rpcData.height, height: job.rpcData.height,
reward: job.rpcData.coinbasevalue,
networkDifficulty: job.difficulty, networkDifficulty: job.difficulty,
solution: blockHash solution: blockHash
}, blockHex); }, blockHex);