From fe221801a593f02407167bcb230ea70702a44a93 Mon Sep 17 00:00:00 2001 From: cubedro Date: Mon, 1 Jun 2015 21:00:14 +0300 Subject: [PATCH 1/2] sending specific stats to server --- lib/node.js | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/lib/node.js b/lib/node.js index bca49a4..36792be 100644 --- a/lib/node.js +++ b/lib/node.js @@ -489,6 +489,37 @@ Node.prototype.getStats = function(forced) } } +Node.prototype.getPending = function() +{ + var self = this; + var now = _.now(); + + if (this._socket) + this._lastStats = JSON.stringify(this.stats); + + if (this._web3) + { + console.info('==>', 'Getting Pending') + + web3.eth.getBlockTransactionCount('pending', function (err, results) + { + if (err) { + console.error('xx>', 'getPending error: ', err); + return false; + } + + results.end = _.now(); + results.diff = results.end - now; + + console.success('==>', 'Got getPending results in', chalk.reset.cyan(results.diff, 'ms')); + + self.stats.pending = results.pending; + + self.sendPendingUpdate(); + }); + } +} + Node.prototype.getHistory = function (range) { var self = this; @@ -549,6 +580,42 @@ Node.prototype.prepareStats = function () }; } +Node.prototype.prepareBlock = function () +{ + return { + id: this.id, + block: this.stats.block + }; +} + +Node.prototype.prepareBasic = function () +{ + return { + id: this.id, + stats: { + active: this.stats.active, + listening: this.stats.listening, + mining: this.stats.mining, + hashrate: this.stats.hashrate, + peers: this.stats.peers, + pending: this.stats.pending, + gasPrice: this.stats.gasPrice, + miners: this.stats.miners, + uptime: this.stats.uptime + } + }; +} + +Node.prototype.preparePending = function () +{ + return { + id: this.id, + stats: { + pending: this.stats.pending + } + }; +} + Node.prototype.sendUpdate = function (force) { if( this.changed() || force ) { @@ -557,6 +624,14 @@ Node.prototype.sendUpdate = function (force) } } +Node.prototype.sendPendingUpdate = function() +{ + if( this.changed() ) { + console.info("wsc", "Sending pending update"); + this.emit('pending', this.preparePending()); + } +} + Node.prototype.ping = function() { this._latency = _.now(); From 781c839dd49d120531fdf492ce411da72e8090b4 Mon Sep 17 00:00:00 2001 From: cubedro Date: Mon, 1 Jun 2015 21:43:19 +0300 Subject: [PATCH 2/2] changed to pending tx as a separate call --- lib/node.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/node.js b/lib/node.js index 36792be..b0dbb89 100644 --- a/lib/node.js +++ b/lib/node.js @@ -501,19 +501,21 @@ Node.prototype.getPending = function() { console.info('==>', 'Getting Pending') - web3.eth.getBlockTransactionCount('pending', function (err, results) + web3.eth.getBlockTransactionCount('pending', function (err, pending) { if (err) { console.error('xx>', 'getPending error: ', err); return false; } + var results = {}; results.end = _.now(); results.diff = results.end - now; console.success('==>', 'Got getPending results in', chalk.reset.cyan(results.diff, 'ms')); + console.log(pending); - self.stats.pending = results.pending; + self.stats.pending = pending; self.sendPendingUpdate(); }); @@ -692,12 +694,12 @@ Node.prototype.setWatches = function() if(time > 50) { - self.getStats(true); + self.getPending(true); } else { debounce(function() { - self.getStats(true); + self.getPending(true); }, 50); } });