code cleanup Added jobManager.blockHashHex which should generate the expected block hash but it seems to not work properly Moved check for the share difficulty after the block check since it's useless to make the check there. Changed emit event from client to client.connected and added client.disconnected Changed share emit data. Now we pass the client instance to everyone listening to the share event. Added mining.get_transaction to the handled events of stratumclient. It looks like bfgminer uses this. changed StratumClient.sendDifficulty to StratumCLient.sendAndSetDifficulty which will also perform a check on the given difficulty and broadcasts the sendDifficulty message to the client Only if the new difficulty is different from the previous one. Code cleanup and comments
41 lines
979 B
JavaScript
41 lines
979 B
JavaScript
var events = require('events');
|
|
|
|
/**
|
|
* This ShareManager Events table: will emit the following events:
|
|
*
|
|
* LISTENS on:
|
|
* - pool('share')
|
|
**/
|
|
|
|
var ShareManager = exports.ShareManager = function(pool) {
|
|
pool.on('share', function(isValid, data) {
|
|
if (isValid) {
|
|
handleValidShare(
|
|
data.client,
|
|
data.blockHeaderHex,
|
|
data.jobId,
|
|
data.extraNonce1,
|
|
data.extraNonce2,
|
|
data.nTime,
|
|
data.nonce);
|
|
} else {
|
|
handleInvalidShare(
|
|
data.client,
|
|
data.error[0],
|
|
data.error[1]);
|
|
}
|
|
});
|
|
|
|
function handleValidShare(client, headerHex, jobId, extraNonce1, extraNonce2, nTime, nonce) {
|
|
console.log("A new Valid share from "+client.workerName+" has arrived! - "+headerHex);
|
|
}
|
|
|
|
function handleInvalidShare(client, errorCode, errorDescription) {
|
|
console.log("Invalid share form "+client.workerName+" ErrorCode: "+errorCode+ " ErrorDescription: "+errorDescription);
|
|
}
|
|
};
|
|
|
|
ShareManager.prototype.__proto__ = events.EventEmitter.prototype;
|
|
|
|
|