diff --git a/js/models/Async.js b/js/models/Async.js index b7b9bca33..ed0212332 100644 --- a/js/models/Async.js +++ b/js/models/Async.js @@ -288,6 +288,8 @@ Network.prototype._setupConnectionHandlers = function(opts, cb) { self.socket.emit('subscribe', pubkey); }); + log.debug('Async subs done'); + if (typeof cb === 'function') cb(); }); diff --git a/js/models/Identity.js b/js/models/Identity.js index fbb5c8783..5b4fa72d3 100644 --- a/js/models/Identity.js +++ b/js/models/Identity.js @@ -133,9 +133,12 @@ Identity.createFromPartialJson = function(jsonString, opts, callback) { async.map(exported.walletIds, function(walletId, callback) { identity.retrieveWalletFromStorage(walletId, {}, function(error, wallet) { if (!error) { + +console.log('[Identity.js.136] GOT:', wallet.getName()); //TODO identity.wallets[wallet.getId()] = wallet; identity.bindWallet(wallet); wallet.netStart(); +console.log('[Identity.js.136] STARTED:', wallet.getName()); //TODO } callback(error, wallet); }); diff --git a/js/models/Insight.js b/js/models/Insight.js index 7d187cb2d..0dd6182a2 100644 --- a/js/models/Insight.js +++ b/js/models/Insight.js @@ -200,6 +200,8 @@ Insight.prototype.subscribe = function(addresses) { addresses = Array.isArray(addresses) ? addresses : [addresses]; var self = this; +console.log('[Insight.js.202] subscribe STARTED'); //TODO + function handlerFor(self, address) { return function(txid) { // verify the address is still subscribed @@ -220,12 +222,15 @@ Insight.prototype.subscribe = function(addresses) { if (!self.subscribed[address]) { var handler = handlerFor(self, address); self.subscribed[address] = handler; - log.debug('Subcribe to: ', address); + log.debug('Subscribe to: ', address); s.emit('subscribe', address); s.on(address, handler); } }); + + +console.log('[Insight.js.202] subscribe ENDED'); //TODO }; Insight.prototype.getSubscriptions = function(addresses) { diff --git a/js/models/PublicKeyRing.js b/js/models/PublicKeyRing.js index 10fa59e4e..0b8e628f8 100644 --- a/js/models/PublicKeyRing.js +++ b/js/models/PublicKeyRing.js @@ -85,22 +85,30 @@ PublicKeyRing.trim = function(data) { * @param {object} data - a serialized version of PublicKeyRing {@see PublicKeyRing#trim} * @return {PublicKeyRing} - the deserialized object */ -PublicKeyRing.fromObj = function(data) { - preconditions.checkArgument(!(data instanceof PublicKeyRing), 'bad data format: Did you use .toObj()?'); - var opts = PublicKeyRing.trim(data); +PublicKeyRing.fromObj = function(opts) { + preconditions.checkArgument(!(opts instanceof PublicKeyRing), 'bad opts format: Did you use .toObj()?'); // Support old indexes schema if (!Array.isArray(opts.indexes)) { opts.indexes = HDParams.update(opts.indexes, opts.totalCopayers); } - var ret = new PublicKeyRing(opts); + var pkr = new PublicKeyRing(opts); for (var k in opts.copayersExtPubKeys) { - ret.addCopayer(opts.copayersExtPubKeys[k]); + pkr.addCopayer(opts.copayersExtPubKeys[k]); } - return ret; + if (opts._cache){ + log.debug('PublicKeyRing: Using address cache'); + pkr._cacheAddressMap = opts._cache; + } + + return pkr; +}; + +PublicKeyRing.fromUntrustedObj = function(opts) { + return PublicKeyRing.fromObj(PublicKeyRing.trim(opts)); }; /** @@ -120,10 +128,17 @@ PublicKeyRing.prototype.toObj = function() { copayersExtPubKeys: this.copayersHK.map(function(b) { return b.extendedPublicKeyString(); }), - nicknameFor: this.nicknameFor + nicknameFor: this.nicknameFor, + _cache: this._cacheAddressMap }; }; + +PublicKeyRing.prototype.toTrimmedObj = function() { + return PublicKeyRing.trim(this.toObj()); +} + + /** * @desc * Retrieve a copayer's public key as a hexadecimal encoded string @@ -335,6 +350,8 @@ PublicKeyRing.prototype.getRedeemScript = function(index, isChange, copayerIndex PublicKeyRing.prototype.getAddress = function(index, isChange, id) { var copayerIndex = this.getCosigner(id); if (!this._cachedAddress(index, isChange, id)) { + +console.log('[PublicKeyRing.js.338] CACHE MISS'); //TODO var script = this.getRedeemScript(index, isChange, copayerIndex); var address = Address.fromScript(script, this.network.name); this.addressToPath[address.toString()] = HDPath.FullBranch(index, isChange, copayerIndex); @@ -472,12 +489,16 @@ PublicKeyRing.prototype.getCosigner = function(pubKey) { */ PublicKeyRing.prototype.getAddressesInfo = function(opts, pubkey) { +console.log('[PublicKeyRing.js.474] STARTED'); //TODO var ret = []; var self = this; var copayerIndex = pubkey && this.getCosigner(pubkey); +console.log('[PublicKeyRing.js.478:copayerIndex:]',copayerIndex); //TODO this.indexes.forEach(function(index) { +console.log('[PublicKeyRing.js.479:index:]',index); //TODO ret = ret.concat(self.getAddressesInfoForIndex(index, opts, copayerIndex)); }); +console.log('[PublicKeyRing.js.474] END'); //TODO return ret; }; @@ -511,15 +532,23 @@ PublicKeyRing.prototype.getAddressesInfoForIndex = function(index, opts, copayer isChange: isChange, owned: isOwned }); + +console.log('[PublicKeyRing.js.518] Appending address'); //TODO }; + console.log('[PublicKeyRing.js.519] getAddressesInfoForIndex'); //TODO for (var i = 0; !opts.excludeChange && i < index.changeIndex; i++) { appendAddressInfo(this.getAddress(i, true, index.copayerIndex), true); } + +console.log('[PublicKeyRing.js.526]'); //TODO for (var i = 0; !opts.excludeMain && i < index.receiveIndex; i++) { appendAddressInfo(this.getAddress(i, false, index.copayerIndex), false); } + +console.log('[PublicKeyRing.js.534] CACHE IS' , this._cacheAddressMap); //TODO + return ret; }; diff --git a/js/models/Wallet.js b/js/models/Wallet.js index 43ea774a4..5cc85bdee 100644 --- a/js/models/Wallet.js +++ b/js/models/Wallet.js @@ -314,7 +314,7 @@ Wallet.prototype.changeSettings = function(settings) { Wallet.prototype._onPublicKeyRing = function(senderId, data) { log.debug('Wallet:' + this.id + ' RECV PUBLICKEYRING:', data); - var inPKR = PublicKeyRing.fromObj(data.publicKeyRing); + var inPKR = PublicKeyRing.fromUntrustedObj(data.publicKeyRing); var wasIncomplete = !this.publicKeyRing.isComplete(); var hasChanged; @@ -886,6 +886,8 @@ Wallet.prototype._lockIncomming = function() { }; Wallet.prototype._setBlockchainListeners = function() { + +console.log('[Wallet.js.889] address'); //TODO var self = this; self.blockchain.removeAllListeners(); self.subscribeToAddresses(); @@ -1053,7 +1055,6 @@ Wallet.prototype.toObj = function() { settings: this.settings, networkNonce: this.network.getHexNonce(), //yours networkNonces: this.network.getHexNonces(), //copayers - publicKeyRing: this.publicKeyRing.toObj(), txProposals: this.txProposals.toObj(), privateKey: this.privateKey ? this.privateKey.toObj() : undefined, addressBook: this.addressBook, @@ -1307,7 +1308,7 @@ Wallet.prototype.sendWalletId = function(recipients) { * @param {string[]} [recipients] - the pubkeys of the recipients */ Wallet.prototype.sendPublicKeyRing = function(recipients) { - var publicKeyRingObj = this.publicKeyRing.toObj(); + var publicKeyRingObj = this.publicKeyRing.toTrimmedObj(); this._sendToPeers(recipients, { type: 'publicKeyRing', @@ -2001,6 +2002,7 @@ Wallet.prototype.getAddressesStr = function(opts) { Wallet.prototype.subscribeToAddresses = function() { if (!this.publicKeyRing.isComplete()) return; +console.log('[Wallet.js.2002:subscribeToAddresses:]'); //TODO var addrInfo = this.publicKeyRing.getAddressesInfo(); this.blockchain.subscribe(_.pluck(addrInfo, 'addressStr')); diff --git a/js/services/controllerUtils.js b/js/services/controllerUtils.js index 935bc1ee1..07d157720 100644 --- a/js/services/controllerUtils.js +++ b/js/services/controllerUtils.js @@ -217,22 +217,32 @@ angular.module('copayApp.services') $rootScope.wallet = w; w.updateFocusedTimestamp(Date.now()); root.redirIfLogged(); - root.updateTxs(); - root.updateBalance(w, function() { + $timeout(function(){ $rootScope.$digest(); - }) + },1) + // root.updateTxs(); + // root.updateBalance(w, function() { + // $rootScope.$digest(); + // }) }; root.bindProfile = function($scope, iden, w) { + +console.log('[controllerUtils.js.230] bindProfile Globals'); //TODO root.setupGlobalVariables(iden); +console.log('[controllerUtils.js.230] bindProfile Wallets'); //TODO root.rebindWallets($scope, iden); if (w) { +console.log('[controllerUtils.js.230] bindProfile set Focus'); //TODO root.setFocusedWallet(w); } else { $location.path('/create'); } $timeout(function() { + +console.log('[controllerUtils.js.242] DIGEST'); //TODO $rootScope.$digest() +console.log('[controllerUtils.js.242] DIGEST DONE'); //TODO }, 1); }; @@ -310,6 +320,10 @@ angular.module('copayApp.services') root.updateBalance = function(w, cb, refreshAll) { + return + cb?cb(): null; + + w = w || $rootScope.wallet; if (!w) return root.onErrorDigest(); if (!w.isReady()) return; diff --git a/js/services/identityService.js b/js/services/identityService.js index 6c54b189d..492bf0f4b 100644 --- a/js/services/identityService.js +++ b/js/services/identityService.js @@ -92,6 +92,8 @@ angular.module('copayApp.services') $rootScope.$digest() }, 1); } else { + +console.log('[identityService.js.95] LISTO OPEN!!'); //TODO var firstWallet = iden.getLastFocusedWallet(); controllerUtils.bindProfile(scope, iden, firstWallet); } diff --git a/views/home.html b/views/home.html index b6edc54d3..03aa994e0 100644 --- a/views/home.html +++ b/views/home.html @@ -9,6 +9,7 @@