Skip to content

Commit 483dde1

Browse files
committed
Merge pull request #346 from isocolsky/estimate_multi_fee
Get multiple values for estimatefee on single request
2 parents 74c27b2 + c1210ce commit 483dde1

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

app/controllers/utils.js

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,18 @@
44
* Module dependencies.
55
*/
66

7-
var Utils = require('../models/Utils'),
8-
common = require('./common');
7+
var _ = require('lodash');
8+
9+
var Utils = require('../models/Utils');
10+
var common = require('./common');
911

1012
exports.estimateFee = function(req, res) {
13+
var args = req.query.nbBlocks || '2';
14+
var nbBlocks = args.split(',');
1115

12-
var nbBlocks = +req.query.nbBlocks || 2;
1316
var utilsObject = new Utils();
14-
15-
var returnJsonp = function(err) {
16-
if (err || !utilsObject)
17-
return common.handleErrors(err, res);
18-
else {
19-
res.jsonp(utilsObject);
20-
}
21-
};
22-
23-
utilsObject.estimateFee(nbBlocks, returnJsonp);
17+
utilsObject.estimateFee(nbBlocks, function(err, fees) {
18+
if (err) return common.handleErrors(err, res);
19+
res.jsonp(fees);
20+
});
2421
};

app/models/Utils.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22
//var imports = require('soop').imports();
3+
var _ = require('lodash');
4+
var async = require('async');
35

46
var bitcore = require('bitcore');
57
var RpcClient = bitcore.RpcClient;
@@ -8,14 +10,16 @@ var rpc = new RpcClient(config.bitcoind);
810

911
function Utils() {}
1012

11-
Utils.prototype.estimateFee = function(n, next) {
13+
Utils.prototype.estimateFee = function(nbBlocks, cb) {
1214
var that = this;
1315

14-
rpc.estimateFee(n, function(err, info) {
15-
if (err) return next(err);
16-
17-
that.feePerKB = info.result;
18-
return next();
16+
async.map([].concat(nbBlocks), function(n, next) {
17+
rpc.estimateFee(+n, function(err, info) {
18+
return next(err, [n, info.result]);
19+
});
20+
}, function(err, result) {
21+
if (err) return cb(err);
22+
return cb(null, _.zipObject(result));
1923
});
2024
};
2125

0 commit comments

Comments
 (0)