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();