added block check

This commit is contained in:
cubedro 2015-04-16 23:45:23 +03:00
parent 9ed6bfe0f0
commit cce918ba95

View File

@ -196,6 +196,8 @@ Node.prototype.getBlock = function(number)
} }
catch (err) { catch (err) {
console.error("getBlock(" + number + "):", err); console.error("getBlock(" + number + "):", err);
return false;
} }
return block; return block;
@ -354,23 +356,26 @@ Node.prototype.getStats = function()
if(this.isActive()) if(this.isActive())
{ {
this.stats.block = this.getBlock(); var block = this.getBlock();
// Get last MAX_BLOCKS_HISTORY blocks for calculations if(block) {
if(this.stats.block.number > 0) this.stats.block = block;
this.getLatestBlocks(); // Get last MAX_BLOCKS_HISTORY blocks for calculations
if(this.stats.block.number > 0)
this.getLatestBlocks();
if(PENDING_WORKS) { if(PENDING_WORKS) {
try { try {
this.stats.pending = web3.eth.getBlockTransactionCount('pending'); this.stats.pending = web3.eth.getBlockTransactionCount('pending');
} catch (err) { } catch (err) {
PENDING_WORKS = false; PENDING_WORKS = false;
console.error("getBlockTransactionCount('pending'):", err); console.error("getBlockTransactionCount('pending'):", err);
}
} }
}
this.stats.mining = web3.eth.mining; this.stats.mining = web3.eth.mining;
this.stats.gasPrice = web3.toBigNumber(web3.eth.gasPrice).toString(10); this.stats.gasPrice = web3.toBigNumber(web3.eth.gasPrice).toString(10);
}
} }
this.uptime(); this.uptime();