From cce918ba95587a0b0d30cd208c486a0a4f7a14e7 Mon Sep 17 00:00:00 2001 From: cubedro Date: Thu, 16 Apr 2015 23:45:23 +0300 Subject: [PATCH] added block check --- lib/node.js | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/lib/node.js b/lib/node.js index 1d4c8e9..1662f73 100644 --- a/lib/node.js +++ b/lib/node.js @@ -196,6 +196,8 @@ Node.prototype.getBlock = function(number) } catch (err) { console.error("getBlock(" + number + "):", err); + + return false; } return block; @@ -354,23 +356,26 @@ Node.prototype.getStats = function() if(this.isActive()) { - this.stats.block = this.getBlock(); + var block = this.getBlock(); - // Get last MAX_BLOCKS_HISTORY blocks for calculations - if(this.stats.block.number > 0) - this.getLatestBlocks(); + if(block) { + this.stats.block = block; + // Get last MAX_BLOCKS_HISTORY blocks for calculations + if(this.stats.block.number > 0) + this.getLatestBlocks(); - if(PENDING_WORKS) { - try { - this.stats.pending = web3.eth.getBlockTransactionCount('pending'); - } catch (err) { - PENDING_WORKS = false; - console.error("getBlockTransactionCount('pending'):", err); + if(PENDING_WORKS) { + try { + this.stats.pending = web3.eth.getBlockTransactionCount('pending'); + } catch (err) { + PENDING_WORKS = false; + console.error("getBlockTransactionCount('pending'):", err); + } } - } - this.stats.mining = web3.eth.mining; - this.stats.gasPrice = web3.toBigNumber(web3.eth.gasPrice).toString(10); + this.stats.mining = web3.eth.mining; + this.stats.gasPrice = web3.toBigNumber(web3.eth.gasPrice).toString(10); + } } this.uptime();