Removed unused functions and refactored tests
This commit is contained in:
parent
cd3f2b8b90
commit
861c1882df
4 changed files with 182 additions and 187 deletions
|
|
@ -122,16 +122,6 @@ Storage.prototype.setSessionId = function(sessionId, cb) {
|
|||
this.sessionStorage.setItem('sessionId', sessionId, cb);
|
||||
};
|
||||
|
||||
Storage.prototype._key = function(walletId, k) {
|
||||
return walletId + '::' + k;
|
||||
};
|
||||
// get value by key
|
||||
Storage.prototype.get = function(walletId, k, cb) {
|
||||
preconditions.checkArgument(walletId, k, cb);
|
||||
this._read(this._key(walletId, k), cb);
|
||||
};
|
||||
|
||||
|
||||
Storage.prototype._readHelper = function(walletId, k, cb) {
|
||||
var wk = this._key(walletId, k);
|
||||
this._read(wk, function(v) {
|
||||
|
|
@ -139,33 +129,34 @@ Storage.prototype._readHelper = function(walletId, k, cb) {
|
|||
});
|
||||
};
|
||||
|
||||
Storage.prototype.readWallet = function(walletId, cb) {
|
||||
Storage.prototype.readWallet_Old = 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;
|
||||
});
|
||||
if (keys.length === 0) return cb(null);
|
||||
if (keys.length === 0) return cb(new Error('Wallet ' + walletId + ' not found'));
|
||||
var count = keys.length;
|
||||
_.each(keys, function(k) {
|
||||
self._read(k, function(v) {
|
||||
obj[k.split('::')[1]] = v;
|
||||
if (--count === 0) return cb(obj);
|
||||
if (--count === 0) return cb(null, obj);
|
||||
})
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
Storage.prototype.readWallet2 = function(walletId, cb) {
|
||||
Storage.prototype.readWallet = function(walletId, cb) {
|
||||
var self = this;
|
||||
this.storage.allKeys(function(allKeys) {
|
||||
var keys = _.filter(allKeys, function(k) {
|
||||
if ((k === 'wallet::' + walletId) || k.indexOf('wallet::' + walletId) === 0) return true;
|
||||
});
|
||||
if (keys.length !== 1) throw new Error('WALLETNOTFOUND');
|
||||
if (keys.length === 0) return cb(new Error('Wallet ' + walletId + ' not found'));
|
||||
self._read(keys[0], function(v) {
|
||||
return cb(v);
|
||||
if (_.isNull(v)) return cb(new Error('Could not decrypt wallet data'));
|
||||
return cb(null, v);
|
||||
})
|
||||
});
|
||||
};
|
||||
|
|
@ -189,32 +180,7 @@ Storage.prototype.getMany = function(walletId, keys, cb) {
|
|||
}
|
||||
};
|
||||
|
||||
// set value for key
|
||||
Storage.prototype.set = function(walletId, k, v, cb) {
|
||||
preconditions.checkArgument(walletId && k && cb);
|
||||
|
||||
if (_.isUndefined(v)) return cb();
|
||||
|
||||
this._write(this._key(walletId, k), v, cb);
|
||||
};
|
||||
|
||||
// remove value for key
|
||||
Storage.prototype.remove = function(walletId, k, cb) {
|
||||
preconditions.checkArgument(walletId && k && cb);
|
||||
this.removeGlobal(this._key(walletId, k), cb);
|
||||
};
|
||||
|
||||
Storage.prototype.setName = function(walletId, name, cb) {
|
||||
preconditions.checkArgument(walletId && name && cb);
|
||||
this.setGlobal('nameFor::' + walletId, name, cb);
|
||||
};
|
||||
|
||||
Storage.prototype.getName = function(walletId, cb) {
|
||||
preconditions.checkArgument(walletId && cb);
|
||||
this.getGlobal('nameFor::' + walletId, cb);
|
||||
};
|
||||
|
||||
Storage.prototype.getWalletIds = function(cb) {
|
||||
Storage.prototype._getWalletIds = function(cb) {
|
||||
preconditions.checkArgument(cb);
|
||||
var walletIds = [];
|
||||
var uniq = {};
|
||||
|
|
@ -225,7 +191,7 @@ Storage.prototype.getWalletIds = function(cb) {
|
|||
if (split.length == 2) {
|
||||
var walletId = split[0];
|
||||
|
||||
if (!walletId || walletId === 'nameFor' || walletId === 'lock')
|
||||
if (!walletId || walletId === 'nameFor' || walletId === 'lock' || walletId === 'wallet')
|
||||
continue;
|
||||
|
||||
if (typeof uniq[walletId] === 'undefined') {
|
||||
|
|
@ -238,7 +204,7 @@ Storage.prototype.getWalletIds = function(cb) {
|
|||
});
|
||||
};
|
||||
|
||||
Storage.prototype.getWallets = function(cb) {
|
||||
Storage.prototype.getWallets_Old = function(cb) {
|
||||
preconditions.checkArgument(cb);
|
||||
|
||||
if (this.wListCache.ts > Date.now())
|
||||
|
|
@ -247,14 +213,14 @@ Storage.prototype.getWallets = function(cb) {
|
|||
var wallets = [];
|
||||
var self = this;
|
||||
|
||||
this.getWalletIds(function(ids) {
|
||||
this._getWalletIds(function(ids) {
|
||||
var l = ids.length,
|
||||
i = 0;
|
||||
if (!l)
|
||||
return cb([]);
|
||||
|
||||
_.each(ids, function(id) {
|
||||
self.getName(id, function(name) {
|
||||
self.getGlobal('nameFor::' + id, function(name) {
|
||||
wallets.push({
|
||||
id: id,
|
||||
name: name,
|
||||
|
|
@ -290,8 +256,17 @@ Storage.prototype.getWallets2 = function(cb) {
|
|||
});
|
||||
};
|
||||
|
||||
Storage.prototype.getWallets = function(cb) {
|
||||
var self = this;
|
||||
self.getWallets2(function(wallets1) {
|
||||
self.getWallets_Old(function(wallets2) {
|
||||
return cb(wallets1.concat(wallets2));
|
||||
});
|
||||
})
|
||||
};
|
||||
|
||||
Storage.prototype.deleteWallet = function(walletId, cb) {
|
||||
|
||||
Storage.prototype.deleteWallet_Old = function(walletId, cb) {
|
||||
preconditions.checkArgument(walletId);
|
||||
preconditions.checkArgument(cb);
|
||||
var err;
|
||||
|
|
@ -325,7 +300,7 @@ Storage.prototype.deleteWallet = function(walletId, cb) {
|
|||
});
|
||||
};
|
||||
|
||||
Storage.prototype.deleteWallet2 = function(walletId, cb) {
|
||||
Storage.prototype.deleteWallet = function(walletId, cb) {
|
||||
preconditions.checkArgument(walletId);
|
||||
preconditions.checkArgument(cb);
|
||||
|
||||
|
|
@ -350,29 +325,10 @@ Storage.prototype.getLastOpened = function(cb) {
|
|||
this.getGlobal('lastOpened', cb);
|
||||
};
|
||||
|
||||
//obj contains keys to be set
|
||||
Storage.prototype.setFromObj = function(walletId, obj, cb) {
|
||||
preconditions.checkArgument(cb);
|
||||
var self = this;
|
||||
|
||||
var l = Object.keys(obj).length,
|
||||
i = 0;
|
||||
for (var k in obj) {
|
||||
self.set(walletId, k, obj[k], function() {
|
||||
if (++i == l) {
|
||||
if (obj.opts.name)
|
||||
self.setName(walletId, obj.opts.name, cb);
|
||||
else
|
||||
return cb();
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Storage.prototype.setFromObj2 = function(walletId, obj, cb) {
|
||||
preconditions.checkArgument(cb);
|
||||
var self = this;
|
||||
|
||||
var key = 'wallet::' + walletId + ((obj.opts && obj.opts.name) ? '_' + obj.opts.name : '');
|
||||
self._write(key, obj, function() {
|
||||
return cb();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue