Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mgregoro/6887b83198b3d9e4eae9f10c806dd6fc to your computer and use it in GitHub Desktop.
Save mgregoro/6887b83198b3d9e4eae9f10c806dd6fc to your computer and use it in GitHub Desktop.
Node.prototype.getSeemsLegitHashrate = function(callback) {
http.get("http://127.0.0.1:8081/api/stats", function (res) {
if (res.statusCode == 200) {
res.setEncoding('utf8');
var body = '';
res.on('data', function (chunk) {
body += chunk;
});
res.on('end', function () {
try {
var data = JSON.parse(body);
callback(null, data.hashrate);
} catch (e) {
console.error("JSON parse error " + e);
callback("JSON parse error " + e, 0);
}
});
// handlers installed, everyone signed, on we go!
res.resume();
} else {
console.error("Unexpected HTTP error code: " + res.status);
callback("Unexpected HTTP error code: " + res.status, 0);
}
}).on('error', function (e) {
console.error("General HTTP error: " + e);
callback("General HTTP error: " + e, 0);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment