change fee sampling

This commit is contained in:
Ivan Socolsky 2015-08-12 18:39:19 -03:00
parent 4c7e7a6d2f
commit bb0e8d7093
1 changed files with 12 additions and 13 deletions

View File

@ -752,23 +752,22 @@ WalletService.prototype.getBalance = function(opts, cb) {
WalletService.prototype._sampleFeeLevels = function(network, points, cb) {
var self = this;
// TODO: cache blockexplorer data
var bc = self._getBlockchainExplorer(network);
async.map(points, function(p, next) {
bc.estimateFee(p, function(err, result) {
bc.estimateFee(points, function(err, result) {
if (err) {
log.error('Error estimating fee', err);
return next(err);
return cb(err);
}
var feePerKB = _.isObject(result) ? +(result.feePerKB) : -1;
var levels = _.zipObject(_.map(points, function(p) {
var feePerKB = _.isObject(result) ? +result[p] : -1;
if (feePerKB < 0) {
log.warn('Could not compute fee estimation (nbBlocks=' + p + ')');
}
return next(null, [p, Utils.strip(feePerKB * 1e8)]);
});
}, function(err, results) {
if (err) return cb(err);
return cb(null, _.zipObject(results));
return [p, Utils.strip(feePerKB * 1e8)];
}));
return cb(null, levels);
});
};