diff --git a/debug_scripts/socket_io.html b/debug_scripts/socket_io.html
index 28879e8..bce2a71 100644
--- a/debug_scripts/socket_io.html
+++ b/debug_scripts/socket_io.html
@@ -11,8 +11,8 @@
socket.emit('room', "pool_stats");
socket.emit('room', "pool_stats_pplns");
socket.emit('room', "pool_stats_solo");
- socket.emit('room', "network_block_info");
- socket.emit('room', "address_stats_46XWBqE1iwsVxSDP1qDrxhE1XvsZV6eALG5LwnoMdjbT4GPdy2bZTb99kagzxp2MMjUamTYZ4WgvZdFadvMimTjvR6Gv8hL")
+ socket.emit('room', "block_update");
+ socket.emit('room', "address_stats_46XWBqE1iwsVxSDP1qDrxhE1XvsZV6eALG5LwnoMdjbT4GPdy2bZTb99kagzxp2MMjUamTYZ4WgvZdFadvMimTjvR6Gv8hL");
});
socket.on('message', function(data) {
diff --git a/lib/api.js b/lib/api.js
index 3e2aec9..164852e 100644
--- a/lib/api.js
+++ b/lib/api.js
@@ -105,14 +105,20 @@ sock.on('message', function(topic, message) {
case 'miner_hash_graph':
message = JSON.parse(message);
message.forEach(function(address){
- io.sockets.in('hash_chart_'+address).emit('message', JSON.stringify(getAllWorkerHashCharts(address)));
+ getAllWorkerHashCharts(address, function(err, data){
+ return io.sockets.in('hash_chart_'+address).emit('message', JSON.stringify(data));
+ });
});
break;
case 'miner_hash_stats':
message = JSON.parse(message);
message.forEach(function(address){
- io.sockets.in('address_stats_'+address).emit('message', JSON.stringify(getAddressStats(address)));
- io.sockets.in('worker_stats_'+address).emit('message', JSON.stringify(getAllWorkerStats(address)));
+ getAddressStats(address, function(err,data){
+ io.sockets.in('address_stats_'+address).emit('message', JSON.stringify(data));
+ });
+ getAllWorkerStats(address, function(err, data){
+ io.sockets.in('worker_stats_'+address).emit('message', JSON.stringify(data));
+ });
io.sockets.in('worker_ids_'+address).emit('message', JSON.stringify(global.database.getCache(address + '_identifiers')));
});
break;
@@ -155,7 +161,7 @@ sock.on('message', function(topic, message) {
});
// Support Functions that are reused now
-function getAllWorkerHashCharts(address){
+function getAllWorkerHashCharts(address, callback){
let identifiers = global.database.getCache(address + '_identifiers');
let returnData = {global: global.database.getCache(address)['hashHistory']};
if (identifiers !== false){
@@ -168,12 +174,12 @@ function getAllWorkerHashCharts(address){
returnData[identifier] = global.database.getCache(address+"_"+identifier)['hashHistory'];
intCounter += 1;
if (intCounter === identifiers.length){
- return returnData;
+ return callback(null, returnData);
}
});
}
-function getAllWorkerStats(address){
+function getAllWorkerStats(address, callback){
let identifiers = global.database.getCache(address + '_identifiers');
let globalCache = global.database.getCache(address);
let returnData = {global: {
@@ -184,7 +190,7 @@ function getAllWorkerStats(address){
}};
let intCounter = 0;
if (identifiers === false){
- return returnData;
+ return callback(null, returnData);
}
identifiers.sort().forEach(function(identifier){
let cachedData = global.database.getCache(address+"_"+identifier);
@@ -196,12 +202,12 @@ function getAllWorkerStats(address){
};
intCounter += 1;
if (intCounter === identifiers.length){
- return returnData;
+ return callback(null, returnData);
}
});
}
-function getAddressStats(address){
+function getAddressStats(address, extCallback){
let address_parts = address.split('.');
let address_pt = address_parts[0];
let payment_id = address_parts[1];
@@ -265,11 +271,11 @@ function getAddressStats(address){
], function (err, result) {
debug(threadName + "Result information for " + address + ": " + JSON.stringify(result));
if (err === true) {
- return result;
+ return extCallback(null, result);
}
if (err) {
console.error(threadName + "Error within the miner stats identifier func");
- return {'error': err.toString()};
+ return extCallback(err.toString());
}
});
}
@@ -537,7 +543,9 @@ app.get('/miner/:address/payments', function (req, res) {
});
app.get('/miner/:address/stats/allWorkers', function (req, res) {
- return res.json(getAllWorkerStats(req.params.address));
+ getAllWorkerStats(req.params.address, function(err, data){
+ return res.json(data);
+ });
});
app.get('/miner/:address/stats/:identifier', function (req, res) {
@@ -565,7 +573,9 @@ app.get('/miner/:address/chart/hashrate', function (req, res) {
});
app.get('/miner/:address/chart/hashrate/allWorkers', function (req, res) {
- return res.json(getAllWorkerHashCharts(req.params.address));
+ getAllWorkerHashCharts(req.params.address, function(err, data){
+ return res.json(data);
+ });
});
app.get('/miner/:address/chart/hashrate/:identifier', function (req, res) {
@@ -573,7 +583,9 @@ app.get('/miner/:address/chart/hashrate/:identifier', function (req, res) {
});
app.get('/miner/:address/stats', function (req, res) {
- return res.json(getAddressStats(req.params.address));
+ getAddressStats(req.params.address, function(err, data){
+ return res.json(data);
+ });
});
// Authentication
diff --git a/lib/worker.js b/lib/worker.js
index 71430f8..f8c0486 100644
--- a/lib/worker.js
+++ b/lib/worker.js
@@ -8,6 +8,7 @@ const sock = zmq.socket('pub');
let threadName = "Worker Server ";
let cycleCount = 0;
sock.bindSync('tcp://127.0.0.1:3000');
+let lastBlockHash = null;
function updateShareStats() {
// This is an omni-worker to deal with all things share-stats related
@@ -432,7 +433,8 @@ function updatePoolInformation() {
function updateBlockHeader() {
global.support.rpcDaemon('getlastblockheader', [], function (body) {
- if (body.result) {
+ if (body.result && body.result.block_header.hash !== lastBlockHash) {
+ lastBlockHash = body.result.block_header.hash;
global.database.setCache('networkBlockInfo', {
difficulty: body.result.block_header.difficulty,
hash: body.result.block_header.hash,