Merge remote-tracking branch 'origin/release-8.1.10' into merge-8.1-into-9

This commit is contained in:
Rafael Taranto 2024-01-08 10:34:44 +00:00
commit d18b5bb29d
8 changed files with 1443 additions and 790 deletions

View file

@ -1,5 +1,6 @@
const _ = require('lodash/fp')
const jsonRpc = require('../../common/json-rpc')
const { getEstimateFeeBtc } = require('../../../blockexplorers/mempool.space')
const BN = require('../../../bn')
const E = require('../../../error')
@ -55,20 +56,27 @@ function balance (account, cryptoCode, settings, operatorId) {
}
function estimateFee () {
return fetch('estimatesmartfee', [6, 'unset'])
.then(result => BN(result.feerate))
.catch(() => {})
return getEstimateFeeBtc()
.then(result => BN(result))
.catch(err => {
logger.error('failure estimating fes', err)
})
}
function calculateFeeDiscount (feeMultiplier) {
function calculateFeeDiscount (feeMultiplier = 1) {
// 0 makes bitcoind do automatic fee selection
const AUTOMATIC_FEE = 0
if (!feeMultiplier || feeMultiplier.eq(1)) return AUTOMATIC_FEE
return estimateFee()
.then(estimatedFee => {
if (!estimatedFee) return AUTOMATIC_FEE
if (!estimatedFee) {
logger.info('failure estimating fee, using bitcoind automatic fee selection')
return AUTOMATIC_FEE
}
const newFee = estimatedFee.times(feeMultiplier)
if (newFee.lt(0.00001) || newFee.gt(0.1)) return AUTOMATIC_FEE
if (newFee.lt(0.00001) || newFee.gt(0.1)) {
logger.info('fee outside safety parameters, defaulting to automatic fee selection')
return AUTOMATIC_FEE
}
return newFee.toFixed(8)
})
}