From 533ddaf3b44fb8cdedde99351df1cdd40c98d916 Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Thu, 7 Apr 2016 12:00:08 -0300 Subject: [PATCH 1/3] remove blockchain explorer dependency from email service --- lib/emailservice.js | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/lib/emailservice.js b/lib/emailservice.js index bb4c5b003fe..34777f7d5c6 100644 --- a/lib/emailservice.js +++ b/lib/emailservice.js @@ -14,7 +14,6 @@ var Utils = require('./common/utils'); var Storage = require('./storage'); var MessageBroker = require('./messagebroker'); var Lock = require('./lock'); -var BlockchainExplorer = require('./blockchainexplorer'); var Model = require('./model'); @@ -99,27 +98,6 @@ EmailService.prototype.start = function(opts, cb) { self.lock = opts.lock || new Lock(opts.lockOpts); done(); }, - function(done) { - self.explorers = _.indexBy(_.map(['livenet', 'testnet'], function(network) { - var explorer; - if (opts.blockchainExplorers) { - explorer = opts.blockchainExplorers[network]; - } else { - var config = {} - if (opts.blockchainExplorerOpts && opts.blockchainExplorerOpts[network]) { - config = opts.blockchainExplorerOpts[network]; - } - var explorer = new BlockchainExplorer({ - provider: config.provider, - network: network, - url: config.url, - }); - } - $.checkState(explorer); - return explorer; - }), 'network'); - done(); - }, function(done) { self.mailer = opts.mailer || nodemailer.createTransport(opts.emailOpts); done(); From 4c9b685e1c9b2319dc1ce42f132768c2f869ba86 Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Thu, 7 Apr 2016 14:52:23 -0300 Subject: [PATCH 2/3] add userAgent opt --- lib/blockchainexplorer.js | 3 ++- lib/blockchainexplorers/insight.js | 31 ++++++++++++++++++------------ lib/blockchainmonitor.js | 3 +++ lib/server.js | 1 + 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/lib/blockchainexplorer.js b/lib/blockchainexplorer.js index a0f40728d29..428b9a97e63 100644 --- a/lib/blockchainexplorer.js +++ b/lib/blockchainexplorer.js @@ -30,7 +30,8 @@ function BlockChainExplorer(opts) { return new Insight({ network: network, url: url, - apiPrefix: opts.apiPrefix + apiPrefix: opts.apiPrefix, + userAgent: opts.userAgent, }); default: throw new Error('Provider ' + provider + ' not supported.'); diff --git a/lib/blockchainexplorers/insight.js b/lib/blockchainexplorers/insight.js index bdc68b725c6..f3778de2d77 100644 --- a/lib/blockchainexplorers/insight.js +++ b/lib/blockchainexplorers/insight.js @@ -15,6 +15,7 @@ function Insight(opts) { this.apiPrefix = opts.apiPrefix || '/api'; this.network = opts.network || 'livenet'; this.hosts = opts.url; + this.userAgent = opts.userAgent || 'bws'; }; @@ -27,6 +28,18 @@ var _parseErr = function(err, res) { return "Error querying the blockchain"; }; +Insight.prototype._doRequest = function(args, cb) { + var opts = { + hosts: this.hosts, + headers: { + 'User-Agent': this.userAgent, + } + }; + console.log('*** [insight.js ln38] opts:', opts); // TODO + + requestList(_.defaults(args, opts), cb); +}; + Insight.prototype.getConnectionInfo = function() { return 'Insight (' + this.network + ') @ ' + this.hosts; }; @@ -38,14 +51,13 @@ Insight.prototype.getUtxos = function(addresses, cb) { var url = this.url + this.apiPrefix + '/addrs/utxo'; var args = { method: 'POST', - hosts: this.hosts, path: this.apiPrefix + '/addrs/utxo', json: { addrs: [].concat(addresses).join(',') }, }; - requestList(args, function(err, res, unspent) { + this._doRequest(args, function(err, res, unspent) { if (err || res.statusCode !== 200) return cb(_parseErr(err, res)); return cb(null, unspent); }); @@ -57,14 +69,13 @@ Insight.prototype.getUtxos = function(addresses, cb) { Insight.prototype.broadcast = function(rawTx, cb) { var args = { method: 'POST', - hosts: this.hosts, path: this.apiPrefix + '/tx/send', json: { rawtx: rawTx }, }; - requestList(args, function(err, res, body) { + this._doRequest(args, function(err, res, body) { if (err || res.statusCode !== 200) return cb(_parseErr(err, res)); return cb(null, body ? body.txid : null); }); @@ -73,12 +84,11 @@ Insight.prototype.broadcast = function(rawTx, cb) { Insight.prototype.getTransaction = function(txid, cb) { var args = { method: 'GET', - hosts: this.hosts, path: this.apiPrefix + '/tx/' + txid, json: true, }; - requestList(args, function(err, res, tx) { + this._doRequest(args, function(err, res, tx) { if (res && res.statusCode == 404) return cb(); if (err || res.statusCode !== 200) return cb(_parseErr(err, res)); @@ -94,14 +104,13 @@ Insight.prototype.getTransactions = function(addresses, from, to, cb) { var args = { method: 'POST', - hosts: this.hosts, path: this.apiPrefix + '/addrs/txs' + (qs.length > 0 ? '?' + qs.join('&') : ''), json: { addrs: [].concat(addresses).join(',') }, }; - requestList(args, function(err, res, txs) { + this._doRequest(args, function(err, res, txs) { if (err || res.statusCode !== 200) return cb(_parseErr(err, res)); if (_.isObject(txs) && txs.items) @@ -119,12 +128,11 @@ Insight.prototype.getAddressActivity = function(address, cb) { var args = { method: 'GET', - hosts: this.hosts, path: self.apiPrefix + '/addr/' + address, json: true, }; - requestList(args, function(err, res, result) { + this._doRequest(args, function(err, res, result) { if (res && res.statusCode == 404) return cb(); if (err || res.statusCode !== 200) return cb(_parseErr(err, res)); @@ -142,11 +150,10 @@ Insight.prototype.estimateFee = function(nbBlocks, cb) { var args = { method: 'GET', - hosts: this.hosts, path: path, json: true, }; - requestList(args, function(err, res, body) { + this._doRequest(args, function(err, res, body) { if (err || res.statusCode !== 200) return cb(_parseErr(err, res)); return cb(null, body); }); diff --git a/lib/blockchainmonitor.js b/lib/blockchainmonitor.js index 938830b8c57..59e29011f49 100644 --- a/lib/blockchainmonitor.js +++ b/lib/blockchainmonitor.js @@ -13,6 +13,8 @@ var Lock = require('./lock'); var Notification = require('./model/notification'); +var WalletService = require('./server'); + function BlockchainMonitor() {}; BlockchainMonitor.prototype.start = function(opts, cb) { @@ -36,6 +38,7 @@ BlockchainMonitor.prototype.start = function(opts, cb) { provider: config.provider, network: network, url: config.url, + userAgent: WalletService.getServiceVersion(), }); } $.checkState(explorer); diff --git a/lib/server.js b/lib/server.js index d07ec6672de..d172b05ca55 100644 --- a/lib/server.js +++ b/lib/server.js @@ -864,6 +864,7 @@ WalletService.prototype._getBlockchainExplorer = function(network) { // TODO: provider should be configurable opts.provider = 'insight'; opts.network = network; + opts.userAgent = WalletService.getServiceVersion(); this.blockchainExplorer = new BlockchainExplorer(opts); } From 017d64c76da4e20e56ec5f0392c1acdf6cafcc21 Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Thu, 7 Apr 2016 15:03:00 -0300 Subject: [PATCH 3/3] remove log strings --- lib/blockchainexplorers/insight.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/blockchainexplorers/insight.js b/lib/blockchainexplorers/insight.js index f3778de2d77..816f27d1923 100644 --- a/lib/blockchainexplorers/insight.js +++ b/lib/blockchainexplorers/insight.js @@ -35,8 +35,6 @@ Insight.prototype._doRequest = function(args, cb) { 'User-Agent': this.userAgent, } }; - console.log('*** [insight.js ln38] opts:', opts); // TODO - requestList(_.defaults(args, opts), cb); };