utils: update estimatefee
This commit is contained in:
parent
e1df171f95
commit
6e5dbfd22a
19
lib/utils.js
19
lib/utils.js
@ -1,5 +1,8 @@
|
||||
'use strict';
|
||||
|
||||
var _ = require('lodash');
|
||||
var async = require('async');
|
||||
var common = require('./common');
|
||||
|
||||
function UtilsController(node) {
|
||||
this.node = node;
|
||||
@ -10,14 +13,22 @@ UtilsController.prototype.estimateFee = function(req, res) {
|
||||
var args = req.query.nbBlocks || '2';
|
||||
var nbBlocks = args.split(',');
|
||||
|
||||
var result = nbBlocks.map(function(n) {
|
||||
async.map(nbBlocks, function(n, next) {
|
||||
var num = parseInt(n);
|
||||
// Insight and Bitcoin JSON-RPC return bitcoin for this value (instead of satoshis).
|
||||
var fee = self.node.services.bitcoind.estimateFee(num) / 1e8;
|
||||
return [num, fee];
|
||||
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));
|
||||
});
|
||||
|
||||
res.jsonp(_.zipObject(result));
|
||||
};
|
||||
|
||||
module.exports = UtilsController;
|
||||
|
||||
@ -10,12 +10,12 @@ describe('Utils', function() {
|
||||
var node = {
|
||||
services: {
|
||||
bitcoind: {
|
||||
estimateFee: function(blocks) {
|
||||
estimateFee: function(blocks, callback) {
|
||||
switch(blocks) {
|
||||
case 1:
|
||||
return 1000;
|
||||
case 3:
|
||||
return 3000;
|
||||
case 1:
|
||||
return callback(null, 1000 / 1e8);
|
||||
case 3:
|
||||
return callback(null, 3000 / 1e8);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user