@ -21,7 +21,8 @@ export class ExecutionContext {
this . executionContext = null
this . blockGasLimitDefault = 4300000
this . blockGasLimit = this . blockGasLimitDefault
this . currentFork = 'berlin'
this . defaultFork = 'berlin'
this . currentFork = this . defaultFork
this . mainNetGenesisHash = '0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3'
this . customNetWorks = { }
this . blocks = { }
@ -48,6 +49,10 @@ export class ExecutionContext {
return this . executionContext
}
getCurrentFork ( ) {
return this . currentFork
}
isVM ( ) {
return this . executionContext === 'vm'
}
@ -58,7 +63,7 @@ export class ExecutionContext {
web3 ( ) {
if ( this . customWeb3 [ this . executionContext ] ) return this . customWeb3 [ this . executionContext ]
return this . isVM ( ) ? this . vms [ this . currentFork ] . web3vm : web3
return web3
}
detectNetwork ( callback ) {
@ -118,16 +123,21 @@ export class ExecutionContext {
this . executionContextChange ( context , endPointUrl , confirmCb , infoCb , null )
}
executionContextChange ( context , endPointUrl , confirmCb , infoCb , cb ) {
executionContextChange ( value , endPointUrl , confirmCb , infoCb , cb ) {
const context = value . context
const fork = value . fork || this . defaultFork
if ( ! cb ) cb = ( ) => { }
if ( ! confirmCb ) confirmCb = ( ) => { }
if ( ! infoCb ) infoCb = ( ) => { }
if ( context === 'vm' ) {
this . executionContext = context
this . currentFork = fork
this . event . trigger ( 'contextChanged' , [ 'vm' ] )
return cb ( )
}
this . currentFork = this . defaultFork
if ( context === 'injected' ) {
if ( injectedProvider === undefined ) {
infoCb ( 'No injected Web3 provider found. Make sure your provider (e.g. MetaMask) is active and running (when recently activated you may have to reload the page).' )
@ -147,7 +157,7 @@ export class ExecutionContext {
}
if ( this . customNetWorks [ context ] ) {
var network = this . customNetWorks [ context ]
this . setProviderFromEndpoint ( network . provider , network . name , ( error ) => {
this . setProviderFromEndpoint ( network . provider , { context : network . name } , ( error ) => {
if ( error ) infoCb ( error )
cb ( )
} )
@ -184,8 +194,9 @@ export class ExecutionContext {
// TODO: remove this when this function is moved
setProviderFromEndpoint ( endpoint , context , cb ) {
setProviderFromEndpoint ( endpoint , value , cb ) {
const oldProvider = web3 . currentProvider
const context = value . context
web3 . setProvider ( endpoint )
web3 . eth . net . isListening ( ( err , isConnected ) => {