From a187726fca51cd44e3440bf2d7f2aaf38f010bae Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Tue, 15 Apr 2014 10:22:50 -0300 Subject: [PATCH] WIP wallet working again --- copay.js | 1 - js/config.js | 6 ++++-- js/models/core/Wallet.js | 13 +++++++++++-- js/models/storage/Base.js | 6 +++--- js/models/storage/Plain.js | 14 +++++++++----- js/services/network.js | 10 +++------- 6 files changed, 30 insertions(+), 20 deletions(-) diff --git a/copay.js b/copay.js index 67fc11658..9f4d3110d 100644 --- a/copay.js +++ b/copay.js @@ -15,4 +15,3 @@ module.exports.Wallet = require('soop').load('./js/models/core/Wallet',{ Storage: StoragePlain, }); - diff --git a/js/config.js b/js/config.js index 128562a87..fc223aa4a 100644 --- a/js/config.js +++ b/js/config.js @@ -5,8 +5,10 @@ var config = { p2pApiKey: 'lwjd5qra8257b9', p2pDebug: 3, maxPeers: 5, - requiredCopayers: 2, - totalCopayers: 3, + wallet: { + requiredCopayers: 2, + totalCopayers: 3, + }, insight: { host: 'localhost', port: 3001 diff --git a/js/models/core/Wallet.js b/js/models/core/Wallet.js index cc5c09021..2d8925903 100644 --- a/js/models/core/Wallet.js +++ b/js/models/core/Wallet.js @@ -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(); diff --git a/js/models/storage/Base.js b/js/models/storage/Base.js index 0a91137ac..8f61f4dfe 100644 --- a/js/models/storage/Base.js +++ b/js/models/storage/Base.js @@ -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 diff --git a/js/models/storage/Plain.js b/js/models/storage/Plain.js index 1a1cf7e69..f7e2cee72 100644 --- a/js/models/storage/Plain.js +++ b/js/models/storage/Plain.js @@ -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 diff --git a/js/services/network.js b/js/services/network.js index 8b5b7cb40..f467a1b4b 100644 --- a/js/services/network.js +++ b/js/services/network.js @@ -20,7 +20,6 @@ angular.module('copay.network') }); }; - // set new inbound connections var _setNewPeer = function(newPeer) { var cp = $rootScope.cp; @@ -51,15 +50,12 @@ angular.module('copay.network') // TODO -> probably not in network.js var createWallet = function(walletId) { - opts.walletId = walletId; - var w = new copay.Wallet(opts, config); + var w = new copay.Wallet.create(config, {walletId: walletId}); // Store it on rootScope - $rootScope.walletId = pkr.id; $rootScope.wallet = w; - -//TODO -// w.store(); + $rootScope.walletId = w.id; + w.store(); }; var openWallet = function (walletId) {