asyncify calls.

This commit is contained in:
Christopher Jeffrey 2016-06-05 17:48:39 -07:00
parent d1695bf014
commit 6a4beafa87
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

@ -280,19 +280,25 @@ ChainDB.prototype.getCache = function getCache(hash) {
*/
ChainDB.prototype.getHeight = function getHeight(hash, callback) {
callback = utils.asyncify(callback);
if (hash == null || hash < 0)
if (hash == null || hash < 0) {
callback = utils.asyncify(callback);
return callback(null, -1);
}
if (typeof hash === 'number')
if (typeof hash === 'number') {
callback = utils.asyncify(callback);
return callback(null, hash);
}
if (hash === constants.NULL_HASH)
if (hash === constants.NULL_HASH) {
callback = utils.asyncify(callback);
return callback(null, -1);
}
if (this.cacheHash.has(hash))
if (this.cacheHash.has(hash)) {
callback = utils.asyncify(callback);
return callback(null, this.cacheHash.get(hash).height);
}
this.db.fetch('h/' + hash, function(data) {
assert(data.length === 4, 'Database corruption.');
@ -316,16 +322,20 @@ ChainDB.prototype.getHeight = function getHeight(hash, callback) {
*/
ChainDB.prototype.getHash = function getHash(height, callback) {
callback = utils.asyncify(callback);
if (height == null || height < 0)
if (height == null || height < 0) {
callback = utils.asyncify(callback);
return callback(null, null);
}
if (typeof height === 'string')
if (typeof height === 'string') {
callback = utils.asyncify(callback);
return callback(null, height);
}
if (this.cacheHeight.has(height))
if (this.cacheHeight.has(height)) {
callback = utils.asyncify(callback);
return callback(null, this.cacheHeight.get(height).hash);
}
this.db.fetch('H/' + pad32(height), function(data) {
assert(data.length === 32, 'Database corruption.');