Created
October 18, 2016 20:14
-
-
Save mgregoro/6887b83198b3d9e4eae9f10c806dd6fc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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