implements delete wallet, in backuptab
This commit is contained in:
parent
46feadf57c
commit
2c60fd91c0
7 changed files with 219 additions and 79 deletions
|
|
@ -1,40 +1,98 @@
|
|||
|
||||
var FakeStorage = function(){
|
||||
var FakeStorage = function() {
|
||||
this.storage = {};
|
||||
};
|
||||
};
|
||||
|
||||
FakeStorage.prototype._setPassphrase = function (password) {
|
||||
FakeStorage.prototype._setPassphrase = function(password) {
|
||||
this.storage.passphrase = password;
|
||||
};
|
||||
|
||||
FakeStorage.prototype.setGlobal = function (id, payload) {
|
||||
FakeStorage.prototype.setGlobal = function(id, payload) {
|
||||
this.storage[id] = payload;
|
||||
};
|
||||
|
||||
FakeStorage.prototype.getGlobal = function(id) {
|
||||
return this.storage[id];
|
||||
}
|
||||
};
|
||||
|
||||
FakeStorage.prototype.set = function (wid, id, payload) {
|
||||
this.storage[wid + '-' + id] = payload;
|
||||
|
||||
FakeStorage.prototype.removeGlobal = function(id) {
|
||||
delete this.storage[id];
|
||||
};
|
||||
|
||||
|
||||
FakeStorage.prototype.set = function(wid, id, payload) {
|
||||
this.storage[wid + '::' + id] = payload;
|
||||
};
|
||||
|
||||
FakeStorage.prototype.get = function(wid, id) {
|
||||
return this.storage[wid + '-' +id];
|
||||
}
|
||||
return this.storage[wid + '::' + id];
|
||||
};
|
||||
|
||||
FakeStorage.prototype.clear = function() {
|
||||
delete this['storage'];
|
||||
}
|
||||
};
|
||||
|
||||
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);
|
||||
};
|
||||
|
||||
|
||||
FakeStorage.prototype.getWallets = function() {
|
||||
return [];
|
||||
var wallets = [];
|
||||
var ids = this.getWalletIds();
|
||||
|
||||
for (var i in ids) {
|
||||
wallets.push({
|
||||
id: ids[i],
|
||||
name: this.getName(ids[i]),
|
||||
});
|
||||
}
|
||||
return wallets;
|
||||
};
|
||||
|
||||
FakeStorage.prototype.setFromObj = function(walletId, obj) {
|
||||
for (var i in obj) {
|
||||
this.storage[walletId + '-' + i] = obj[i];
|
||||
};
|
||||
for (var k in obj) {
|
||||
this.set(walletId, k, obj[k]);
|
||||
}
|
||||
this.setName(walletId, obj.opts.name);
|
||||
};
|
||||
|
||||
module.exports = require('soop')(FakeStorage);
|
||||
|
|
|
|||
|
|
@ -1,20 +1,22 @@
|
|||
|
||||
var FakeWallet = function(){
|
||||
this.balance=10000;
|
||||
this.safeBalance=1000;
|
||||
this.balanceByAddr={'1CjPR7Z5ZSyWk6WtXvSFgkptmpoi4UM9BC': 1000};
|
||||
var FakeWallet = function() {
|
||||
this.id = 'testID';
|
||||
this.balance = 10000;
|
||||
this.safeBalance = 1000;
|
||||
this.balanceByAddr = {
|
||||
'1CjPR7Z5ZSyWk6WtXvSFgkptmpoi4UM9BC': 1000
|
||||
};
|
||||
};
|
||||
|
||||
FakeWallet.prototype.set = function(balance, safeBalance, balanceByAddr){
|
||||
this.balance=balance;
|
||||
FakeWallet.prototype.set = function(balance, safeBalance, balanceByAddr) {
|
||||
this.balance = balance;
|
||||
this.safeBalance = safeBalance;
|
||||
this.balanceByAddr = balanceByAddr;
|
||||
};
|
||||
|
||||
FakeWallet.prototype.getAddressesInfo=function(){
|
||||
FakeWallet.prototype.getAddressesInfo = function() {
|
||||
var ret = [];
|
||||
|
||||
for(var ii in this.balanceByAddr){
|
||||
for (var ii in this.balanceByAddr) {
|
||||
ret.push({
|
||||
address: ii,
|
||||
isChange: false,
|
||||
|
|
@ -24,10 +26,22 @@ FakeWallet.prototype.getAddressesInfo=function(){
|
|||
};
|
||||
|
||||
|
||||
FakeWallet.prototype.getBalance=function(cb){
|
||||
FakeWallet.prototype.getBalance = function(cb) {
|
||||
return cb(null, this.balance, this.balanceByAddr, this.safeBalance);
|
||||
};
|
||||
|
||||
FakeWallet.prototype.setEnc = function(enc) {
|
||||
this.enc = enc;
|
||||
};
|
||||
|
||||
FakeWallet.prototype.toEncryptedObj = function() {
|
||||
return this.enc;
|
||||
};
|
||||
|
||||
FakeWallet.prototype.disconnect = function() {
|
||||
this.disconnectCalled = 1;
|
||||
};
|
||||
|
||||
// This mock is meant for karma, module.exports is not necesary.
|
||||
try {
|
||||
module.exports = require('soop')(FakeWallet);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue