From e3210fc00b991500721c024fdb867047a48c7b0f Mon Sep 17 00:00:00 2001 From: cubedro <contact@siteshop.ro> Date: Wed, 18 Feb 2015 10:55:50 +0200 Subject: [PATCH] fixed blocktime and blocktimeAvg --- lib/node.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) 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;