fix: serialize ETH sendCoins()

This commit is contained in:
siiky 2024-12-17 13:07:46 +00:00
parent 58e625f798
commit 2ade6c21cc

View file

@ -42,6 +42,10 @@ const SWEEP_QUEUE = new PQueue({
interval: 250,
})
const SEND_QUEUE = new PQueue({
concurrency: 1,
})
const infuraCalls = {}
const pify = _function => {
@ -78,18 +82,20 @@ function sendCoins (account, tx, settings, operatorId, feeMultiplier) {
const { toAddress, cryptoAtoms, cryptoCode } = tx
const isErc20Token = coins.utils.isErc20Token(cryptoCode)
return (isErc20Token ? generateErc20Tx : generateTx)(toAddress, defaultWallet(account), cryptoAtoms, false, cryptoCode)
.then(pify(web3.eth.sendSignedTransaction))
.then(txid => {
return pify(web3.eth.getTransaction)(txid)
.then(tx => {
if (!tx) return { txid }
return SEND_QUEUE.add(() =>
(isErc20Token ? generateErc20Tx : generateTx)(toAddress, defaultWallet(account), cryptoAtoms, false, cryptoCode)
.then(pify(web3.eth.sendSignedTransaction))
.then(txid => {
return pify(web3.eth.getTransaction)(txid)
.then(tx => {
if (!tx) return { txid }
const fee = new BN(tx.gas).times(new BN(tx.gasPrice)).decimalPlaces(0)
const fee = new BN(tx.gas).times(new BN(tx.gasPrice)).decimalPlaces(0)
return { txid, fee }
})
})
return { txid, fee }
})
})
)
}
function checkCryptoCode (cryptoCode) {