From d4805b925de158761f11d871dd2a8591df274f0f Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Thu, 26 Jun 2014 18:47:27 -0300 Subject: [PATCH 1/3] SSL and livenet config by default --- config.js | 12 +++--- index.html | 3 ++ js/controllers/settings.js | 15 ++++++-- js/models/blockchain/Insight.js | 68 +++++++++++---------------------- js/services/socket.js | 9 +++-- 5 files changed, 51 insertions(+), 56 deletions(-) diff --git a/config.js b/config.js index 5f33dfdfe..f65af3ff4 100644 --- a/config.js +++ b/config.js @@ -1,7 +1,7 @@ 'use strict'; var defaultConfig = { // DEFAULT network (livenet or testnet) - networkName: 'testnet', + networkName: 'livenet', // DEFAULT unit: Bit unitName: 'bits', @@ -96,14 +96,16 @@ var defaultConfig = { // blockchain service API config blockchain: { - host: 'test.insight.is', - port: 80, + schema: 'https', + host: 'insight.bitpay.com', + port: 443, retryDelay: 1000, }, // socket service API config socket: { - host: 'test.insight.is', - port: 80, + schema: 'https', + host: 'insight.bitpay.com', + port: 443, // will duplicate itself after each try reconnectDelay: 500, }, diff --git a/index.html b/index.html index 0381a52b0..f837a3070 100644 --- a/index.html +++ b/index.html @@ -854,6 +854,9 @@ + + +
PeerJS server diff --git a/js/controllers/settings.js b/js/controllers/settings.js index 78a5f5762..4f027e15d 100644 --- a/js/controllers/settings.js +++ b/js/controllers/settings.js @@ -7,6 +7,7 @@ angular.module('copayApp.controllers').controller('SettingsController', $scope.networkName = config.networkName; $scope.insightHost = config.blockchain.host; $scope.insightPort = config.blockchain.port; + $scope.insightSecure = config.blockchain.schema === 'https'; $scope.networkKey = config.network.key; $scope.networkHost = config.network.host; $scope.networkPort = config.network.port; @@ -39,9 +40,15 @@ angular.module('copayApp.controllers').controller('SettingsController', } $scope.$watch('networkName', function(net) { - $scope.insightHost = net === 'testnet' ? 'test.insight.is' : 'live.insight.is'; + $scope.insightHost = net === 'testnet' ? 'test-insight.bitpay.com' : 'insight.bitpay.com'; }); + + $scope.$watch('insightSecure', function(ssl) { + $scope.insightPort = ssl ? 443 : 80; + }); + + $scope.save = function() { var network = config.network; network.key = $scope.networkKey; @@ -53,11 +60,13 @@ angular.module('copayApp.controllers').controller('SettingsController', networkName: $scope.networkName, blockchain: { host: $scope.insightHost, - port: $scope.insightPort + port: $scope.insightPort, + schema: $scope.insightSecure ? 'https' : 'http', }, socket: { host: $scope.insightHost, - port: $scope.insightPort + port: $scope.insightPort, + schema: $scope.insightSecure ? 'https' : 'http', }, network: network, disableVideo: $scope.disableVideo, diff --git a/js/models/blockchain/Insight.js b/js/models/blockchain/Insight.js index 66422cf80..0ca13c397 100644 --- a/js/models/blockchain/Insight.js +++ b/js/models/blockchain/Insight.js @@ -12,7 +12,7 @@ function Insight(opts) { opts = opts || {}; this.host = opts.host || 'localhost'; this.port = opts.port || '3001'; - this.scheme = opts.scheme || 'http'; + this.schema = opts.schema || 'http'; this.retryDelay = opts.retryDelay || 5000; } @@ -62,6 +62,21 @@ function removeRepeatedElements(ar) { return r; } + +Insight.prototype._getOptions = function(method, path, data) { + return { + host: this.host, + port: this.port, + schema: this.schema, + method: method, + path: path, + data: data, + headers: { + 'Access-Control-Request-Headers': '' + } + }; +}; + Insight.prototype.getTransactions = function(addresses, cb) { var self = this; @@ -71,17 +86,7 @@ Insight.prototype.getTransactions = function(addresses, cb) { var txs = []; _asyncForEach(addresses, function(addr, callback) { - var options = { - host: self.host, - port: self.port, - scheme: self.scheme, - method: 'GET', - path: '/api/addr/' + addr, - headers: { - 'Access-Control-Request-Headers': '' - } - }; - + var options = self._getOptions('GET', '/api/addr/' + addr); self._request(options, function(err, res) { var txids_tmp = res.transactions; for (var i = 0; i < txids_tmp.length; i++) { @@ -92,16 +97,7 @@ Insight.prototype.getTransactions = function(addresses, cb) { }, function() { var clean_txids = removeRepeatedElements(txids); _asyncForEach(clean_txids, function(txid, callback2) { - var options = { - host: self.host, - port: self.port, - scheme: self.scheme, - method: 'GET', - path: '/api/tx/' + txid, - headers: { - 'Access-Control-Request-Headers': '' - } - }; + var options = self._getOptions('GET', '/api/tx/' + txid); self._request(options, function(err, res) { txs.push(res); callback2(); @@ -117,17 +113,7 @@ Insight.prototype.getUnspent = function(addresses, cb) { var all = []; - var options = { - host: this.host, - port: this.port, - scheme: this.scheme, - method: 'POST', - data: 'addrs=' + addresses.join(','), - path: '/api/addrs/utxo', - headers: { - 'Access-Control-Request-Headers': '' - } - }; + var options = this._getOptions('POST', '/api/addrs/utxo', 'addrs=' + addresses.join(',')); var self = this; this._request(options, function(err, res) { @@ -146,16 +132,7 @@ Insight.prototype.getUnspent = function(addresses, cb) { Insight.prototype.sendRawTransaction = function(rawtx, cb) { if (!rawtx) throw new Error('rawtx must be set'); - var options = { - host: this.host, - port: this.port, - method: 'POST', - path: '/api/tx/send', - data: 'rawtx=' + rawtx, - headers: { - 'Access-Control-Request-Headers': '' - } - }; + var options = this._getOptions('POST', '/api/tx/send', 'rawtx=' + rawtx); this._request(options, function(err, res) { if (err) return cb(); @@ -244,9 +221,10 @@ Insight.prototype._requestNode = function(options, callback) { Insight.prototype._requestBrowser = function(options, callback) { var request = new XMLHttpRequest(); + console.log('[Insight.js.225:options:]', options); //TODO - // TODO: Normalize URL - var url = 'http://' + options.host; + var url = (options.schema || 'http') + '://' + options.host; + console.log('[Insight.js.226:url:]', url); //TODO if (options.port !== 80) { url = url + ':' + options.port; diff --git a/js/services/socket.js b/js/services/socket.js index 99dce34b4..8e618643d 100644 --- a/js/services/socket.js +++ b/js/services/socket.js @@ -3,11 +3,14 @@ angular.module('copayApp.services').factory('Socket', function($rootScope) { var listeners = []; - var url = 'http://' + config.socket.host + ':' + config.socket.port; - var socket = io(url, { + var url = (config.socket.schema || 'http') + '://' + config.socket.host + ':' + config.socket.port; + var opts = { 'reconnection': true, 'reconnectionDelay': config.socket.reconnectDelay || 500, - }); + 'secure': config.socket.schema === 'https' ? true : false, + }; + + var socket = io(url, opts); return { on: function(event, callback) { From de0ab04de5de50a4fe72c12c593805012e6297b6 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Thu, 26 Jun 2014 21:34:22 -0300 Subject: [PATCH 2/3] 0.2.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8fde93aa3..57c6887c9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "copay", - "version": "0.1.1", + "version": "0.2.0", "description": "A multisignature wallet", "repository": { "type": "git", From 7693b27e90f77ca7b0dd8c0247568f67b46d2a4a Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Fri, 27 Jun 2014 09:42:18 -0300 Subject: [PATCH 3/3] rm console.log --- js/models/blockchain/Insight.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/js/models/blockchain/Insight.js b/js/models/blockchain/Insight.js index 0ca13c397..46afa817b 100644 --- a/js/models/blockchain/Insight.js +++ b/js/models/blockchain/Insight.js @@ -221,10 +221,7 @@ Insight.prototype._requestNode = function(options, callback) { Insight.prototype._requestBrowser = function(options, callback) { var request = new XMLHttpRequest(); - console.log('[Insight.js.225:options:]', options); //TODO - var url = (options.schema || 'http') + '://' + options.host; - console.log('[Insight.js.226:url:]', url); //TODO if (options.port !== 80) { url = url + ':' + options.port;