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';
|
'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;
|
||||||
|
|||||||
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user