add chain.hasOrphan method.
This commit is contained in:
parent
e735249d0d
commit
d1f8e9b5ff
@ -381,13 +381,26 @@ Chain.prototype.has = function has(hash, noProbe, cb) {
|
|||||||
return cb(!!this.orphan.map[hash]);
|
return cb(!!this.orphan.map[hash]);
|
||||||
};
|
};
|
||||||
|
|
||||||
Chain.prototype.hasBlock = function hasBlock(hash, noProbe, strict) {
|
Chain.prototype.hasBlock = function hasBlock(hash) {
|
||||||
if (this.loading)
|
if (this.loading)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
if (Array.isArray(hash))
|
||||||
|
hash = utils.toHex(hash);
|
||||||
|
|
||||||
return this.index.bloom.test(hash, 'hex');
|
return this.index.bloom.test(hash, 'hex');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Chain.prototype.hasOrphan = function hasOrphan(hash) {
|
||||||
|
if (this.loading)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (Array.isArray(hash))
|
||||||
|
hash = utils.toHex(hash);
|
||||||
|
|
||||||
|
return !!this.orphan.bmap[hash];
|
||||||
|
};
|
||||||
|
|
||||||
Chain.prototype.get = function get(hash, force, cb) {
|
Chain.prototype.get = function get(hash, force, cb) {
|
||||||
if (typeof force === 'function') {
|
if (typeof force === 'function') {
|
||||||
cb = force;
|
cb = force;
|
||||||
|
|||||||
@ -460,12 +460,11 @@ Peer.prototype._handleInv = function handleInv(items) {
|
|||||||
for (var i = 0; i < blocks.length; i++) {
|
for (var i = 0; i < blocks.length; i++) {
|
||||||
var block = blocks[i];
|
var block = blocks[i];
|
||||||
var hash = utils.toHex(block);
|
var hash = utils.toHex(block);
|
||||||
if (this.chain.orphan.bmap[hash]) {
|
if (this.chain.hasOrphan(hash)) {
|
||||||
this.loadBlocks(this.chain.locatorHashes(), this.chain.getOrphanRoot(hash));
|
this.loadBlocks(this.chain.locatorHashes(), this.chain.getOrphanRoot(hash));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!this.chain.hasBlock(hash)) {
|
if (!this.chain.hasBlock(hash)) {
|
||||||
// this.getData({ type: 'block', hash: hash });
|
|
||||||
req.push({ type: 'block', hash: block });
|
req.push({ type: 'block', hash: block });
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user