added get stats as separate method

This commit is contained in:
cubedro 2015-06-01 23:50:26 +03:00
parent 0478c8193e
commit c74b72b6eb
1 changed files with 22 additions and 34 deletions

View File

@ -88,7 +88,6 @@ function Node ()
transactions: [],
uncles: []
},
miners: [],
uptime: 0
};
@ -476,7 +475,7 @@ Node.prototype.getStats = function(forced)
self.setUptime();
self.sendUpdate(forced);
self.sendStatsUpdate(forced);
});
}
}
@ -562,14 +561,6 @@ Node.prototype.changed = function ()
return changed;
}
Node.prototype.prepareStats = function ()
{
return {
id: this.id,
stats: this.stats
};
}
Node.prototype.prepareBlock = function ()
{
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 ()
{
return {
@ -604,12 +579,19 @@ Node.prototype.preparePending = function ()
};
}
Node.prototype.sendUpdate = function (force)
Node.prototype.prepareStats = function ()
{
if( this.changed() || force ) {
console.info("wsc", "Sending", chalk.reset.blue((force ? "forced" : "changed")), chalk.bold.white("update"));
this.emit('update', this.prepareStats());
}
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,
uptime: this.stats.uptime
}
};
}
Node.prototype.sendBlockUpdate = function()
@ -620,9 +602,15 @@ Node.prototype.sendBlockUpdate = function()
Node.prototype.sendPendingUpdate = function()
{
if( this.changed() ) {
console.info("wsc", "Sending pending update");
this.emit('pending', this.preparePending());
console.info("wsc", "Sending pending update");
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());
}
}