feat: apply fee discount for outgoing tx

This commit is contained in:
José Oliveira 2021-05-19 13:31:19 +01:00
parent 8128f05ffb
commit eb33203d26
5 changed files with 136 additions and 3 deletions

View file

@ -3,6 +3,7 @@ const mem = require('mem')
const hkdf = require('futoin-hkdf')
const configManager = require('./new-config-manager')
const { loadLatestConfig } = require('./new-settings-loader')
const pify = require('pify')
const fs = pify(require('fs'))
@ -59,6 +60,17 @@ function _balance (settings, cryptoCode) {
function sendCoins (settings, tx) {
return fetchWallet(settings, tx.cryptoCode)
.then(r => {
if (tx.cryptoCode === 'BTC') {
return loadLatestConfig()
.then(config => {
const feeDiscount = config.wallets_BTC_feeDiscount
return r.wallet.sendCoins(r.account, tx, settings, r.operatorId, feeDiscount)
})
.then(res => {
mem.clear(module.exports.balance)
return res
})
}
return r.wallet.sendCoins(r.account, tx, settings, r.operatorId)
.then(res => {
mem.clear(module.exports.balance)
@ -69,7 +81,6 @@ function sendCoins (settings, tx) {
if (err.name === INSUFFICIENT_FUNDS_NAME) {
throw httpError(INSUFFICIENT_FUNDS_NAME, INSUFFICIENT_FUNDS_CODE)
}
throw err
})
}