Skip to content

Commit 2fe7b24

Browse files
use arrow functions
1 parent f156693 commit 2fe7b24

File tree

3 files changed

+31
-35
lines changed

3 files changed

+31
-35
lines changed

index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,20 @@ async function init() {
5656

5757
// wait for shares from the miner and send them up to the pool. use the
5858
// callback to notify the miner if share was accepted.
59-
rpcServer.on('submitShare', async function(args, callback) {
59+
rpcServer.on('submitShare', async (args, callback) => {
6060
var res = await stratumClient.submitShare(args);
6161
callback(res);
6262
rejected = res ? rejected : rejected + 1;
6363
process.stdout.write('Total shares: ' + shareCount++ + ', Rejected: ' + rejected + "\r");
6464
});
6565

6666
// if we get disconnected from the pool, try to reconnect
67-
stratumClient.on('disconnect', function() {
67+
stratumClient.on('disconnect', () => {
6868
rpcServer.removeAllListeners('submitShare');
6969
LogB('Connection closed. Reconnecting in 5 seconds ...');
7070
setTimeout(init, 5000);
7171

72-
}).on('workPackage', function(params) {
72+
}).on('workPackage', (params) => {
7373
// listen for work packages from the stratum pool and make them available to the rpc server
7474
rpcServer.setWork(params);
7575
});

lib/rpc.js

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ module.exports = class RPCServer extends EventEmitter {
1111

1212
constructor (config) {
1313
super();
14-
var _this = this;
1514

1615
this.minerEthAddress = config.Miner.EthAddress.toLowerCase();
1716
this.mintingAccount = "";
@@ -22,38 +21,38 @@ module.exports = class RPCServer extends EventEmitter {
2221
// create an rpc server
2322
var server = jayson.server({
2423

25-
getPoolEthAddress: function(args, callback) {
24+
getPoolEthAddress: (args, callback) => {
2625
// LogB('getPoolEthAddress: ', args);
27-
callback(null, _this.mintingAccount);
26+
callback(null, this.mintingAccount);
2827
},
2928

30-
getMinimumShareDifficulty: async function(args, callback) {
29+
getMinimumShareDifficulty: async (args, callback) => {
3130
// LogB('getMinimumShareDifficulty: ', args);
32-
if (args[0].toLowerCase() != _this.minerEthAddress) {
33-
callback({code: -1, message: 'Invalid minerEthAddresss ' + args[0] + '. Expecting ' + _this.minerEthAddress});
31+
if (args[0].toLowerCase() != this.minerEthAddress) {
32+
callback({code: -1, message: 'Invalid minerEthAddresss ' + args[0] + '. Expecting ' + this.minerEthAddress});
3433
}
35-
callback(null, _this.minerVarDiff);
34+
callback(null, this.minerVarDiff);
3635
},
3736

38-
getMinimumShareTarget: async function(args, callback) {
37+
getMinimumShareTarget: async (args, callback) => {
3938
// LogB('getMinimumShareTarget: ', args);
40-
if (args[0].toLowerCase() != _this.minerEthAddress) {
41-
callback({code: -1, message: 'Invalid minerEthAddresss ' + args[0] + '. Expecting ' + _this.minerEthAddress});
39+
if (args[0].toLowerCase() != this.minerEthAddress) {
40+
callback({code: -1, message: 'Invalid minerEthAddresss ' + args[0] + '. Expecting ' + this.minerEthAddress});
4241
}
43-
callback(null, _this.minimumShareTarget);
42+
callback(null, this.minimumShareTarget);
4443
},
4544

46-
getChallengeNumber: async function(args, callback) {
45+
getChallengeNumber: async (args, callback) => {
4746
// LogB('getChallengeNumber: ', args);
48-
callback(null, _this.challengeNumber);
47+
callback(null, this.challengeNumber);
4948
},
5049

51-
submitShare: async function(args, callback) {
50+
submitShare: async (args, callback) => {
5251
// LogB('submitShare: ', args);
5352

5453
// notify interested listeners of a share submit. provide a callback so we can be
5554
// notified if share was accepted (true/false).
56-
_this.emit('submitShare', args, (res) => {
55+
this.emit('submitShare', args, (res) => {
5756
callback(null, res);
5857
})
5958
},

lib/stratum.js

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ module.exports = class StratumClient extends EventEmitter {
2323
}
2424

2525
connectToPool() {
26-
var _this = this;
2726

2827
this.subscribed = false;
2928
this.submitShareResponse = null;
@@ -33,25 +32,25 @@ module.exports = class StratumClient extends EventEmitter {
3332
this.client.setEncoding('utf8');
3433
this.client.setKeepAlive(true);
3534

36-
this.client.on('connect', function() {
37-
LogB('Stratum proxy connected to ' + _this.config.Stratum.Host + ':' + _this.config.Stratum.Port);
35+
this.client.on('connect', () => {
36+
LogB('Stratum proxy connected to ' + this.config.Stratum.Host + ':' + this.config.Stratum.Port);
3837
// subscribe to work notifications
3938
var msg = {
4039
id : 1,
4140
method : 'mining.subscribe',
42-
params : [_this.minerAccount, 'Stratum Proxy v' + global.VERSION]
41+
params : [this.minerAccount, 'Stratum Proxy v' + global.VERSION]
4342
};
44-
LogD('subscribing to pool with account', _this.minerAccount);
45-
_this.client.write(JSON.stringify(msg) + '\n');
43+
LogD('subscribing to pool with account', this.minerAccount);
44+
this.client.write(JSON.stringify(msg) + '\n');
4645

47-
}).on('data', function(data) {
48-
_this.handleData(data);
46+
}).on('data', (data) => {
47+
this.handleData(data);
4948

50-
}).on('close', function() {
51-
_this.subscribed = false;
52-
_this.emit('disconnect');
49+
}).on('close', () => {
50+
this.subscribed = false;
51+
this.emit('disconnect');
5352

54-
}).on('error', function(e) {
53+
}).on('error', (e) => {
5554
if (e.code == 'ECONNREFUSED') {
5655
LogB('Socket error: unable to connect to mining pool at ', e.address + ':' + e.port, ' [ECONNREFUSED]');
5756
} else {
@@ -64,21 +63,19 @@ module.exports = class StratumClient extends EventEmitter {
6463
}
6564

6665
handleData(data) {
67-
var _this = this;
68-
6966
this.dataBuffer += data;
7067
if (this.dataBuffer.indexOf('\n') !== -1) {
7168
var messages = this.dataBuffer.split('\n');
7269
var incomplete = this.dataBuffer.slice(-1) === '\n' ? '' : messages.pop();
73-
messages.forEach(function(message) {
70+
messages.forEach((message) => {
7471
if (message === '') return;
75-
_this.handleMessage(message);
72+
this.handleMessage(message);
7673
});
7774
this.dataBuffer = incomplete;
7875
}
7976
}
8077

81-
handleMessage(message){
78+
handleMessage(message) {
8279
try {
8380
var jsonData = JSON.parse(message);
8481
if (jsonData.id !== undefined) {

0 commit comments

Comments
 (0)