added get stats as separate method

This commit is contained in:
cubedro 2015-06-01 23:50:26 +03:00
parent 0478c8193e
commit c74b72b6eb

View File

@ -88,7 +88,6 @@ function Node ()
transactions: [], transactions: [],
uncles: [] uncles: []
}, },
miners: [],
uptime: 0 uptime: 0
}; };
@ -476,7 +475,7 @@ Node.prototype.getStats = function(forced)
self.setUptime(); self.setUptime();
self.sendUpdate(forced); self.sendStatsUpdate(forced);
}); });
} }
} }
@ -562,14 +561,6 @@ Node.prototype.changed = function ()
return changed; return changed;
} }
Node.prototype.prepareStats = function ()
{
return {
id: this.id,
stats: this.stats
};
}
Node.prototype.prepareBlock = function () Node.prototype.prepareBlock = function ()
{ {
return { return {
@ -578,22 +569,6 @@ Node.prototype.prepareBlock = function ()
}; };
} }
Node.prototype.prepareBasic = function ()
{
return {
id: this.id,
stats: {
active: this.stats.active,
mining: this.stats.mining,
hashrate: this.stats.hashrate,
peers: this.stats.peers,
gasPrice: this.stats.gasPrice,
miners: this.stats.miners,
uptime: this.stats.uptime
}
};
}
Node.prototype.preparePending = function () Node.prototype.preparePending = function ()
{ {
return { return {
@ -604,12 +579,19 @@ Node.prototype.preparePending = function ()
}; };
} }
Node.prototype.sendUpdate = function (force) Node.prototype.prepareStats = function ()
{ {
if( this.changed() || force ) { return {
console.info("wsc", "Sending", chalk.reset.blue((force ? "forced" : "changed")), chalk.bold.white("update")); id: this.id,
this.emit('update', this.prepareStats()); stats: {
active: this.stats.active,
mining: this.stats.mining,
hashrate: this.stats.hashrate,
peers: this.stats.peers,
gasPrice: this.stats.gasPrice,
uptime: this.stats.uptime
} }
};
} }
Node.prototype.sendBlockUpdate = function() Node.prototype.sendBlockUpdate = function()
@ -620,10 +602,16 @@ Node.prototype.sendBlockUpdate = function()
Node.prototype.sendPendingUpdate = function() Node.prototype.sendPendingUpdate = function()
{ {
if( this.changed() ) {
console.info("wsc", "Sending pending update"); console.info("wsc", "Sending pending update");
this.emit('pending', this.preparePending()); this.emit('pending', this.preparePending());
} }
Node.prototype.sendStatsUpdate = function (force)
{
if( this.changed() || force ) {
console.info("wsc", "Sending", chalk.reset.blue((force ? "forced" : "changed")), chalk.bold.white("update"));
this.emit('stats', this.prepareBasic());
}
} }
Node.prototype.ping = function() Node.prototype.ping = function()