chaindb: cleanup.
This commit is contained in:
parent
ac7f194c4d
commit
fcc3f52f72
@ -336,36 +336,6 @@ ChainDB.prototype.getHash = co(function* getHash(height) {
|
|||||||
return hash.toString('hex');
|
return hash.toString('hex');
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
|
||||||
* Get both hash and height depending on the value passed in.
|
|
||||||
* @param {Hash|Number} block - Can be a hash or height.
|
|
||||||
* @returns {Promise}
|
|
||||||
*/
|
|
||||||
|
|
||||||
ChainDB.prototype.getBoth = co(function* getBoth(block) {
|
|
||||||
var hash, height;
|
|
||||||
|
|
||||||
if (typeof block === 'number') {
|
|
||||||
height = block;
|
|
||||||
hash = yield this.getHash(height);
|
|
||||||
|
|
||||||
if (hash == null)
|
|
||||||
height = -1;
|
|
||||||
|
|
||||||
return new BlockPair(hash, height);
|
|
||||||
}
|
|
||||||
|
|
||||||
assert(typeof block === 'string');
|
|
||||||
|
|
||||||
hash = block;
|
|
||||||
height = yield this.getHeight(hash);
|
|
||||||
|
|
||||||
if (height === -1)
|
|
||||||
hash = null;
|
|
||||||
|
|
||||||
return new BlockPair(hash, height);
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve a chain entry by height.
|
* Retrieve a chain entry by height.
|
||||||
* @param {Number} height
|
* @param {Number} height
|
||||||
@ -454,16 +424,14 @@ ChainDB.prototype.getEntry = function getEntry(block) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test whether the chain contains a block in the
|
* Test whether the chain contains a block.
|
||||||
* main chain or an alternate chain. Alternate chains will only
|
* @param {Hash} hash
|
||||||
* be tested if the lookup is done by hash.
|
|
||||||
* @param {Hash|Number} block - Hash or height.
|
|
||||||
* @returns {Promise} - Returns Boolean.
|
* @returns {Promise} - Returns Boolean.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
ChainDB.prototype.hasEntry = co(function* hasEntry(block) {
|
ChainDB.prototype.hasEntry = co(function* hasEntry(hash) {
|
||||||
var item = yield this.getBoth(block);
|
var height = yield this.getHeight(hash);
|
||||||
return item.hash != null;
|
return height !== -1;
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user