Merge pull request #84 from ryanxcharles/feature/wallet-file-consistency

WIP: add setFromObj and getEncryptedObj to storage classes
This commit is contained in:
Manuel Aráoz 2014-04-17 18:35:08 -03:00
commit 9319c7f93f
8 changed files with 140 additions and 6 deletions

View file

@ -1,9 +1,11 @@
'use strict';
var imports = require('soop').imports();
var parent = imports.parent || require('./Base');
function Storage() {
}
Storage.parent = parent;
Storage.prototype._read = function(k) {
var ret;
@ -17,6 +19,21 @@ Storage.prototype._write = function(k,v) {
localStorage.setItem(k, JSON.stringify(v));
};
Storage.prototype._getWalletKeys = function(walletId) {
var keys = [];
for (var i = 0; i < localStorage.length; i++) {
var key = localStorage.key(i);
var split = key.split('::');
if (split.length == 2) {
if (walletId = split[0])
keys.push(split[1]);
}
}
return keys;
};
// get value by key
Storage.prototype.getGlobal = function(k) {
return this._read(k);
@ -71,6 +88,13 @@ Storage.prototype.getWalletIds = function() {
return walletIds;
};
//obj contains keys to be set
Storage.prototype.setFromObj = function(walletId, obj) {
for (var k in obj) {
this.set(walletId, k, obj[k]);
}
};
// remove all values
Storage.prototype.clearAll = function() {
localStorage.clear();