From 8d624f1b0e48718a8bd1cc9deacb5bddb6e58384 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Fri, 4 Nov 2016 12:38:27 -0700 Subject: [PATCH] walletdb: better getAccounts. --- lib/wallet/walletdb.js | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/lib/wallet/walletdb.js b/lib/wallet/walletdb.js index c73857ce..6cadf85a 100644 --- a/lib/wallet/walletdb.js +++ b/lib/wallet/walletdb.js @@ -970,30 +970,17 @@ WalletDB.prototype.getAccount = co(function* getAccount(wid, index) { */ WalletDB.prototype.getAccounts = co(function* getAccounts(wid) { - var map = []; - var i, items, item, name, index, accounts; + var i, items; - items = yield this.db.range({ - gte: layout.i(wid, '\x00'), - lte: layout.i(wid, '\xff') + items = yield this.db.values({ + gte: layout.n(wid, 0x00000000), + lte: layout.n(wid, 0xffffffff) }); - for (i = 0; i < items.length; i++) { - item = items[i]; - name = layout.ii(item.key)[1]; - index = item.value.readUInt32LE(0, true); - map[index] = name; - } + for (i = 0; i < items.length; i++) + items[i] = items[i].toString('ascii'); - // Get it out of hash table mode. - accounts = []; - - for (i = 0; i < map.length; i++) { - assert(map[i] != null); - accounts.push(map[i]); - } - - return accounts; + return items; }); /** @@ -1291,6 +1278,7 @@ WalletDB.prototype.getWallets = function getWallets() { /** * Encrypt all imported keys for a wallet. * @param {WalletID} wid + * @param {Buffer} key * @returns {Promise} */ @@ -1324,6 +1312,7 @@ WalletDB.prototype.encryptKeys = co(function* encryptKeys(wallet, key) { /** * Decrypt all imported keys for a wallet. * @param {WalletID} wid + * @param {Buffer} key * @returns {Promise} */