diff --git a/models/node.js b/models/node.js index 6be3a05..1d5ff65 100644 --- a/models/node.js +++ b/models/node.js @@ -15,7 +15,8 @@ var Node = function Node(options, id) mining: false, block: { height: 0, - hash: '?' + hash: '?', + timestamp: 0 } } @@ -33,10 +34,23 @@ Node.prototype.update = function() var eth = this.web3.eth; - this.info.stats.peers = eth.peerCount; - this.info.stats.mining = eth.mining; - this.info.stats.block.height = eth.number; - this.info.stats.block.hash = eth.block(this.info.stats.block.height).hash; + try { + this.info.stats.peers = parseInt(eth.peerCount); + } + catch (err) { + this.info.stats.peers = 0; + } + + if(this.info.stats.peers > 0) { + this.info.stats.block.height = eth.number; + var block = eth.block(this.info.stats.block.height) + this.info.stats.block.hash = block.hash; + this.info.stats.block.timestamp = block.timestamp; + this.info.stats.mining = eth.mining; + this.info.stats.active = true; + } else { + this.info.stats.active = false; + } return this.info; };