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(!!this.orphan.map[hash]);
|
||||
if (this.hasOrphan(hash))
|
||||
return cb(true);
|
||||
|
||||
return cb(false);
|
||||
};
|
||||
|
||||
Chain.prototype.byHeight = function byHeight(height) {
|
||||
@ -480,9 +483,13 @@ Chain.prototype.get = function get(hash, force, cb) {
|
||||
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))
|
||||
this.emit('missing', hash, null, null);
|
||||
};
|
||||
|
||||
@ -249,8 +249,6 @@ Chain.prototype.add = function add(block) {
|
||||
};
|
||||
|
||||
Chain.prototype.has = function has(hash, noProbe, cb) {
|
||||
var res;
|
||||
|
||||
if (typeof noProbe === 'function') {
|
||||
cb = noProbe;
|
||||
noProbe = false;
|
||||
@ -263,13 +261,11 @@ Chain.prototype.has = function has(hash, noProbe, cb) {
|
||||
return;
|
||||
}
|
||||
|
||||
res = this.hasBlock(hash) || this.hasOrphan(hash);
|
||||
|
||||
if (!cb)
|
||||
return res;
|
||||
|
||||
cb = utils.asyncify(cb);
|
||||
return cb(res);
|
||||
|
||||
assert(!noProbe);
|
||||
|
||||
return cb(this.hasBlock(hash) || this.hasOrphan(hash));
|
||||
};
|
||||
|
||||
Chain.prototype.byHeight = function byHeight(height) {
|
||||
@ -338,22 +334,14 @@ Chain.prototype.hashesInRange = function hashesInRange(start, end, cb) {
|
||||
};
|
||||
|
||||
Chain.prototype.getLast = function getLast(cb) {
|
||||
var res;
|
||||
|
||||
if (this.loading) {
|
||||
this.once('load', function() {
|
||||
this.getLast(cb);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
res = this.index.hashes[this.index.hashes.length - 1];
|
||||
|
||||
if (!cb)
|
||||
return res;
|
||||
|
||||
cb = utils.asyncify(cb);
|
||||
return cb(res);
|
||||
return cb(this.index.hashes[this.index.hashes.length - 1]);
|
||||
};
|
||||
|
||||
Chain.prototype.getStartHeight = function getStartHeight() {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user