diff --git a/lib/bcoin/chaindb.js b/lib/bcoin/chaindb.js index 579c3726..2e8222ba 100644 --- a/lib/bcoin/chaindb.js +++ b/lib/bcoin/chaindb.js @@ -849,8 +849,8 @@ ChainDB.prototype.getCoinsByAddress = function getCoinsByAddress(addresses, opti utils.forEach(addresses, function(address, done) { var iter = self.db.db.iterator({ - gte: 'u/a/' + address, - lte: 'u/a/' + address + '~', + gte: 'u/a/' + address + '/', + lte: 'u/a/' + address + '/~', keys: true, values: true, fillCache: true, @@ -945,8 +945,8 @@ ChainDB.prototype.getTXByAddress = function getTXByAddress(addresses, options, c utils.forEach(addresses, function(address, done) { var iter = self.db.db.iterator({ - gte: 't/a/' + address, - lte: 't/a/' + address + '~', + gte: 't/a/' + address + '/', + lte: 't/a/' + address + '/~', keys: true, values: true, fillCache: true, @@ -977,6 +977,8 @@ ChainDB.prototype.getTXByAddress = function getTXByAddress(addresses, options, c } hashes.push(hash); + + next(); }); })(); }, function(err) { diff --git a/lib/bcoin/datastore.js b/lib/bcoin/datastore.js index ab72c762..2a3fc206 100644 --- a/lib/bcoin/datastore.js +++ b/lib/bcoin/datastore.js @@ -330,8 +330,11 @@ DataStore.prototype.iterator = function iterator(options) { function Iterator(store, options) { this.store = store; this._db = store._db; - if (options && options.keys === false) + if (!options) + options = {}; + if (options.keys === false) options.keys = true; + this.options = options; this.iterator = this._db.db.iterator(options); } @@ -343,18 +346,19 @@ Iterator.prototype.seek = function seek(key) { // hashes directly in the db (unless they're // the same length as offset). function isDirect(key) { - return !/^(b\/b\/|t\/t\/)/.test(key); + return !/^(b\/b\/|t\/t\/|c\/c\/|u\/t\/)/.test(key); } Iterator.prototype.next = function next(callback) { + var self = this; return this.iterator.next(function(err, key, value) { if (err) return callback(err); - if (value) { + if (self.options.values !== false && value) { if (isDirect(key)) return callback(null, key, value); - return self.getData(value, function(err, data) { + return self.store.getData(value, function(err, data) { if (err) return callback(err); return callback(null, key, data); @@ -634,9 +638,8 @@ DataStore.prototype.write = function write(fd, offset, data, callback) { (function next() { fs.write(fd, data, index, size, offset, function(err, bytes) { - if (err) { - return callback(err, index); - } + if (err) + return callback(err); if (!bytes) return callback(self._ioError('write', size, offset)); diff --git a/lib/bcoin/utils.js b/lib/bcoin/utils.js index fde36c50..d2c48f56 100644 --- a/lib/bcoin/utils.js +++ b/lib/bcoin/utils.js @@ -1728,7 +1728,7 @@ utils.indexOf = function indexOf(arr, buf) { }; utils.pad32 = function pad32(num) { - assert(num >= 0); + assert(num >= 0, num); num = num + ''; while (num.length < 10) num = '0' + num;