fix: enqueue sweeping requests and loosen sweep polling
This commit is contained in:
parent
ecdc020113
commit
fa0ef6b053
3 changed files with 12 additions and 4 deletions
|
|
@ -9,6 +9,8 @@ const { default: Common, Chain, Hardfork } = require('@ethereumjs/common')
|
|||
const Tx = require('ethereumjs-tx')
|
||||
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')
|
||||
|
|
@ -48,6 +50,11 @@ const logInfuraCall = call => {
|
|||
logger.info(`Calling web3 method ${call} via Infura. Current count for this session: ${JSON.stringify(infuraCalls)}`)
|
||||
}
|
||||
|
||||
const SWEEP_QUEUE = new PQueue({
|
||||
concurrency: 3,
|
||||
interval: 250,
|
||||
})
|
||||
|
||||
function connect (url) {
|
||||
web3.setProvider(new web3.providers.HttpProvider(url))
|
||||
}
|
||||
|
|
@ -236,13 +243,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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue