fix locator hashes by height.

This commit is contained in:
Christopher Jeffrey 2015-12-18 17:38:59 -08:00
parent 7cabdcfda5
commit 0bd4d798a9

View File

@ -499,22 +499,26 @@ Chain.prototype.getStartHeight = function getStartHeight() {
return this.index.heights[this.index.heights.length - 1]; return this.index.heights[this.index.heights.length - 1];
}; };
Chain.prototype.locatorHashes = function(index) { Chain.prototype.locatorHashes = function(start) {
var chain = this.index.hashes; var chain = this.index.hashes;
var hashes = []; var hashes = [];
var top = chain.length - 1; var top = chain.length - 1;
var step = 1; var step = 1;
var i; var i;
if (typeof index === 'string') { if (typeof start === 'string') {
// Hash
for (i = top; i >= 0; i--) { for (i = top; i >= 0; i--) {
if (chain[i] === index) { if (chain[i] === start) {
top = i; top = i;
break; break;
} }
} }
} else if (typeof index === 'number') { } else if (typeof start === 'number') {
top = index; // Height
start = this.index.heights.indexOf(start);
if (start !== -1)
top = start;
} }
i = top; i = top;
@ -540,14 +544,14 @@ Chain.prototype.getOrphanRoot = function getOrphanRoot(hash) {
else if (hash.hash) else if (hash.hash)
hash = hash.hash('hex'); hash = hash.hash('hex');
var orphanRoot = hash; var root = hash;
while (this.orphan.bmap[hash]) { while (this.orphan.bmap[hash]) {
orphanRoot = hash; root = hash;
hash = this.orphan.bmap[hash].prevBlock; hash = this.orphan.bmap[hash].prevBlock;
} }
return orphanRoot; return root;
}; };
Chain.prototype.toJSON = function toJSON() { Chain.prototype.toJSON = function toJSON() {