fix: enqueue sweeping requests and loosen sweep polling

This commit is contained in:
Sérgio Salgado 2022-07-05 21:22:00 +01:00
parent 2d5cbe771a
commit 1d2b762613
3 changed files with 12 additions and 4 deletions

View file

@ -8,6 +8,8 @@ const { FeeMarketEIP1559Transaction } = require('@ethereumjs/tx')
const { default: Common, Chain, Hardfork } = require('@ethereumjs/common')
const util = require('ethereumjs-util')
const coins = require('@lamassu/coins')
const { default: PQueue } = require('p-queue')
const pify = require('pify')
const BN = require('../../../bn')
const ABI = require('../../tokens')
@ -33,6 +35,11 @@ module.exports = {
checkBlockchainStatus
}
const SWEEP_QUEUE = new PQueue({
concurrency: 3,
interval: 250,
})
function connect (url) {
web3.setProvider(new web3.providers.HttpProvider(url))
}
@ -173,13 +180,14 @@ function sweep (account, cryptoCode, hdIndex, settings, operatorId) {
const wallet = paymentHdNode(account).deriveChild(hdIndex).getWallet()
const fromAddress = wallet.getChecksumAddressString()
return confirmedBalance(fromAddress, cryptoCode)
return SWEEP_QUEUE.add(() => confirmedBalance(fromAddress, cryptoCode)
.then(r => {
if (r.eq(0)) return
return generateTx(defaultAddress(account), wallet, r, true, cryptoCode)
.then(signedTx => pify(web3.eth.sendSignedTransaction)(signedTx))
})
)
}
function newAddress (account, info, tx, settings, operatorId) {