more chain method improvements.
This commit is contained in:
parent
a4084d8252
commit
1be3a74c70
@ -383,7 +383,10 @@ Chain.prototype.has = function has(hash, noProbe, cb) {
|
|||||||
return cb(true);
|
return cb(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
return cb(!!this.orphan.map[hash]);
|
if (this.hasOrphan(hash))
|
||||||
|
return cb(true);
|
||||||
|
|
||||||
|
return cb(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
Chain.prototype.byHeight = function byHeight(height) {
|
Chain.prototype.byHeight = function byHeight(height) {
|
||||||
@ -480,9 +483,13 @@ Chain.prototype.get = function get(hash, force, cb) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assert(false);
|
// False positive:
|
||||||
|
// assert(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!force && this.orphan.bmap[hash])
|
||||||
|
return cb(this.orphan.bmap[hash]);
|
||||||
|
|
||||||
if (this.request.add(hash, cb))
|
if (this.request.add(hash, cb))
|
||||||
this.emit('missing', hash, null, null);
|
this.emit('missing', hash, null, null);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -249,8 +249,6 @@ Chain.prototype.add = function add(block) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Chain.prototype.has = function has(hash, noProbe, cb) {
|
Chain.prototype.has = function has(hash, noProbe, cb) {
|
||||||
var res;
|
|
||||||
|
|
||||||
if (typeof noProbe === 'function') {
|
if (typeof noProbe === 'function') {
|
||||||
cb = noProbe;
|
cb = noProbe;
|
||||||
noProbe = false;
|
noProbe = false;
|
||||||
@ -263,13 +261,11 @@ Chain.prototype.has = function has(hash, noProbe, cb) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
res = this.hasBlock(hash) || this.hasOrphan(hash);
|
|
||||||
|
|
||||||
if (!cb)
|
|
||||||
return res;
|
|
||||||
|
|
||||||
cb = utils.asyncify(cb);
|
cb = utils.asyncify(cb);
|
||||||
return cb(res);
|
|
||||||
|
assert(!noProbe);
|
||||||
|
|
||||||
|
return cb(this.hasBlock(hash) || this.hasOrphan(hash));
|
||||||
};
|
};
|
||||||
|
|
||||||
Chain.prototype.byHeight = function byHeight(height) {
|
Chain.prototype.byHeight = function byHeight(height) {
|
||||||
@ -338,22 +334,14 @@ Chain.prototype.hashesInRange = function hashesInRange(start, end, cb) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Chain.prototype.getLast = function getLast(cb) {
|
Chain.prototype.getLast = function getLast(cb) {
|
||||||
var res;
|
|
||||||
|
|
||||||
if (this.loading) {
|
if (this.loading) {
|
||||||
this.once('load', function() {
|
this.once('load', function() {
|
||||||
this.getLast(cb);
|
this.getLast(cb);
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
res = this.index.hashes[this.index.hashes.length - 1];
|
|
||||||
|
|
||||||
if (!cb)
|
|
||||||
return res;
|
|
||||||
|
|
||||||
cb = utils.asyncify(cb);
|
cb = utils.asyncify(cb);
|
||||||
return cb(res);
|
return cb(this.index.hashes[this.index.hashes.length - 1]);
|
||||||
};
|
};
|
||||||
|
|
||||||
Chain.prototype.getStartHeight = function getStartHeight() {
|
Chain.prototype.getStartHeight = function getStartHeight() {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user