flosight-api/lib/utils.js
2016-04-20 14:07:29 -04:00

35 lines
810 B
JavaScript

'use strict';
var _ = require('lodash');
var async = require('async');
var common = require('./common');
function UtilsController(node) {
this.node = node;
}
UtilsController.prototype.estimateFee = function(req, res) {
var self = this;
var args = req.query.nbBlocks || '2';
var nbBlocks = args.split(',');
async.map(nbBlocks, function(n, next) {
var num = parseInt(n);
// Insight and Bitcoin JSON-RPC return bitcoin for this value (instead of satoshis).
self.node.services.bitcoind.estimateFee(num, function(err, fee) {
if (err) {
return next(err);
}
next(null, [num, fee]);
});
}, function(err, result) {
if (err) {
return common.handleErrors(err, res);
}
res.jsonp(_.zipObject(result));
});
};
module.exports = UtilsController;