Merge pull request #346 from isocolsky/estimate_multi_fee
Get multiple values for estimatefee on single request
This commit is contained in:
commit
483dde1d81
@ -4,21 +4,18 @@
|
|||||||
* Module dependencies.
|
* Module dependencies.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var Utils = require('../models/Utils'),
|
var _ = require('lodash');
|
||||||
common = require('./common');
|
|
||||||
|
var Utils = require('../models/Utils');
|
||||||
|
var common = require('./common');
|
||||||
|
|
||||||
exports.estimateFee = function(req, res) {
|
exports.estimateFee = function(req, res) {
|
||||||
|
var args = req.query.nbBlocks || '2';
|
||||||
|
var nbBlocks = args.split(',');
|
||||||
|
|
||||||
var nbBlocks = +req.query.nbBlocks || 2;
|
|
||||||
var utilsObject = new Utils();
|
var utilsObject = new Utils();
|
||||||
|
utilsObject.estimateFee(nbBlocks, function(err, fees) {
|
||||||
var returnJsonp = function(err) {
|
if (err) return common.handleErrors(err, res);
|
||||||
if (err || !utilsObject)
|
res.jsonp(fees);
|
||||||
return common.handleErrors(err, res);
|
});
|
||||||
else {
|
|
||||||
res.jsonp(utilsObject);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
utilsObject.estimateFee(nbBlocks, returnJsonp);
|
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
//var imports = require('soop').imports();
|
//var imports = require('soop').imports();
|
||||||
|
var _ = require('lodash');
|
||||||
|
var async = require('async');
|
||||||
|
|
||||||
var bitcore = require('bitcore');
|
var bitcore = require('bitcore');
|
||||||
var RpcClient = bitcore.RpcClient;
|
var RpcClient = bitcore.RpcClient;
|
||||||
@ -8,14 +10,16 @@ var rpc = new RpcClient(config.bitcoind);
|
|||||||
|
|
||||||
function Utils() {}
|
function Utils() {}
|
||||||
|
|
||||||
Utils.prototype.estimateFee = function(n, next) {
|
Utils.prototype.estimateFee = function(nbBlocks, cb) {
|
||||||
var that = this;
|
var that = this;
|
||||||
|
|
||||||
rpc.estimateFee(n, function(err, info) {
|
async.map([].concat(nbBlocks), function(n, next) {
|
||||||
if (err) return next(err);
|
rpc.estimateFee(+n, function(err, info) {
|
||||||
|
return next(err, [n, info.result]);
|
||||||
that.feePerKB = info.result;
|
});
|
||||||
return next();
|
}, function(err, result) {
|
||||||
|
if (err) return cb(err);
|
||||||
|
return cb(null, _.zipObject(result));
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user