Merge remote-tracking branch 'origin/release-9.0' into chore/merge-9-into-10-20240206
This commit is contained in:
commit
35e40f4528
52 changed files with 4794 additions and 6007 deletions
|
|
@ -1,5 +1,6 @@
|
|||
const _ = require('lodash/fp')
|
||||
const jsonRpc = require('../../common/json-rpc')
|
||||
const { getSatBEstimateFee } = require('../../../blockexplorers/mempool.space')
|
||||
|
||||
const BN = require('../../../bn')
|
||||
const E = require('../../../error')
|
||||
|
|
@ -56,20 +57,28 @@ function balance (account, cryptoCode, settings, operatorId) {
|
|||
}
|
||||
|
||||
function estimateFee () {
|
||||
return fetch('estimatesmartfee', [6, 'unset'])
|
||||
.then(result => BN(result.feerate))
|
||||
.catch(() => {})
|
||||
return getSatBEstimateFee()
|
||||
.then(result => BN(result))
|
||||
.catch(err => {
|
||||
logger.error('failure estimating fes', err)
|
||||
})
|
||||
}
|
||||
|
||||
function calculateFeeDiscount (feeMultiplier) {
|
||||
function calculateFeeDiscount (feeMultiplier = 1, unitScale) {
|
||||
// 0 makes bitcoind do automatic fee selection
|
||||
const AUTOMATIC_FEE = isDevMode() ? 0.01 : 0
|
||||
if (!feeMultiplier || feeMultiplier.eq(1)) return AUTOMATIC_FEE
|
||||
const AUTOMATIC_FEE = 0
|
||||
return estimateFee()
|
||||
.then(estimatedFee => {
|
||||
if (!estimatedFee) return AUTOMATIC_FEE
|
||||
const newFee = estimatedFee.times(feeMultiplier)
|
||||
if (newFee.lt(0.00001) || newFee.gt(0.1)) return AUTOMATIC_FEE
|
||||
if (!estimatedFee) {
|
||||
logger.info('failure estimating fee, using bitcoind automatic fee selection')
|
||||
return AUTOMATIC_FEE
|
||||
}
|
||||
// transform from sat/vB to BTC/kvB and apply the multipler
|
||||
const newFee = estimatedFee.shiftedBy(-unitScale+3).times(feeMultiplier)
|
||||
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)
|
||||
})
|
||||
}
|
||||
|
|
@ -79,7 +88,7 @@ function sendCoins (account, tx, settings, operatorId, feeMultiplier) {
|
|||
const coins = cryptoAtoms.shiftedBy(-unitScale).toFixed(8)
|
||||
|
||||
return checkCryptoCode(cryptoCode)
|
||||
.then(() => calculateFeeDiscount(feeMultiplier))
|
||||
.then(() => calculateFeeDiscount(feeMultiplier, unitScale))
|
||||
.then(newFee => fetch('settxfee', [newFee]))
|
||||
.then(() => fetch('sendtoaddress', [toAddress, coins]))
|
||||
.then((txId) => fetch('gettransaction', [txId]))
|
||||
|
|
@ -95,7 +104,7 @@ function sendCoins (account, tx, settings, operatorId, feeMultiplier) {
|
|||
|
||||
function sendCoinsBatch (account, txs, cryptoCode, feeMultiplier) {
|
||||
return checkCryptoCode(cryptoCode)
|
||||
.then(() => calculateFeeDiscount(feeMultiplier))
|
||||
.then(() => calculateFeeDiscount(feeMultiplier, unitScale))
|
||||
.then(newFee => fetch('settxfee', [newFee]))
|
||||
.then(() => _.reduce((acc, value) => ({
|
||||
...acc,
|
||||
|
|
@ -207,7 +216,6 @@ module.exports = {
|
|||
newFunding,
|
||||
cryptoNetwork,
|
||||
fetchRBF,
|
||||
estimateFee,
|
||||
sendCoinsBatch,
|
||||
checkBlockchainStatus,
|
||||
getTxHashesByAddress,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue