Browse Source

add REST endpoint

activeAddress
Ivan Socolsky 9 years ago
parent
commit
15234bee6b
  1. 4
      lib/blockchainexplorers/insight.js
  2. 10
      lib/expressapp.js
  3. 5
      lib/server.js

4
lib/blockchainexplorers/insight.js

@ -114,11 +114,11 @@ Insight.prototype.estimateFee = function(nbBlocks, cb) {
var args = { var args = {
method: 'GET', method: 'GET',
url: url, url: url,
json: true,
}; };
request(args, function(err, res, body) { request(args, function(err, res, body) {
if (err || res.statusCode !== 200) return cb(err || res); if (err || res.statusCode !== 200) return cb(err || res);
return cb(null, body.feePerKB); return cb(null, body);
}); });
}; };

10
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) { router.post('/v1/txproposals/:id/signatures/', function(req, res) {
getServerWithAuth(req, res, function(server) { getServerWithAuth(req, res, function(server) {
req.body.txProposalId = req.params['id']; req.body.txProposalId = req.params['id'];

5
lib/server.js

@ -777,10 +777,11 @@ WalletService.prototype._sampleFeeLevels = function(network, points, cb) {
log.error('Error estimating fee', err); log.error('Error estimating fee', err);
return next(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 + ')'); 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) { }, function(err, results) {
if (err) return cb(err); if (err) return cb(err);

Loading…
Cancel
Save