Merge pull request #91 from cubedro/develop

Version 0.0.6
This commit is contained in:
Marian OANCΞA 2015-04-28 10:45:12 +03:00
commit b2146c5b71
2 changed files with 39 additions and 5 deletions

View File

@ -44,6 +44,7 @@ var MAX_BLOCKS_HISTORY = 40;
var UPDATE_INTERVAL = 5000; var UPDATE_INTERVAL = 5000;
var PING_INTERVAL = 2000; var PING_INTERVAL = 2000;
var MINERS_LIMIT = 5; var MINERS_LIMIT = 5;
var MAX_HISTORY_UPDATE = 100;
function Node() function Node()
{ {
@ -71,6 +72,7 @@ function Node()
os: os.platform(), os: os.platform(),
os_v: os.release(), os_v: os.release(),
client: pjson.version, client: pjson.version,
canUpdateHistory: true,
coinbase: COINBASE coinbase: COINBASE
}; };
@ -137,14 +139,21 @@ function Node()
}) })
.on('data', function incoming(data) { .on('data', function incoming(data) {
console.info('Received some data', data); console.info('Received some data', data);
}); })
.on('ready', function()
socket.on('ready', function()
{ {
self._socket = true; self._socket = true;
self.sendUpdate(true); self.sendUpdate(true);
console.info('The connection has been established.'); console.info('The connection has been established.');
})
.on('history', function(data)
{
console.info('Getting history.');
var reqHistory = self.getHistory(data);
console.info('Sending history.');
socket.emit('history', {id: self.id, history: reqHistory});
}); });
this.init(); this.init();
@ -426,6 +435,31 @@ Node.prototype.getStats = function()
this.uptime(); this.uptime();
} }
Node.prototype.getHistory = function(interval)
{
var history = [];
console.log('interval', interval);
if(typeof interval === 'undefined' || interval === null)
{
interval = {
min: this.stats.block.number - MAX_HISTORY_UPDATE,
max: this.stats.block.number - 1
}
}
for(var number = interval.min; number <= interval.max; number++)
{
var block = this.getBlock(number);
if(block !== null && block.number !== this.blocks[0].number)
{
history.push(block);
}
}
return history.reverse();
}
Node.prototype.changed = function() Node.prototype.changed = function()
{ {
var changed = ! _.isEqual(this._lastStats, JSON.stringify(this.stats)); var changed = ! _.isEqual(this._lastStats, JSON.stringify(this.stats));

View File

@ -1,7 +1,7 @@
{ {
"name": "eth-net-intelligence-api", "name": "eth-net-intelligence-api",
"description": "Ethereum Network Intelligence API", "description": "Ethereum Network Intelligence API",
"version": "0.0.5", "version": "0.0.6",
"private": true, "private": true,
"main": "./app.js", "main": "./app.js",
"directories": { "directories": {
@ -16,7 +16,7 @@
"primus-spark-latency": "0.1.1", "primus-spark-latency": "0.1.1",
"shelljs": "0.4.0", "shelljs": "0.4.0",
"sleep": "2.0.0", "sleep": "2.0.0",
"web3": "0.3.2", "web3": "0.3.3",
"ws": "0.7.1" "ws": "0.7.1"
}, },
"scripts": { "scripts": {