WIP wallet working again

This commit is contained in:
Matias Alejo Garcia 2014-04-15 10:22:50 -03:00
commit a187726fca
6 changed files with 29 additions and 19 deletions

View file

@ -13,12 +13,10 @@ var Blockchain = imports.Blockchain;
var copay = copay || require('../../../copay');
function Wallet(config) {
this._startInterface(config);
}
Wallet.prototype._startInterface = function(config) {
this.storage = new Storage(config.storage);
this.network = new Network(config.network);
@ -77,6 +75,13 @@ Wallet.prototype._load = function(config, walletId) {
};
Wallet.prototype.store = function() {
this.storage.set(this.id,'publicKeyRing', this.publicKeyRing.toObj());
this.storage.set(this.id,'txProposals', this.txProposals.toObj());
this.storage.set(this.id,'privateKey', this.privateKey.toObj());
};
// CONSTRUCTORS
Wallet.read = function(config, walletId) {
var w = new Wallet(config);
@ -92,6 +97,7 @@ Wallet.create = function(config, opts) {
return w;
};
<<<<<<< HEAD
Wallet.getRandomId = function() {
var r = buffertools.toHex(coinUtil.generateNonce());
return r;
@ -121,6 +127,9 @@ WalletFactory.prototype.remove = function(walletId) {
// TODO remove wallet contents, not only the id (Wallet.remove?)
this._delWalletId(walletId);
};
=======
module.exports = require('soop')(Wallet);
>>>>>>> WIP wallet working again
WalletFactory.prototype._addWalletId = function(walletId) {
var ids = this._getWalletIds();

View file

@ -6,15 +6,15 @@ function Storage() {
}
// get value by key
Storage.prototype.get = function(k) {
Storage.prototype.get = function(walletId,k) {
};
// set value for key
Storage.prototype.set = function(k,v) {
Storage.prototype.set = function(walletId,v) {
};
// remove value for key
Storage.prototype.remove = function(k) {
Storage.prototype.remove = function(walletId, k) {
};
// remove all values

View file

@ -6,19 +6,23 @@ function Storage() {
this.data = {};
}
// get value by key
Storage.prototype.get = function(k) {
return JSON.parse(localStorage.getItem(k));
Storage.prototype._key = function(walletId, k) {
return walletId + '::' + k;
};
// get value by key
Storage.prototype.get = function(walletId, k) {
return JSON.parse(localStorage.getItem(this._key(walletId,k)));
};
// set value for key
Storage.prototype.set = function(k,v) {
localStorage.setItem(k, JSON.stringify(v));
localStorage.setItem(this._key(walletId,k), JSON.stringify(v));
};
// remove value for key
Storage.prototype.remove = function(k) {
localStorage.removeItem(k);
localStorage.removeItem(this._key(walletId,k));
};
// remove all values