From 350c76d49baa66bafe825a66f06cf9095fb37ad5 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Wed, 13 Jul 2016 15:23:34 -0700 Subject: [PATCH] fix getAccounts. --- bench/walletdb.js | 2 +- lib/bcoin/walletdb.js | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/bench/walletdb.js b/bench/walletdb.js index 54824f0b..966165c1 100644 --- a/bench/walletdb.js +++ b/bench/walletdb.js @@ -81,7 +81,7 @@ function runBench(callback) { }); }, function(err) { assert.ifError(err); - end(10000); + end(100000); next(); }); end = bench('tx'); diff --git a/lib/bcoin/walletdb.js b/lib/bcoin/walletdb.js index 025a7552..4998e52b 100644 --- a/lib/bcoin/walletdb.js +++ b/lib/bcoin/walletdb.js @@ -705,7 +705,8 @@ WalletDB.prototype._getAccount = function getAccount(id, index, callback) { */ WalletDB.prototype.getAccounts = function getAccounts(id, callback) { - var accounts = []; + var map = []; + var i, accounts; if (!utils.isAlpha(id)) return callback(new Error('Wallet IDs must be alphanumeric.')); @@ -717,13 +718,20 @@ WalletDB.prototype.getAccounts = function getAccounts(id, callback) { parse: function(value, key) { var name = key.split('/')[2]; var index = value.readUInt32LE(0, true); - assert(index === accounts.length); - accounts.push(name); + map[index] = name; } }, function(err) { if (err) return callback(err); + // Get it out of hash table mode. + accounts = new Array(map.length); + + for (i = 0; i < map.length; i++) { + assert(map[i] != null); + accounts[i] = map[i]; + } + return callback(null, accounts); }); };