diff --git a/lib/bcoin/chain.js b/lib/bcoin/chain.js index 62dee6e0..1281c958 100644 --- a/lib/bcoin/chain.js +++ b/lib/bcoin/chain.js @@ -543,7 +543,7 @@ Chain.prototype.locatorHashes = function locatorHashes(start) { top = start; } - assert(this.db.get(top)); + assert(this.db.has(top)); i = top; for (;;) { @@ -553,7 +553,7 @@ Chain.prototype.locatorHashes = function locatorHashes(start) { i = i - step; if (i <= 0) { if (i + step !== 0) - hashes.push(this.db.get(0).hash); + hashes.push(network.genesis.hash); break; } if (hashes.length >= 10) @@ -999,6 +999,20 @@ ChainDB.prototype.isNull = function isNull(height) { return utils.read32(data, 0) === 0; }; +ChainDB.prototype.has = function has(height) { + var data; + + if (this._queue[height] || this._cache[height]) + return true; + + data = this._readSync(4, height * BLOCK_SIZE); + + if (!data) + return false; + + return utils.read32(data, 0) !== 0; +}; + ChainDB.prototype._readSync = function _readSync(size, offset) { var index = 0; var data, bytes;