|
|
@ -1148,6 +1148,7 @@ WalletService.prototype.getBalance = function(opts, cb) { |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
WalletService.prototype._sampleFeeLevels = function(network, points, cb) { |
|
|
|
var self = this; |
|
|
|
|
|
|
@ -1169,13 +1170,15 @@ WalletService.prototype._sampleFeeLevels = function(network, points, cb) { |
|
|
|
|
|
|
|
if (failed.length) { |
|
|
|
var logger = network == 'livenet' ? log.warn : log.debug; |
|
|
|
logger('Could not compute fee estimation in ' + network + ': ' + failed.join(',')); |
|
|
|
logger('Could not compute fee estimation in ' + network + ': ' + failed.join(', ') + ' blocks.'); |
|
|
|
} |
|
|
|
|
|
|
|
return cb(null, levels); |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
WalletService._feeLevelCache = {}; |
|
|
|
|
|
|
|
/** |
|
|
|
* Returns fee levels for the current state of the network. |
|
|
|
* @param {Object} opts |
|
|
@ -1191,6 +1194,8 @@ WalletService.prototype.getFeeLevels = function(opts, cb) { |
|
|
|
if (network != 'livenet' && network != 'testnet') |
|
|
|
return cb(new ClientError('Invalid network')); |
|
|
|
|
|
|
|
var cache = WalletService._feeLevelCache[network] || {}; |
|
|
|
|
|
|
|
var levels = Defaults.FEE_LEVELS; |
|
|
|
var samplePoints = _.uniq(_.pluck(levels, 'nbBlocks')); |
|
|
|
self._sampleFeeLevels(network, samplePoints, function(err, feeSamples) { |
|
|
@ -1199,8 +1204,13 @@ WalletService.prototype.getFeeLevels = function(opts, cb) { |
|
|
|
level: level.name, |
|
|
|
}; |
|
|
|
if (err || feeSamples[level.nbBlocks] < 0) { |
|
|
|
result.feePerKb = level.defaultValue; |
|
|
|
result.nbBlocks = null; |
|
|
|
if (cache[level.nbBlocks] >= 0) { |
|
|
|
result.feePerKb = cache[level.nbBlocks]; |
|
|
|
result.nbBlocks = level.nbBlocks; |
|
|
|
} else { |
|
|
|
result.feePerKb = level.defaultValue; |
|
|
|
result.nbBlocks = null; |
|
|
|
} |
|
|
|
} else { |
|
|
|
result.feePerKb = feeSamples[level.nbBlocks]; |
|
|
|
result.nbBlocks = level.nbBlocks; |
|
|
@ -1208,6 +1218,14 @@ WalletService.prototype.getFeeLevels = function(opts, cb) { |
|
|
|
return result; |
|
|
|
}); |
|
|
|
|
|
|
|
var obtainedValues = _.zipObject(_.map(_.reject(values, { |
|
|
|
nbBlocks: null |
|
|
|
}), function(v) { |
|
|
|
return [v.nbBlocks, v.feePerKb]; |
|
|
|
})); |
|
|
|
|
|
|
|
WalletService._feeLevelCache[network] = _.assign(cache, obtainedValues); |
|
|
|
|
|
|
|
return cb(null, values); |
|
|
|
}); |
|
|
|
}; |
|
|
|