From ad6102c7cef79f0d607ec24d37fa090c251a5a02 Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Wed, 12 Aug 2015 18:38:38 -0300 Subject: [PATCH 1/3] fix stub --- test/integration/server.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/integration/server.js b/test/integration/server.js index b6be0e9..da43d8b 100644 --- a/test/integration/server.js +++ b/test/integration/server.js @@ -196,9 +196,10 @@ helpers.stubHistory = function(txs) { helpers.stubFeeLevels = function(levels) { blockchainExplorer.estimateFee = function(nbBlocks, cb) { - return cb(null, { - feePerKB: levels[nbBlocks] / 1e8 - }); + var result = _.zipObject(_.map(_.pick(levels, nbBlocks), function(fee, n) { + return [+n, fee > 0 ? fee / 1e8 : fee]; + })); + return cb(null, result); }; }; From 4c7e7a6d2feb63a42a6818497034d020a2800c56 Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Wed, 12 Aug 2015 18:39:09 -0300 Subject: [PATCH 2/3] send list of nbBlocks to insight --- lib/blockchainexplorers/insight.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/blockchainexplorers/insight.js b/lib/blockchainexplorers/insight.js index 91fad8c..9eb9d67 100644 --- a/lib/blockchainexplorers/insight.js +++ b/lib/blockchainexplorers/insight.js @@ -108,7 +108,7 @@ Insight.prototype.getAddressActivity = function(addresses, cb) { Insight.prototype.estimateFee = function(nbBlocks, cb) { var url = this.url + '/api/utils/estimatefee'; if (nbBlocks) { - url += '?nbBlocks=' + nbBlocks; + url += '?nbBlocks=' + [].concat(nbBlocks).join(','); } var args = { From bb0e8d70931336453859b46eb6f09448a599bb4a Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Wed, 12 Aug 2015 18:39:19 -0300 Subject: [PATCH 3/3] change fee sampling --- lib/server.js | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/lib/server.js b/lib/server.js index cd85a5f..7c19bf9 100644 --- a/lib/server.js +++ b/lib/server.js @@ -752,23 +752,22 @@ WalletService.prototype.getBalance = function(opts, cb) { WalletService.prototype._sampleFeeLevels = function(network, points, cb) { var self = this; - // TODO: cache blockexplorer data var bc = self._getBlockchainExplorer(network); - async.map(points, function(p, next) { - bc.estimateFee(p, function(err, result) { - if (err) { - log.error('Error estimating fee', err); - return next(err); - } - var feePerKB = _.isObject(result) ? +(result.feePerKB) : -1; + bc.estimateFee(points, function(err, result) { + if (err) { + log.error('Error estimating fee', err); + return cb(err); + } + + var levels = _.zipObject(_.map(points, function(p) { + var feePerKB = _.isObject(result) ? +result[p] : -1; if (feePerKB < 0) { log.warn('Could not compute fee estimation (nbBlocks=' + p + ')'); } - return next(null, [p, Utils.strip(feePerKB * 1e8)]); - }); - }, function(err, results) { - if (err) return cb(err); - return cb(null, _.zipObject(results)); + return [p, Utils.strip(feePerKB * 1e8)]; + })); + + return cb(null, levels); }); };