From 5115b434352248dd0cab8ceddc81d1baa95f243d Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Wed, 6 Jul 2016 12:05:41 -0700 Subject: [PATCH] iterate options. --- lib/bcoin/lowlevelup.js | 26 ++++++++------------------ lib/bcoin/walletdb.js | 12 ++++-------- 2 files changed, 12 insertions(+), 26 deletions(-) diff --git a/lib/bcoin/lowlevelup.js b/lib/bcoin/lowlevelup.js index 8eb65582..3f6a9d56 100644 --- a/lib/bcoin/lowlevelup.js +++ b/lib/bcoin/lowlevelup.js @@ -265,27 +265,17 @@ LowlevelUp.prototype.iterate = function iterate(options, callback) { gte: options.gte, lte: options.lte, keys: true, - values: options.values, - fillCache: false, + values: options.values || false, + fillCache: options.fillCache || false, keyAsBuffer: options.keyAsBuffer || false, - limit: options.limit, - reverse: options.reverse + reverse: options.reverse || false }; - if (opt.gte == null) - delete opt.gte; - - if (opt.lte == null) - delete opt.lte; - - if (opt.values == null) - delete opt.values; - - if (opt.limit == null) - delete opt.limit; - - if (opt.reverse == null) - delete opt.reverse; + // Work around a bug in leveldown that + // I haven't fixed yet, where iterator + // treats limit=undefined as limit=0. + if (options.limit != null) + opt.limit = options.limit; iter = this.iterator(opt); diff --git a/lib/bcoin/walletdb.js b/lib/bcoin/walletdb.js index 7f683409..cf2cea5b 100644 --- a/lib/bcoin/walletdb.js +++ b/lib/bcoin/walletdb.js @@ -215,7 +215,7 @@ WalletDB.prototype.updateBalances = function updateBalances(tx, map, callback) { self.fire(id, 'balance', balances[id]); } - self.emit('balances', balances, map); + self.emit('balance', balances, map); return callback(null, balances); }); @@ -758,19 +758,15 @@ WalletDB.prototype.saveAddress = function saveAddress(id, addresses, callback) { for (i = 0; i < addresses.length; i++) { address = addresses[i]; - path = Path.fromKeyRing(address); + items.push([address.getKeyAddress(), path]); - if (address.type === 'multisig') { - path = Path.fromKeyRing(address); + if (address.type === 'multisig') items.push([address.getScriptAddress(), path]); - } - if (address.witness) { - path = Path.fromKeyRing(address); + if (address.witness) items.push([address.getProgramAddress(), path]); - } } utils.forEachSerial(items, function(item, next) {