make it all async

compilertrigger^2
yann300 3 years ago committed by Aniket
parent 4bf032633a
commit c44e2f745d
  1. 33
      libs/remix-lib/src/execution/txListener.ts

@ -105,8 +105,7 @@ export class TxListener {
addExecutionCosts(txResult, tx, execResult) addExecutionCosts(txResult, tx, execResult)
tx.envMode = this.executionContext.getProvider() tx.envMode = this.executionContext.getProvider()
tx.status = txResult.receipt.status // 0x0 or 0x1 tx.status = txResult.receipt.status // 0x0 or 0x1
this._resolve([tx], () => { this._resolve([tx])
})
}) })
}) })
} }
@ -162,7 +161,8 @@ export class TxListener {
async _startListenOnNetwork () { async _startListenOnNetwork () {
let lastSeenBlock = this.executionContext.lastBlock?.number let lastSeenBlock = this.executionContext.lastBlock?.number
let processingBlock = false let processingBlock = false
this._loopId = setInterval(() => {
const processBlocks = async () => {
if (processingBlock) return if (processingBlock) return
processingBlock = true processingBlock = true
const currentLoopId = this._loopId const currentLoopId = this._loopId
@ -186,7 +186,7 @@ export class TxListener {
while (lastSeenBlock <= current) { while (lastSeenBlock <= current) {
try { try {
if (!this._isListening) break if (!this._isListening) break
this._manageBlock(lastSeenBlock) await this._manageBlock(lastSeenBlock)
} catch (e) { } catch (e) {
console.log(e) console.log(e)
} }
@ -195,15 +195,16 @@ export class TxListener {
lastSeenBlock = current lastSeenBlock = current
} }
processingBlock = false processingBlock = false
}, 20000) }
processBlocks()
this._loopId = setInterval(processBlocks, 20000)
} }
_manageBlock (blockNumber) { async _manageBlock (blockNumber) {
this.executionContext.web3().eth.getBlock(blockNumber, true, (error, result) => { try {
if (!error) { const result = await this.executionContext.web3().eth.getBlock(blockNumber, true)
this._newBlock(Object.assign({ type: 'web3' }, result)) return await this._newBlock(Object.assign({ type: 'web3' }, result))
} } catch (e) {}
})
} }
/** /**
@ -227,11 +228,10 @@ export class TxListener {
return this._resolvedTransactions[txHash] return this._resolvedTransactions[txHash]
} }
_newBlock (block) { async _newBlock (block) {
this.blocks.push(block) this.blocks.push(block)
this._resolve(block.transactions, () => { await this._resolve(block.transactions)
this.event.trigger('newBlock', [block]) this.event.trigger('newBlock', [block])
})
} }
_resolveAsync (tx) { _resolveAsync (tx) {
@ -250,14 +250,13 @@ export class TxListener {
}) })
} }
async _resolve (transactions, callback) { async _resolve (transactions) {
for (const tx of transactions) { for (const tx of transactions) {
try { try {
if (!this._isListening) break if (!this._isListening) break
await this._resolveAsync(tx) await this._resolveAsync(tx)
} catch (e) {} } catch (e) {}
} }
callback()
} }
_resolveTx (tx, receipt, cb) { _resolveTx (tx, receipt, cb) {

Loading…
Cancel
Save