From c74b72b6eb47be7a363c6159c4864ef6038024fe Mon Sep 17 00:00:00 2001 From: cubedro Date: Mon, 1 Jun 2015 23:50:26 +0300 Subject: [PATCH 1/2] added get stats as separate method --- lib/node.js | 56 +++++++++++++++++++++-------------------------------- 1 file changed, 22 insertions(+), 34 deletions(-) diff --git a/lib/node.js b/lib/node.js index d21fea5..c207461 100644 --- a/lib/node.js +++ b/lib/node.js @@ -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()); } } From 1447a21c8c3079a071dbe1e697c8401ecab00fa7 Mon Sep 17 00:00:00 2001 From: cubedro Date: Tue, 2 Jun 2015 00:00:04 +0300 Subject: [PATCH 2/2] fixed prepareStats bug --- lib/node.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node.js b/lib/node.js index c207461..337f497 100644 --- a/lib/node.js +++ b/lib/node.js @@ -610,7 +610,7 @@ 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()); + this.emit('stats', this.prepareStats()); } }