utils: update estimatefee

This commit is contained in:
Braydon Fuller 2016-04-20 14:07:29 -04:00
parent e1df171f95
commit 6e5dbfd22a
2 changed files with 20 additions and 9 deletions

View File

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

View File

@ -10,12 +10,12 @@ describe('Utils', function() {
var node = { var node = {
services: { services: {
bitcoind: { bitcoind: {
estimateFee: function(blocks) { estimateFee: function(blocks, callback) {
switch(blocks) { switch(blocks) {
case 1: case 1:
return 1000; return callback(null, 1000 / 1e8);
case 3: case 3:
return 3000; return callback(null, 3000 / 1e8);
} }
} }
} }