refactor key handing in storage (part 1)

This commit is contained in:
Matias Alejo Garcia 2014-09-27 11:38:25 -03:00
commit 691951a86a
3 changed files with 16 additions and 15 deletions

View file

@ -330,12 +330,10 @@ Storage.prototype.getLastOpened = function(cb) {
this.getGlobal('lastOpened', cb);
};
Storage.prototype.setFromObj = function(walletId, obj, cb) {
Storage.prototype.setFromObj = function(key, obj, cb) {
preconditions.checkArgument(key);
preconditions.checkArgument(cb);
var self = this;
var key = 'wallet::' + walletId + ((obj.opts && obj.opts.name) ? '_' + obj.opts.name : '');
self._write(key, obj, function() {
this._write(key, obj, function() {
return cb();
});
};

View file

@ -873,7 +873,10 @@ Wallet.prototype.keepAlive = function() {
Wallet.prototype.store = function(cb) {
var self = this;
this.keepAlive();
this.storage.setFromObj(this.id, this.toObj(), function(err) {
var val = this.toObj();
var key = 'wallet::' + this.id + ((val.opts && val.opts.name) ? '_' + obj.opts.name : '');
this.storage.setFromObj(key, val, function(err) {
log.debug('Wallet stored');
if (cb)
cb(err);