diff --git a/lib/node.js b/lib/node.js index 58d35c2..8e53ee7 100644 --- a/lib/node.js +++ b/lib/node.js @@ -24,8 +24,7 @@ if(process.env.NODE_ENV === 'production') var socket = new Socket(process.env.WS_SERVER || 'ws://localhost:3000'); -var MAX_BLOCKS_HISTORY = 12, - LOWEST_TIMESTAMP = 0; +var MAX_BLOCKS_HISTORY = 12; function Node() { @@ -206,11 +205,10 @@ Node.prototype.getLatestBlocks = function() Node.prototype.addBlockHistory = function(block) { - if(this.blocks.length === 0 || block.number != this.blocks[0].number) + if(this.blocks.length === 0 || block.number !== this.blocks[0].number) { if(this.blocks.length === MAX_BLOCKS_HISTORY) { - LOWEST_TIMESTAMP = this.blocks[MAX_BLOCKS_HISTORY - 1].timestamp; this.blocks.pop(); } @@ -224,7 +222,7 @@ Node.prototype.calculateBlockTimes = function() var blockTimes = _.map(this.blocks, function(block, key, list) { - var diff = block.timestamp - (key < list.length - 1 ? list[key + 1].timestamp : LOWEST_TIMESTAMP); + var diff = (key > 0 ? list[key - 1].timestamp : Math.floor(Date.now()/1000)) - block.timestamp; self.blocks[key].blocktime = diff;