add REST endpoint

This commit is contained in:
Ivan Socolsky 2015-07-17 10:32:48 -03:00
parent d8b45ea51e
commit 15234bee6b
3 changed files with 15 additions and 4 deletions

View File

@ -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);
});
};

View File

@ -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'];

View File

@ -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);