From 15234bee6b6a6de4d5ee0157fb509a18e3cc30fc Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Fri, 17 Jul 2015 10:32:48 -0300 Subject: [PATCH] add REST endpoint --- lib/blockchainexplorers/insight.js | 4 ++-- lib/expressapp.js | 10 ++++++++++ lib/server.js | 5 +++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/blockchainexplorers/insight.js b/lib/blockchainexplorers/insight.js index 9e66230..91fad8c 100644 --- a/lib/blockchainexplorers/insight.js +++ b/lib/blockchainexplorers/insight.js @@ -114,11 +114,11 @@ Insight.prototype.estimateFee = function(nbBlocks, cb) { var args = { method: 'GET', url: url, + json: true, }; - request(args, function(err, res, body) { if (err || res.statusCode !== 200) return cb(err || res); - return cb(null, body.feePerKB); + return cb(null, body); }); }; diff --git a/lib/expressapp.js b/lib/expressapp.js index eddfc8f..f35bef1 100644 --- a/lib/expressapp.js +++ b/lib/expressapp.js @@ -266,6 +266,16 @@ ExpressApp.prototype.start = function(opts, cb) { }); }); + router.get('/v1/feelevels/', function(req, res) { + var opts = {}; + if (req.query.network) opts.network = req.query.network; + var server = getServer(req, res); + server.getFeeLevels(opts, function(err, feeLevels) { + if (err) return returnError(err, res, req); + res.json(feeLevels); + }); + }); + router.post('/v1/txproposals/:id/signatures/', function(req, res) { getServerWithAuth(req, res, function(server) { req.body.txProposalId = req.params['id']; diff --git a/lib/server.js b/lib/server.js index e51e231..e0b180d 100644 --- a/lib/server.js +++ b/lib/server.js @@ -777,10 +777,11 @@ WalletService.prototype._sampleFeeLevels = function(network, points, cb) { log.error('Error estimating fee', err); return next(err); } - if (result.feePerKB < 0) { + var feePerKB = _.isObject(result) ? +(result.feePerKB) : -1; + if (feePerKB < 0) { log.warn('Could not compute fee estimation (nbBlocks=' + p + ')'); } - return next(null, [p, result.feePerKB * 1e8]); + return next(null, [p, feePerKB * 1e8]); }); }, function(err, results) { if (err) return cb(err);