From c45495eeffc526f04808806be7529b42bffe69d6 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Tue, 9 Sep 2014 13:45:50 -0300 Subject: [PATCH 01/20] lazy connect --- js/models/blockchain/Insight.js | 112 +++++++++++++++++++------------- js/services/controllerUtils.js | 2 +- test/test.blockchain.Insight.js | 33 +++++++--- views/open.html | 2 +- 4 files changed, 91 insertions(+), 58 deletions(-) diff --git a/js/models/blockchain/Insight.js b/js/models/blockchain/Insight.js index e26651787..67b95fd7c 100644 --- a/js/models/blockchain/Insight.js +++ b/js/models/blockchain/Insight.js @@ -27,15 +27,15 @@ var preconditions = require('preconditions').singleton(); - disconnect: the connection with the blochckain is unavailable. */ -var Insight = function (opts) { +var Insight = function(opts) { this.status = this.STATUS.DISCONNECTED; this.subscribed = {}; this.listeningBlocks = false; preconditions.checkArgument(opts).shouldBeObject(opts) - .checkArgument(opts.host) - .checkArgument(opts.port) - .checkArgument(opts.schema); + .checkArgument(opts.host) + .checkArgument(opts.port) + .checkArgument(opts.schema); this.url = opts.schema + '://' + opts.host + ':' + opts.port; this.opts = { @@ -44,33 +44,6 @@ var Insight = function (opts) { 'secure': opts.schema === 'https' }; - this.socket = this.getSocket(this.url, this.opts); - - // Emmit connection events - var self = this; - this.socket.on('connect', function() { - self.status = self.STATUS.CONNECTED; - self.subscribeToBlocks(); - self.emit('connect', 0); - }); - - this.socket.on('connect_error', function() { - if (self.status != self.STATUS.CONNECTED) return; - self.status = self.STATUS.DISCONNECTED; - self.emit('disconnect'); - }); - - this.socket.on('connect_timeout', function() { - if (self.status != self.STATUS.CONNECTED) return; - self.status = self.STATUS.DISCONNECTED; - self.emit('disconnect'); - }); - - this.socket.on('reconnect', function(attempt) { - if (self.status != self.STATUS.DISCONNECTED) return; - self.status = self.STATUS.CONNECTED; - self.emit('connect', attempt); - }); } util.inherits(Insight, EventEmitter); @@ -83,19 +56,55 @@ Insight.prototype.STATUS = { /** @private */ Insight.prototype.subscribeToBlocks = function() { - if (this.listeningBlocks || !this.socket.connected) return; + var socket = this.getSocket(); + if (this.listeningBlocks || ! socket.connected) return; var self = this; - this.socket.emit('subscribe', 'inv'); - this.socket.on('block', function(blockHash) { + socket.emit('subscribe', 'inv'); + socket.on('block', function(blockHash) { self.emit('block', blockHash); }); this.listeningBlocks = true; } +/** @private */ +Insight.prototype._getSocketIO = function(url, opts) { + return io(this.url, this.opts); +}; + /** @private */ Insight.prototype.getSocket = function(url, opts) { - return io(this.url, this.opts); + + if (!this.socket) { + this.socket = this._getSocketIO(this.url, this.opts); + + // Emmit connection events + var self = this; + this.socket.on('connect', function() { + self.status = self.STATUS.CONNECTED; + self.subscribeToBlocks(); + self.emit('connect', 0); + }); + + this.socket.on('connect_error', function() { + if (self.status != self.STATUS.CONNECTED) return; + self.status = self.STATUS.DISCONNECTED; + self.emit('disconnect'); + }); + + this.socket.on('connect_timeout', function() { + if (self.status != self.STATUS.CONNECTED) return; + self.status = self.STATUS.DISCONNECTED; + self.emit('disconnect'); + }); + + this.socket.on('reconnect', function(attempt) { + if (self.status != self.STATUS.DISCONNECTED) return; + self.status = self.STATUS.CONNECTED; + self.emit('connect', attempt); + }); + } + return this.socket; } /** @private */ @@ -107,11 +116,15 @@ Insight.prototype.request = function(path, cb) { /** @private */ Insight.prototype.requestPost = function(path, data, cb) { preconditions.checkArgument(path).checkArgument(data).shouldBeFunction(cb); - request({method: "POST", url: this.url + path, json: data}, cb); + request({ + method: "POST", + url: this.url + path, + json: data + }, cb); } Insight.prototype.destroy = function() { - this.socket.destroy(); + this.getSocket().destroy(); this.subscribed = {}; this.status = this.STATUS.DESTROYED; this.removeAllListeners(); @@ -122,10 +135,13 @@ Insight.prototype.subscribe = function(addresses) { var self = this; function handlerFor(self, address) { - return function (txid) { + return function(txid) { // verify the address is still subscribed if (!self.subscribed[address]) return; - self.emit('tx', {address: address, txid: txid}); + self.emit('tx', { + address: address, + txid: txid + }); } } @@ -135,8 +151,8 @@ Insight.prototype.subscribe = function(addresses) { // skip already subscibed if (!self.subscribed[address]) { self.subscribed[address] = true; - self.socket.emit('subscribe', address); - self.socket.on(address, handlerFor(self, address)); + self.getSocket().emit('subscribe', address); + self.getSocket().on(address, handlerFor(self, address)); } }); }; @@ -151,7 +167,7 @@ Insight.prototype.unsubscribe = function(addresses) { addresses.forEach(function(address) { preconditions.checkArgument(new bitcore.Address(address).isValid()); - self.socket.removeEventListener(address); + self.getSocket().removeEventListener(address); delete self.subscribed[address]; }); }; @@ -164,7 +180,9 @@ Insight.prototype.broadcast = function(rawtx, cb) { preconditions.checkArgument(rawtx); preconditions.shouldBeFunction(cb); - this.requestPost('/api/tx/send', {rawtx: rawtx}, function(err, res, body) { + this.requestPost('/api/tx/send', { + rawtx: rawtx + }, function(err, res, body) { if (err || res.statusCode != 200) cb(err || res); cb(null, body.txid); }); @@ -218,7 +236,9 @@ Insight.prototype.getUnspent = function(addresses, cb) { preconditions.shouldBeArray(addresses); preconditions.shouldBeFunction(cb); - this.requestPost('/api/addrs/utxo', {addrs: addresses.join(',')}, function(err, res, body) { + this.requestPost('/api/addrs/utxo', { + addrs: addresses.join(',') + }, function(err, res, body) { if (err || res.statusCode != 200) return cb(err || res); cb(null, body); }); @@ -243,8 +263,8 @@ Insight.prototype.getActivity = function(addresses, cb) { var getOutputs = function(t) { return flatArray( t.vout.map(function(vout) { - return vout.scriptPubKey.addresses; - }) + return vout.scriptPubKey.addresses; + }) ); }; diff --git a/js/services/controllerUtils.js b/js/services/controllerUtils.js index a5ecf83d2..5a339a165 100644 --- a/js/services/controllerUtils.js +++ b/js/services/controllerUtils.js @@ -312,7 +312,7 @@ angular.module('copayApp.services') var allAddrs = $rootScope.addrInfos; var newAddrs = []; - for (var i in allAddrs) { + for:(var i in allAddrs) { var a = allAddrs[i]; if (!currentAddrs[a.addressStr] && !a.isChange) newAddrs.push(a.addressStr); diff --git a/test/test.blockchain.Insight.js b/test/test.blockchain.Insight.js index 7546ff315..46eecdc0e 100644 --- a/test/test.blockchain.Insight.js +++ b/test/test.blockchain.Insight.js @@ -48,13 +48,13 @@ var FAKE_OPTS = { describe('Insight model', function() { before(function() { - sinon.stub(Insight.prototype, "getSocket", function() { + sinon.stub(Insight.prototype, "_getSocketIO", function() { return new FakeSocket(); }); }); after(function() { - Insight.prototype.getSocket.restore(); + Insight.prototype._getSocketIO.restore(); }); it('should create an instance', function() { @@ -65,7 +65,8 @@ describe('Insight model', function() { it('should subscribe to inventory', function(done) { var blockchain = new Insight(FAKE_OPTS); - var emitSpy = sinon.spy(blockchain.socket, 'emit'); + var socket = blockchain.getSocket(); + var emitSpy = sinon.spy(socket, 'emit'); blockchain.on('connect', function() { emitSpy.calledWith('subscribe', 'inv'); done(); @@ -75,6 +76,7 @@ describe('Insight model', function() { it('should be able to destroy the instance', function(done) { var blockchain = new Insight(FAKE_OPTS); blockchain.status.should.be.equal('disconnected'); + var socket = blockchain.getSocket(); blockchain.on('connect', function() { blockchain.subscribe('mg7UbtKgMvWAixTNMbC8soyUnwFk1qxEuM'); blockchain.getSubscriptions().length.should.equal(1); @@ -87,7 +89,8 @@ describe('Insight model', function() { it('should subscribe to an address', function() { var blockchain = new Insight(FAKE_OPTS); - var emitSpy = sinon.spy(blockchain.socket, 'emit'); + var socket = blockchain.getSocket(); + var emitSpy = sinon.spy(socket, 'emit'); blockchain.subscribe('mg7UbtKgMvWAixTNMbC8soyUnwFk1qxEuM'); blockchain.getSubscriptions().length.should.equal(1); @@ -104,7 +107,8 @@ describe('Insight model', function() { it('should subscribe to a list of addresses', function() { var blockchain = new Insight(FAKE_OPTS); - var emitSpy = sinon.spy(blockchain.socket, 'emit'); + var socket = blockchain.getSocket(); + var emitSpy = sinon.spy(socket, 'emit'); blockchain.subscribe([ 'mg7UbtKgMvWAixTNMbC8soyUnwFk1qxEuM', @@ -354,8 +358,10 @@ describe('Insight model', function() { describe('Events', function() { it('should emmit event on a new block', function(done) { var blockchain = new Insight(FAKE_OPTS); + var socket = blockchain.getSocket(); blockchain.on('connect', function() { - blockchain.socket.emit('block', '12312312'); + var socket = blockchain.getSocket(); + socket.emit('block', '12312312'); }); blockchain.on('block', function(blockid) { @@ -364,11 +370,13 @@ describe('Insight model', function() { }); }); - it('should emmit event on a transaction for subscried addresses', function(done) { + it('should emmit event on a transaction for subscribed addresses', function(done) { var blockchain = new Insight(FAKE_OPTS); + var socket = blockchain.getSocket(); blockchain.subscribe('2NFjCBFZSsxiwWAD7CKQ3hzWFtf9DcqTucY'); blockchain.on('connect', function() { - blockchain.socket.emit('2NFjCBFZSsxiwWAD7CKQ3hzWFtf9DcqTucY', '1123'); + var socket = blockchain.getSocket(); + socket.emit('2NFjCBFZSsxiwWAD7CKQ3hzWFtf9DcqTucY', '1123'); }); blockchain.on('tx', function(ev) { @@ -380,8 +388,10 @@ describe('Insight model', function() { it('should\'t emmit event on a transaction for non subscribed addresses', function(done) { var blockchain = new Insight(FAKE_OPTS); + var socket = blockchain.getSocket(); blockchain.on('connect', function() { - blockchain.socket.emit('2NFjCBFZSsxiwWAD7CKQ3hzWFtf9DcqTucY', '1123'); + var socket = blockchain.getSocket(); + socket.emit('2NFjCBFZSsxiwWAD7CKQ3hzWFtf9DcqTucY', '1123'); setTimeout(function() { done(); }, 20); }); @@ -392,6 +402,7 @@ describe('Insight model', function() { it('should emmit event on connection', function(done) { var blockchain = new Insight(FAKE_OPTS); + var socket = blockchain.getSocket(); blockchain.on('connect', function() { done(); }); @@ -399,8 +410,10 @@ describe('Insight model', function() { it('should emmit event on disconnection', function(done) { var blockchain = new Insight(FAKE_OPTS); + var socket = blockchain.getSocket(); blockchain.on('connect', function() { - blockchain.socket.emit('connect_error'); + var socket = blockchain.getSocket(); + socket.emit('connect_error'); }); blockchain.on('disconnect', function() { done(); diff --git a/views/open.html b/views/open.html index f9222e99e..8cf125ff2 100644 --- a/views/open.html +++ b/views/open.html @@ -1,7 +1,7 @@
- Authenticating and looking for peers... + Connecting...
From bd78c758aaf986b47c9c8c9e397e95c43acc6d0d Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Tue, 9 Sep 2014 13:46:31 -0300 Subject: [PATCH 02/20] fix typo --- js/services/controllerUtils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/services/controllerUtils.js b/js/services/controllerUtils.js index 5a339a165..a5ecf83d2 100644 --- a/js/services/controllerUtils.js +++ b/js/services/controllerUtils.js @@ -312,7 +312,7 @@ angular.module('copayApp.services') var allAddrs = $rootScope.addrInfos; var newAddrs = []; - for:(var i in allAddrs) { + for (var i in allAddrs) { var a = allAddrs[i]; if (!currentAddrs[a.addressStr] && !a.isChange) newAddrs.push(a.addressStr); From b5b7acd5a46da33c9c3de916d48b35bae3e0186d Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Tue, 9 Sep 2014 15:30:21 -0300 Subject: [PATCH 03/20] move blockchain event handles to wallet --- js/models/blockchain/Insight.js | 7 +- js/models/core/Wallet.js | 49 +++++++-- js/models/network/Async.js | 49 +++++---- js/services/controllerUtils.js | 185 +++++++++++++++----------------- 4 files changed, 160 insertions(+), 130 deletions(-) diff --git a/js/models/blockchain/Insight.js b/js/models/blockchain/Insight.js index 67b95fd7c..14825963d 100644 --- a/js/models/blockchain/Insight.js +++ b/js/models/blockchain/Insight.js @@ -124,7 +124,12 @@ Insight.prototype.requestPost = function(path, data, cb) { } Insight.prototype.destroy = function() { - this.getSocket().destroy(); + +console.log('[Insight.js.127] INSIGHT destroy' ); //TODO + var socket = this.getSocket(); + this.socket.disconnect(); + this.socket.removeAllListeners(); + this.socket = null; this.subscribed = {}; this.status = this.STATUS.DESTROYED; this.removeAllListeners(); diff --git a/js/models/core/Wallet.js b/js/models/core/Wallet.js index 60e2a6ca5..1b35a85ba 100644 --- a/js/models/core/Wallet.js +++ b/js/models/core/Wallet.js @@ -633,7 +633,7 @@ Wallet.decodeSecret = function(secretB) { var secretNumber = secret.slice(33, 38); return { pubKey: pubKeyBuf.toString('hex'), - secretNumber : secretNumber.toString('hex') + secretNumber: secretNumber.toString('hex') } }; @@ -645,6 +645,24 @@ Wallet.prototype._lockIncomming = function() { this.network.lockIncommingConnections(this.publicKeyRing.getAllCopayerIds()); }; + + +Wallet.prototype._setBlockchainListeners = function() { + var self = this; + this.blockchain.on('connect', self.emit.bind(self,'networkReconnected')); + this.blockchain.on('disconnect', self.emit.bind(self,'networkError')); + + this.blockchain.on('tx', function(tx) { + self.emit('tx', tx.address); + }); + + if (!self.spendUnconfirmed) { + self.blockchain.on('block', self.emit.bind(self,'balanceUpdated')); + } +} + + + /** * @desc Sets up the networking with other peers. * @@ -682,7 +700,12 @@ Wallet.prototype.netStart = function() { this._lockIncomming(); } + net.on('connect_error', function() { + self.emit('connectionError'); + }); + net.start(startOpts, function() { + self._setBlockchainListeners(); self.emit('ready', net.getPeer()); setTimeout(function() { self.emit('publicKeyRingUpdated', true); @@ -866,7 +889,7 @@ Wallet.prototype.send = function(recipients, obj) { */ Wallet.prototype.sendAllTxProposals = function(recipients) { var ntxids = this.txProposals.getNtxids(), - that = this; + that = this; _.each(ntxids, function(ntxid, key) { that.sendTxProposal(ntxid, recipients); }); @@ -1872,7 +1895,9 @@ Wallet.prototype.getAddressesInfo = function(opts) { */ Wallet.prototype.addressIsOwn = function(addrStr, opts) { var addrList = this.getAddressesStr(opts); - return _.any(addrList, function(value) { return value === addrStr; }); + return _.any(addrList, function(value) { + return value === addrStr; + }); }; @@ -1973,7 +1998,7 @@ Wallet.prototype.getUnspent = function(cb) { Wallet.prototype.removeTxWithSpentInputs = function(cb) { var self = this; - cb = cb || function () {}; + cb = cb || function() {}; var txps = []; var maxRejectCount = this.maxRejectCount(); @@ -1986,9 +2011,13 @@ Wallet.prototype.removeTxWithSpentInputs = function(cb) { } var inputs = []; - txps.forEach(function (txp) { - txp.builder.utxos.forEach(function (utxo) { - inputs.push({ ntxid: txp.ntxid, txid: utxo.txid, vout: utxo.vout }); + txps.forEach(function(txp) { + txp.builder.utxos.forEach(function(utxo) { + inputs.push({ + ntxid: txp.ntxid, + txid: utxo.txid, + vout: utxo.vout + }); }); }); if (inputs.length === 0) @@ -1999,13 +2028,13 @@ Wallet.prototype.removeTxWithSpentInputs = function(cb) { this.blockchain.getUnspent(this.getAddressesStr(), function(err, unspentList) { if (err) return cb(err); - unspentList.forEach(function (unspent) { - inputs.forEach(function (input) { + unspentList.forEach(function(unspent) { + inputs.forEach(function(input) { input.unspent = input.unspent || (input.txid === unspent.txid && input.vout === unspent.vout); }); }); - inputs.forEach(function (input) { + inputs.forEach(function(input) { if (!input.unspent) { proposalsChanged = true; self.txProposals.deleteOne(input.ntxid); diff --git a/js/models/network/Async.js b/js/models/network/Async.js index ad4a5630e..52b434e12 100644 --- a/js/models/network/Async.js +++ b/js/models/network/Async.js @@ -33,14 +33,14 @@ Network.prototype.cleanUp = function() { this.allowedCopayerIds = null; this.isInboundPeerAuth = []; this.copayerForPeer = {}; - this.connections = {}; this.criticalErr = ''; - this.removeAllListeners(); if (this.socket) { - this.socket.removeAllListeners(); +console.log('[Async.js.39] DISCONNECT'); //TODO this.socket.disconnect(); + this.socket.removeAllListeners(); this.socket = null; } + this.removeAllListeners(); }; Network.parent = EventEmitter; @@ -86,11 +86,6 @@ Network.prototype._sendHello = function(copayerId,secretNumber) { Network.prototype._deletePeer = function(peerId) { delete this.isInboundPeerAuth[peerId]; delete this.copayerForPeer[peerId]; - - if (this.connections[peerId]) { - this.connections[peerId].close(); - } - delete this.connections[peerId]; this.connectedPeers = Network._arrayRemove(peerId, this.connectedPeers); }; @@ -219,9 +214,27 @@ Network.prototype._onMessage = function(enc) { } }; -Network.prototype._setupConnectionHandlers = function(cb) { +Network.prototype._setupConnectionHandlers = function(opts, cb) { preconditions.checkState(this.socket); var self = this; + + self.socket.on('connect_error', function(m) { + + // If socket is not started, destroy it and emit and error + // If it is started, socket.io will try to reconnect. + if (!self.started) { + self.emit('connect_error'); + self.cleanUp(); + } + }); + + self.socket.on('subscribed', function(m) { + var fromTs = (opts.lastTimestamp||0) + 1; + self.socket.emit('sync', fromTs); + self.started = true; + }); + + self.socket.on('message', function(m) { // delay execution, to improve error handling setTimeout(function() { @@ -233,14 +246,17 @@ Network.prototype._setupConnectionHandlers = function(cb) { self.socket.on('no messages', self.emit.bind(self, 'no messages')); self.socket.on('connect', function() { + var pubkey = self.getKey().public.toString('hex'); + self.socket.emit('subscribe', pubkey); self.socket.on('disconnect', function() { - var pubKey = self.getKey().public.toString('hex'); - self.socket.emit('subscribe', pubKey); + self.socket.emit('subscribe', pubkey); }); if (typeof cb === 'function') cb(); }); + + }; Network.prototype._onError = function(err) { @@ -293,20 +309,11 @@ Network.prototype.start = function(opts, openCallback) { if (this.started) return openCallback(); this.privkey = opts.privkey; - var pubkey = this.getKey().public.toString('hex'); this.setCopayerId(opts.copayerId); this.maxPeers = opts.maxPeers || this.maxPeers; this.socket = this.createSocket(); - this._setupConnectionHandlers(openCallback); - this.socket.emit('subscribe', pubkey); - - var fromTs = opts.lastTimestamp + 1; - var self = this; - self.socket.on('subscribed', function(m) { - self.socket.emit('sync', fromTs); - self.started = true; - }); + this._setupConnectionHandlers(opts, openCallback); }; Network.prototype.createSocket = function() { diff --git a/js/services/controllerUtils.js b/js/services/controllerUtils.js index a5ecf83d2..71bd5ced4 100644 --- a/js/services/controllerUtils.js +++ b/js/services/controllerUtils.js @@ -40,15 +40,96 @@ angular.module('copayApp.services') } }; - root.installStartupHandlers = function(wallet, $scope) { - wallet.on('connectionError', function() { - var message = "Looks like you are already connected to this wallet, please logout and try importing it again."; - notification.error('PeerJS Error', message); + root.installWalletHandlers = function(w, $scope) { + w.on('connectionError', function() { + var message = "Could not connect to the Insight server. Check your settings and network configuration"; + notification.error('Networking Error', message); root.onErrorDigest($scope); }); - wallet.on('ready', function() { + w.on('ready', function() { $scope.loading = false; }); + + + w.on('corrupt', function(peerId) { + notification.error('Error', 'Received corrupt message from ' + peerId); + }); + w.on('ready', function(myPeerID) { + $rootScope.wallet = w; + if ($rootScope.pendingPayment) { + $location.path('send'); + } else { + $location.path('receive'); + } + }); + + w.on('publicKeyRingUpdated', function(dontDigest) { + root.updateGlobalAddresses(); + if (!dontDigest) { + $rootScope.$digest(); + } + }); + + w.on('tx', function() { + notification.funds('Funds received!', tx.address); + root.updateBalance(function() { + $rootScope.$digest(); + }); + }); + + w.on('balanceUpdated', function() { + root.updateBalance(function() { + $rootScope.$digest(); + }); + }); + + w.on('networkReconnected', function() { + $rootScope.reconnecting = false; + root.updateBalance(function() { + $rootScope.$digest(); + }); + }); + + w.on('networkError', function() { + $rootScope.reconnecting = true; + $rootScope.$digest(); + }); + + w.on('txProposalsUpdated', function(dontDigest) { + root.updateTxs(); + // give sometime to the tx to propagate. + $timeout(function() { + root.updateBalance(function() { + if (!dontDigest) { + $rootScope.$digest(); + } + }); + }, 3000); + }); + w.on('txProposalEvent', function(e) { + var user = w.publicKeyRing.nicknameForCopayer(e.cId); + switch (e.type) { + case 'signed': + notification.info('Transaction Update', 'A transaction was signed by ' + user); + break; + case 'rejected': + notification.info('Transaction Update', 'A transaction was rejected by ' + user); + break; + case 'corrupt': + notification.error('Transaction Error', 'Received corrupt transaction from ' + user); + break; + } + }); + w.on('addressBookUpdated', function(dontDigest) { + if (!dontDigest) { + $rootScope.$digest(); + } + }); + w.on('connect', function(peerID) { + $rootScope.$digest(); + }); + w.on('close', root.onErrorDigest); + w.on('locked', root.onErrorDigest.bind(this)); }; root.setupRootVariables = function() { @@ -88,69 +169,9 @@ angular.module('copayApp.services') root.startNetwork = function(w, $scope) { root.setupRootVariables(); - root.installStartupHandlers(w, $scope); + root.installWalletHandlers(w, $scope); root.updateGlobalAddresses(); - notification.enableHtml5Mode(); // for chrome: if support, enable it - - w.on('corrupt', function(peerId) { - notification.error('Error', 'Received corrupt message from ' + peerId); - }); - w.on('ready', function(myPeerID) { - $rootScope.wallet = w; - root.setConnectionListeners($rootScope.wallet); - - if ($rootScope.pendingPayment) { - $location.path('send'); - } else { - $location.path('receive'); - } - }); - - w.on('publicKeyRingUpdated', function(dontDigest) { - root.updateGlobalAddresses(); - if (!dontDigest) { - $rootScope.$digest(); - } - }); - w.on('txProposalsUpdated', function(dontDigest) { - root.updateTxs(); - // give sometime to the tx to propagate. - $timeout(function() { - root.updateBalance(function() { - if (!dontDigest) { - $rootScope.$digest(); - } - }); - }, 3000); - }); - w.on('txProposalEvent', function(e) { - var user = w.publicKeyRing.nicknameForCopayer(e.cId); - switch (e.type) { - case 'signed': - notification.info('Transaction Update', 'A transaction was signed by ' + user); - break; - case 'rejected': - notification.info('Transaction Update', 'A transaction was rejected by ' + user); - break; - case 'corrupt': - notification.error('Transaction Error', 'Received corrupt transaction from ' + user); - break; - } - }); - w.on('addressBookUpdated', function(dontDigest) { - if (!dontDigest) { - $rootScope.$digest(); - } - }); - w.on('connectionError', function(msg) { - root.onErrorDigest(null, msg); - }); - w.on('connect', function(peerID) { - $rootScope.$digest(); - }); - w.on('close', root.onErrorDigest); - w.on('locked', root.onErrorDigest.bind(this)); w.netStart(); }; @@ -272,38 +293,6 @@ angular.module('copayApp.services') }); } - root.setConnectionListeners = function(wallet) { - wallet.blockchain.on('connect', function(attempts) { - if (attempts == 0) return; - notification.success('Networking restored', 'Connection to Insight re-established'); - $rootScope.reconnecting = false; - root.updateBalance(function() { - $rootScope.$digest(); - }); - }); - - wallet.blockchain.on('disconnect', function() { - notification.error('Networking problem', 'Connection to Insight lost, trying to reconnect...'); - $rootScope.reconnecting = true; - $rootScope.$digest(); - }); - - wallet.blockchain.on('tx', function(tx) { - notification.funds('Funds received!', tx.address); - root.updateBalance(function() { - $rootScope.$digest(); - }); - }); - - if (!$rootScope.wallet.spendUnconfirmed) { - wallet.blockchain.on('block', function(block) { - root.updateBalance(function() { - $rootScope.$digest(); - }); - }); - } - } - root.updateGlobalAddresses = function() { if (!$rootScope.wallet) return; From 255affe382952b681f36eb81a8fb8cba198b1abd Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Tue, 9 Sep 2014 15:40:12 -0300 Subject: [PATCH 04/20] fix received --- index.html | 2 +- js/models/core/Wallet.js | 1 + js/services/controllerUtils.js | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/index.html b/index.html index 26ee2c92f..e6f34fd00 100644 --- a/index.html +++ b/index.html @@ -15,7 +15,7 @@
- Attempting to reconnect... + Network Error. Attempting to reconnect...