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 48d2a689b..8f8ebd41e 100644 --- a/index.html +++ b/index.html @@ -849,6 +849,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..46afa817b 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,7 @@ Insight.prototype._requestNode = function(options, callback) { Insight.prototype._requestBrowser = function(options, callback) { var request = new XMLHttpRequest(); - - // TODO: Normalize URL - var url = 'http://' + options.host; + var url = (options.schema || 'http') + '://' + options.host; 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) { 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",