Merge pull request #1135 from chaotixkilla/fix-btc-batching-same-output-address

Fix BTC transaction batching on same output address
This commit is contained in:
Rafael Taranto 2022-03-01 10:59:38 +00:00 committed by GitHub
commit 7e9fd148f3

View file

@ -91,10 +91,12 @@ function sendCoinsBatch (account, txs, cryptoCode, feeMultiplier) {
logger.info('** DEBUG MINERS FEE ** - Calculated fee discount: ', newFee)
return fetch('settxfee', [newFee])
})
.then(() => {
const txAddressAmountPairs = _.map(tx => [tx.toAddress, BN(tx.cryptoAtoms).shiftedBy(-unitScale).toFixed(8)], txs)
return _.fromPairs(txAddressAmountPairs)
})
.then(() => _.reduce((acc, value) => ({
...acc,
[value.toAddress]: _.isNil(acc[value.toAddress])
? BN(value.cryptoAtoms).shiftedBy(-unitScale).toFixed(8)
: BN(acc[value.toAddress]).plus(BN(value.cryptoAtoms).shiftedBy(-unitScale).toFixed(8))
}), {}, txs))
.then((obj) => fetch('sendmany', ['', obj]))
.then((txId) => fetch('gettransaction', [txId]))
.then((res) => _.pick(['fee', 'txid'], res))