fix walletLock test
This commit is contained in:
parent
b3ed2a2ea8
commit
f1e6d6cfc6
8 changed files with 269 additions and 153 deletions
|
|
@ -99,17 +99,22 @@ Storage.prototype.setGlobal = function(k, v, cb) {
|
|||
// remove value for key
|
||||
Storage.prototype.removeGlobal = function(k, cb) {
|
||||
preconditions.checkArgument(cb);
|
||||
|
||||
this.storage.removeItem(k, cb);
|
||||
};
|
||||
|
||||
Storage.prototype.getSessionId = function() {
|
||||
var sessionId = this.sessionStorage.getItem('sessionId');
|
||||
if (!sessionId) {
|
||||
Storage.prototype.getSessionId = function(cb) {
|
||||
preconditions.checkArgument(cb);
|
||||
var self = this;
|
||||
|
||||
self.sessionStorage.getItem('sessionId', function(sessionId) {
|
||||
if (sessionId)
|
||||
return cb(sessionId);
|
||||
|
||||
sessionId = bitcore.SecureRandom.getRandomBuffer(8).toString('hex');
|
||||
this.sessionStorage.setItem('sessionId', sessionId);
|
||||
}
|
||||
return sessionId;
|
||||
self.sessionStorage.setItem('sessionId', sessionId, function(){
|
||||
return cb(sessionId);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
Storage.prototype._key = function(walletId, k) {
|
||||
|
|
@ -117,14 +122,15 @@ Storage.prototype._key = function(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){
|
||||
return cb(v,k);
|
||||
this._read(wk, function(v) {
|
||||
return cb(v, k);
|
||||
});
|
||||
};
|
||||
|
||||
|
|
@ -133,15 +139,15 @@ Storage.prototype.getMany = function(walletId, keys, cb) {
|
|||
|
||||
var self = this;
|
||||
var ret = {};
|
||||
console.log('[Storage.js.142:keys:]',keys); //TODO
|
||||
|
||||
var l = keys.length, i=0;
|
||||
var l = keys.length,
|
||||
i = 0;
|
||||
|
||||
for (var ii in keys) {
|
||||
this._readHelper(walletId, keys[ii], function(v, k) {
|
||||
ret[k] = v;
|
||||
if (++i == l) {
|
||||
return cb(ret);
|
||||
return cb(ret);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -202,7 +208,8 @@ Storage.prototype.getWallets = function(cb) {
|
|||
var self = this;
|
||||
|
||||
this.getWalletIds(function(ids) {
|
||||
var l = ids.length, i=0;
|
||||
var l = ids.length,
|
||||
i = 0;
|
||||
if (!l)
|
||||
return cb([]);
|
||||
|
||||
|
|
@ -221,21 +228,29 @@ Storage.prototype.getWallets = function(cb) {
|
|||
});
|
||||
};
|
||||
|
||||
Storage.prototype.deleteWallet = function(walletId) {
|
||||
Storage.prototype.deleteWallet = function(walletId, cb) {
|
||||
preconditions.checkArgument(walletId);
|
||||
preconditions.checkArgument(cb);
|
||||
|
||||
var toDelete = {};
|
||||
toDelete['nameFor::' + walletId] = 1;
|
||||
|
||||
for (var i = 0; i < this.storage.length; i++) {
|
||||
var key = this.storage.key(i);
|
||||
var split = key.split('::');
|
||||
if (split.length == 2 && split[0] === walletId) {
|
||||
toDelete[key] = 1;
|
||||
this.storage.allKeys(function(allKeys) {
|
||||
for (var key in allKeys) {
|
||||
var split = key.split('::');
|
||||
if (split.length == 2 && split[0] === walletId) {
|
||||
toDelete[key] = 1;
|
||||
};
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var l = toDelete.length,
|
||||
i = 0;
|
||||
for (var i in toDelete) {
|
||||
this.removeGlobal(i);
|
||||
this.removeGlobal(i, function() {
|
||||
if (++i == l)
|
||||
return cb();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -255,7 +270,6 @@ Storage.prototype.setFromObj = function(walletId, obj, cb) {
|
|||
var l = Object.keys(obj).length,
|
||||
i = 0;
|
||||
for (var k in obj) {
|
||||
console.log('[Storage.js.247]', k, i, l); //TODO
|
||||
self.set(walletId, k, obj[k], function() {
|
||||
if (++i == l) {
|
||||
self.setName(walletId, obj.opts.name, cb);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue