From 450de3cc0bcbe3004c35aa95661143f21ac45c6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Salgado?= Date: Fri, 25 Feb 2022 16:39:39 +0000 Subject: [PATCH] fix: reducer function to calculate per address crypto atoms --- lib/plugins/wallet/bitcoind/bitcoind.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/plugins/wallet/bitcoind/bitcoind.js b/lib/plugins/wallet/bitcoind/bitcoind.js index cd9b1df0..dd07b1a9 100644 --- a/lib/plugins/wallet/bitcoind/bitcoind.js +++ b/lib/plugins/wallet/bitcoind/bitcoind.js @@ -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))