Refactored handleAuthorize to accept a new parameter used to reply or not to the socket
This commit is contained in:
parent
89434f29dc
commit
1e3c47d527
|
@ -40,7 +40,7 @@ var StratumClient = function(options){
|
|||
handleSubscribe(message);
|
||||
break;
|
||||
case 'mining.authorize':
|
||||
handleAuthorize(message);
|
||||
handleAuthorize(message, true /*reply to socket*/);
|
||||
break;
|
||||
case 'mining.submit':
|
||||
handleSubmit(message);
|
||||
|
@ -87,17 +87,20 @@ var StratumClient = function(options){
|
|||
);
|
||||
}
|
||||
|
||||
function handleAuthorize(message){
|
||||
function handleAuthorize(message, replyToSocket){
|
||||
_this.workerIP = options.socket.address().address;
|
||||
_this.workerName = message.params[0];
|
||||
_this.workerPass = message.params[1];
|
||||
options.authorizeFn(_this.workerIP, _this.workerName, _this.workerPass, function(result) {
|
||||
_this.authorized = (!result.error && result.authorized);
|
||||
sendJson({
|
||||
id : message.id,
|
||||
result : _this.authorized,
|
||||
error : result.error
|
||||
});
|
||||
|
||||
if (replyToSocket) {
|
||||
sendJson({
|
||||
id : message.id,
|
||||
result : _this.authorized,
|
||||
error : result.error
|
||||
});
|
||||
}
|
||||
|
||||
// If the authorizer wants us to close the socket lets do it.
|
||||
if (result.disconnect === true) {
|
||||
|
@ -235,7 +238,7 @@ var StratumClient = function(options){
|
|||
};
|
||||
|
||||
this.manuallyInitClient = function (username, password) {
|
||||
handleAuthorize({id: 1, params: [username, password]});
|
||||
handleAuthorize({id: 1, params: [username, password]}, false /*do not reply to miner*/);
|
||||
handleSubscribe({id: 2});
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue