add size method.

This commit is contained in:
Christopher Jeffrey 2016-01-01 17:38:10 -08:00
parent 3c5a823445
commit 90856a8f5b
3 changed files with 11 additions and 4 deletions

View File

@ -601,6 +601,10 @@ Chain.prototype.getNextBlock = function getNextBlock(hash) {
return this.index.hashes[entry.index + 1] || null;
};
Chain.prototype.size = function size() {
return this.index.hashes.length;
};
Chain.prototype.toJSON = function toJSON() {
var keep = 1000;

View File

@ -431,6 +431,10 @@ Chain.prototype.getNextBlock = function getNextBlock(hash) {
return entry.next.hash;
};
Chain.prototype.size = function size() {
return this.index.entries.length;
};
Chain.prototype._save = function(entry) {
var self = this;

View File

@ -330,8 +330,7 @@ Pool.prototype._handleMerkle = function _handleMerkle(block, peer) {
Pool.prototype._handleBlock = function _handleBlock(block, peer) {
var self = this;
var chainIndex = this.chain.index;
var hash, len, orphan, err;
var hash, size, orphan, err;
if (this.listeners('watched').length > 0) {
utils.nextTick(function() {
@ -347,7 +346,7 @@ Pool.prototype._handleBlock = function _handleBlock(block, peer) {
this._response(block);
hash = block.hash('hex');
len = chainIndex.hashes.length;
size = this.chain.size();
orphan = this.chain.hasOrphan(block);
err = this.chain.add(block);
@ -363,7 +362,7 @@ Pool.prototype._handleBlock = function _handleBlock(block, peer) {
return;
}
if (chainIndex.hashes.length === len)
if (this.chain.size() === size)
return;
this.emit('chain-progress', this.chain.fillPercent(), peer);