2014-06-16 13:37:33 -07:00
|
|
|
var FakeStorage = function() {
|
2014-06-17 10:02:39 -07:00
|
|
|
this.reset();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
FakeStorage.prototype.reset = function(password) {
|
2014-03-26 13:55:02 -07:00
|
|
|
this.storage = {};
|
2014-06-16 13:37:33 -07:00
|
|
|
};
|
2014-03-26 13:55:02 -07:00
|
|
|
|
2014-06-16 13:37:33 -07:00
|
|
|
FakeStorage.prototype._setPassphrase = function(password) {
|
2014-05-01 11:12:38 -07:00
|
|
|
this.storage.passphrase = password;
|
|
|
|
};
|
|
|
|
|
2014-06-16 13:37:33 -07:00
|
|
|
FakeStorage.prototype.setGlobal = function(id, payload) {
|
2014-04-09 10:30:12 -07:00
|
|
|
this.storage[id] = payload;
|
2014-03-26 13:55:02 -07:00
|
|
|
};
|
|
|
|
|
2014-04-15 10:55:09 -07:00
|
|
|
FakeStorage.prototype.getGlobal = function(id) {
|
2014-04-09 10:30:12 -07:00
|
|
|
return this.storage[id];
|
2014-06-16 13:37:33 -07:00
|
|
|
};
|
|
|
|
|
2014-08-04 11:10:01 -07:00
|
|
|
FakeStorage.prototype.setLastOpened = function(val) {
|
|
|
|
this.storage['lastOpened'] = val;
|
|
|
|
};
|
|
|
|
|
|
|
|
FakeStorage.prototype.getLastOpened = function() {
|
|
|
|
return this.storage['lastOpened'];
|
|
|
|
};
|
2014-06-16 13:37:33 -07:00
|
|
|
|
2014-08-12 12:26:15 -07:00
|
|
|
FakeStorage.prototype.setLock = function(id) {
|
|
|
|
this.storage[id + '::lock'] = true;
|
2014-08-07 16:07:41 -07:00
|
|
|
}
|
|
|
|
|
2014-08-12 12:26:15 -07:00
|
|
|
FakeStorage.prototype.getLock = function(id) {
|
|
|
|
return this.storage[id + '::lock'];
|
2014-08-07 16:07:41 -07:00
|
|
|
}
|
|
|
|
|
2014-08-12 12:26:15 -07:00
|
|
|
FakeStorage.prototype.removeLock = function(id) {
|
|
|
|
delete this.storage[id + '::lock'];
|
2014-08-07 16:07:41 -07:00
|
|
|
}
|
|
|
|
|
2014-06-16 13:37:33 -07:00
|
|
|
FakeStorage.prototype.removeGlobal = function(id) {
|
|
|
|
delete this.storage[id];
|
|
|
|
};
|
2014-03-26 13:55:02 -07:00
|
|
|
|
2014-06-16 13:37:33 -07:00
|
|
|
|
|
|
|
FakeStorage.prototype.set = function(wid, id, payload) {
|
|
|
|
this.storage[wid + '::' + id] = payload;
|
2014-04-15 10:55:09 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
FakeStorage.prototype.get = function(wid, id) {
|
2014-06-16 13:37:33 -07:00
|
|
|
return this.storage[wid + '::' + id];
|
|
|
|
};
|
2014-04-15 10:55:09 -07:00
|
|
|
|
|
|
|
FakeStorage.prototype.clear = function() {
|
|
|
|
delete this['storage'];
|
2014-06-16 13:37:33 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
FakeStorage.prototype.getWalletIds = function() {
|
|
|
|
var walletIds = [];
|
|
|
|
var uniq = {};
|
|
|
|
|
|
|
|
for (var ii in this.storage) {
|
|
|
|
var split = ii.split('::');
|
|
|
|
if (split.length == 2) {
|
|
|
|
var walletId = split[0];
|
|
|
|
if (walletId !== 'nameFor' && typeof uniq[walletId] === 'undefined') {
|
|
|
|
walletIds.push(walletId);
|
|
|
|
uniq[walletId] = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return walletIds;
|
|
|
|
};
|
|
|
|
|
|
|
|
FakeStorage.prototype.deleteWallet = function(walletId) {
|
|
|
|
var toDelete = {};
|
|
|
|
toDelete['nameFor::' + walletId] = 1;
|
|
|
|
|
|
|
|
for (var key in this.storage) {
|
|
|
|
var split = key.split('::');
|
|
|
|
if (split.length == 2 && split[0] === walletId) {
|
|
|
|
toDelete[key] = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (var i in toDelete) {
|
|
|
|
this.removeGlobal(i);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
FakeStorage.prototype.getName = function(walletId) {
|
|
|
|
return this.getGlobal('nameFor::' + walletId);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
FakeStorage.prototype.setName = function(walletId, name) {
|
|
|
|
this.setGlobal('nameFor::' + walletId, name);
|
|
|
|
};
|
|
|
|
|
2014-04-15 10:55:09 -07:00
|
|
|
|
2014-04-24 19:42:59 -07:00
|
|
|
FakeStorage.prototype.getWallets = function() {
|
2014-06-16 13:37:33 -07:00
|
|
|
var wallets = [];
|
|
|
|
var ids = this.getWalletIds();
|
|
|
|
|
|
|
|
for (var i in ids) {
|
|
|
|
wallets.push({
|
|
|
|
id: ids[i],
|
|
|
|
name: this.getName(ids[i]),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return wallets;
|
2014-04-16 17:02:53 -07:00
|
|
|
};
|
|
|
|
|
2014-04-17 14:55:17 -07:00
|
|
|
FakeStorage.prototype.setFromObj = function(walletId, obj) {
|
2014-06-16 13:37:33 -07:00
|
|
|
for (var k in obj) {
|
|
|
|
this.set(walletId, k, obj[k]);
|
|
|
|
}
|
|
|
|
this.setName(walletId, obj.opts.name);
|
2014-04-17 14:55:17 -07:00
|
|
|
};
|
|
|
|
|
2014-03-26 13:55:02 -07:00
|
|
|
module.exports = require('soop')(FakeStorage);
|