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

@ -15,4 +15,3 @@ module.exports.Wallet = require('soop').load('./js/models/core/Wallet',{
Storage: StoragePlain, Storage: StoragePlain,
}); });

View file

@ -5,8 +5,10 @@ var config = {
p2pApiKey: 'lwjd5qra8257b9', p2pApiKey: 'lwjd5qra8257b9',
p2pDebug: 3, p2pDebug: 3,
maxPeers: 5, maxPeers: 5,
requiredCopayers: 2, wallet: {
totalCopayers: 3, requiredCopayers: 2,
totalCopayers: 3,
},
insight: { insight: {
host: 'localhost', host: 'localhost',
port: 3001 port: 3001

View file

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

View file

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

View file

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

View file

@ -20,7 +20,6 @@ angular.module('copay.network')
}); });
}; };
// set new inbound connections // set new inbound connections
var _setNewPeer = function(newPeer) { var _setNewPeer = function(newPeer) {
var cp = $rootScope.cp; var cp = $rootScope.cp;
@ -51,15 +50,12 @@ angular.module('copay.network')
// TODO -> probably not in network.js // TODO -> probably not in network.js
var createWallet = function(walletId) { var createWallet = function(walletId) {
opts.walletId = walletId; var w = new copay.Wallet.create(config, {walletId: walletId});
var w = new copay.Wallet(opts, config);
// Store it on rootScope // Store it on rootScope
$rootScope.walletId = pkr.id;
$rootScope.wallet = w; $rootScope.wallet = w;
$rootScope.walletId = w.id;
//TODO w.store();
// w.store();
}; };
var openWallet = function (walletId) { var openWallet = function (walletId) {