Merge pull request #76 from cubedro/develop

Added block check
This commit is contained in:
Marian OANCΞA 2015-04-16 23:46:44 +03:00
commit c27e1cb76a
1 changed files with 20 additions and 13 deletions

View File

@ -196,6 +196,8 @@ Node.prototype.getBlock = function(number)
}
catch (err) {
console.error("getBlock(" + number + "):", err);
return false;
}
return block;
@ -354,23 +356,28 @@ 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);
} else {
console.error("getStats: couldn't fetch block...");
}
}
this.uptime();