Added Storage#readWallet and used this from WalletFactory
This commit is contained in:
parent
5c1935e04b
commit
0f37ea1929
4 changed files with 105 additions and 63 deletions
|
|
@ -140,6 +140,23 @@ Storage.prototype._readHelper = function(walletId, k, cb) {
|
|||
});
|
||||
};
|
||||
|
||||
Storage.prototype.readWallet = function(walletId, cb) {
|
||||
var self = this;
|
||||
this.storage.allKeys(function(allKeys) {
|
||||
var obj = {};
|
||||
var keys = _.filter(allKeys, function(k) {
|
||||
if (k.indexOf(walletId + '::') === 0) return true;
|
||||
});
|
||||
var count = keys.length;
|
||||
_.each(keys, function(k) {
|
||||
self._read(k, function(v) {
|
||||
obj[k.split('::')[1]] = v;
|
||||
if (--count === 0) return cb(obj);
|
||||
})
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
Storage.prototype.getMany = function(walletId, keys, cb) {
|
||||
preconditions.checkArgument(cb);
|
||||
|
||||
|
|
|
|||
|
|
@ -153,10 +153,10 @@ WalletFactory.prototype.read = function(walletId, skipFields, cb) {
|
|||
err;
|
||||
var obj = {};
|
||||
|
||||
this.storage.getMany(walletId, Wallet.PERSISTED_PROPERTIES, function(ret) {
|
||||
for (var ii in ret) {
|
||||
obj[ii] = ret[ii];
|
||||
}
|
||||
this.storage.readWallet(walletId, function(ret) {
|
||||
_.each(Wallet.PERSISTED_PROPERTIES, function(p) {
|
||||
obj[p] = ret[p];
|
||||
});
|
||||
|
||||
if (!_.any(_.values(obj)))
|
||||
return cb(new Error('Wallet not found'));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue