From 9b266c6ec798305b281fd0eb0a12be6363b7571e Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Thu, 21 Jan 2016 18:28:04 -0800 Subject: [PATCH] minor. --- lib/bcoin/chain.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) 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;