fix getAccounts.

This commit is contained in:
Christopher Jeffrey 2016-07-13 15:23:34 -07:00
parent 1e1bd82355
commit 350c76d49b
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
2 changed files with 12 additions and 4 deletions

View File

@ -81,7 +81,7 @@ function runBench(callback) {
});
}, function(err) {
assert.ifError(err);
end(10000);
end(100000);
next();
});
end = bench('tx');

View File

@ -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);
});
};