Make sure current fork is set before continuing (#1340)

pull/1306/head^2
yann300 3 years ago committed by GitHub
parent 4ddba6b228
commit 43029b7462
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 34
      apps/remix-ide/src/blockchain/execution-context.js

@ -123,7 +123,7 @@ export class ExecutionContext {
this.executionContextChange(context, endPointUrl, confirmCb, infoCb, null)
}
executionContextChange (value, endPointUrl, confirmCb, infoCb, cb) {
async executionContextChange (value, endPointUrl, confirmCb, infoCb, cb) {
const context = value.context
if (!cb) cb = () => {}
if (!confirmCb) confirmCb = () => {}
@ -143,7 +143,7 @@ export class ExecutionContext {
this.askPermission()
this.executionContext = context
web3.setProvider(injectedProvider)
this._updateChainContext()
await this._updateChainContext()
this.event.trigger('contextChanged', ['injected'])
return cb()
}
@ -170,23 +170,23 @@ export class ExecutionContext {
this.listenOnLastBlockId = null
}
_updateChainContext () {
async _updateChainContext () {
if (this.getProvider() !== 'vm') {
web3.eth.getBlock('latest', async (err, block) => {
if (!err) {
// we can't use the blockGasLimit cause the next blocks could have a lower limit : https://github.com/ethereum/remix/issues/506
this.blockGasLimit = (block && block.gasLimit) ? Math.floor(block.gasLimit - (5 * block.gasLimit) / 1024) : this.blockGasLimitDefault
try {
this.currentFork = execution.forkAt(await web3.eth.net.getId(), block.number)
} catch (e) {
this.currentFork = 'berlin'
console.log(`unable to detect fork, defaulting to ${this.currentFork}..`)
console.error(e)
}
} else {
this.blockGasLimit = this.blockGasLimitDefault
try {
const block = await web3.eth.getBlock('latest')
// we can't use the blockGasLimit cause the next blocks could have a lower limit : https://github.com/ethereum/remix/issues/506
this.blockGasLimit = (block && block.gasLimit) ? Math.floor(block.gasLimit - (5 * block.gasLimit) / 1024) : this.blockGasLimitDefault
try {
this.currentFork = execution.forkAt(await web3.eth.net.getId(), block.number)
} catch (e) {
this.currentFork = 'berlin'
console.log(`unable to detect fork, defaulting to ${this.currentFork}..`)
console.error(e)
}
})
} catch (e) {
console.error(e)
this.blockGasLimit = this.blockGasLimitDefault
}
}
}

Loading…
Cancel
Save