Merge pull request #155 from cubedro/develop
Pending as a separate call
This commit is contained in:
		
						commit
						6a62a254f0
					
				
							
								
								
									
										81
									
								
								lib/node.js
									
									
									
									
									
								
							
							
						
						
									
										81
									
								
								lib/node.js
									
									
									
									
									
								
							@ -489,6 +489,39 @@ 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, 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 = pending;
 | 
			
		||||
 | 
			
		||||
			self.sendPendingUpdate();
 | 
			
		||||
		});
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Node.prototype.getHistory = function (range)
 | 
			
		||||
{
 | 
			
		||||
	var self = this;
 | 
			
		||||
@ -549,6 +582,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 +626,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();
 | 
			
		||||
@ -617,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);
 | 
			
		||||
			}
 | 
			
		||||
		});
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user