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. 14
      apps/remix-ide/src/blockchain/execution-context.js

@ -123,7 +123,7 @@ export class ExecutionContext {
this.executionContextChange(context, endPointUrl, confirmCb, infoCb, null) this.executionContextChange(context, endPointUrl, confirmCb, infoCb, null)
} }
executionContextChange (value, endPointUrl, confirmCb, infoCb, cb) { async executionContextChange (value, endPointUrl, confirmCb, infoCb, cb) {
const context = value.context const context = value.context
if (!cb) cb = () => {} if (!cb) cb = () => {}
if (!confirmCb) confirmCb = () => {} if (!confirmCb) confirmCb = () => {}
@ -143,7 +143,7 @@ export class ExecutionContext {
this.askPermission() this.askPermission()
this.executionContext = context this.executionContext = context
web3.setProvider(injectedProvider) web3.setProvider(injectedProvider)
this._updateChainContext() await this._updateChainContext()
this.event.trigger('contextChanged', ['injected']) this.event.trigger('contextChanged', ['injected'])
return cb() return cb()
} }
@ -170,10 +170,10 @@ export class ExecutionContext {
this.listenOnLastBlockId = null this.listenOnLastBlockId = null
} }
_updateChainContext () { async _updateChainContext () {
if (this.getProvider() !== 'vm') { if (this.getProvider() !== 'vm') {
web3.eth.getBlock('latest', async (err, block) => { try {
if (!err) { 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 // 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 this.blockGasLimit = (block && block.gasLimit) ? Math.floor(block.gasLimit - (5 * block.gasLimit) / 1024) : this.blockGasLimitDefault
try { try {
@ -183,10 +183,10 @@ export class ExecutionContext {
console.log(`unable to detect fork, defaulting to ${this.currentFork}..`) console.log(`unable to detect fork, defaulting to ${this.currentFork}..`)
console.error(e) console.error(e)
} }
} else { } catch (e) {
console.error(e)
this.blockGasLimit = this.blockGasLimitDefault this.blockGasLimit = this.blockGasLimitDefault
} }
})
} }
} }

Loading…
Cancel
Save