@@ -110,9 +110,11 @@ function ExecutionContext () {
110110
111111 let executionContext = null
112112
113+ this . currentProviderName = null
113114 this . blockGasLimitDefault = 4300000
114115 this . blockGasLimit = this . blockGasLimitDefault
115116 this . customNetWorks = { }
117+ this . customWeb3Providers = { }
116118 this . blocks = { }
117119 this . latestBlockNumber = 0
118120 this . txs = { }
@@ -135,6 +137,10 @@ function ExecutionContext () {
135137 return executionContext
136138 }
137139
140+ this . getProviderName = function ( ) {
141+ return this . currentProviderName
142+ }
143+
138144 this . isVM = function ( ) {
139145 return executionContext === 'vm'
140146 }
@@ -180,12 +186,26 @@ function ExecutionContext () {
180186 }
181187
182188 this . addProvider = ( network ) => {
183- if ( network && network . name && network . url ) {
189+ if ( network && network . name && network . url && ! this . customNetWorks [ network . name ] ) {
184190 this . customNetWorks [ network . name ] = network
185191 this . event . trigger ( 'addProvider' , [ network ] )
186192 }
187193 }
188194
195+ this . addWeb3provider = ( name , provider ) => {
196+ if ( name && ! this . customWeb3Providers [ name ] ) {
197+ this . customWeb3Providers [ name ] = provider
198+ this . event . trigger ( 'addWeb3Provider' , [ { name} ] )
199+ }
200+ }
201+
202+ this . removeWeb3Provider = ( name ) => {
203+ if ( name && this . customWeb3Providers [ name ] ) {
204+ delete this . customWeb3Providers [ name ]
205+ this . event . trigger ( 'removeWeb3Provider' , [ name ] )
206+ }
207+ }
208+
189209 this . internalWeb3 = ( ) => {
190210 return web3
191211 }
@@ -205,9 +225,10 @@ function ExecutionContext () {
205225
206226 this . executionContextChange = ( context , endPointUrl , confirmCb , infoCb , cb ) => {
207227 if ( ! cb ) cb = ( ) => { }
208-
228+ console . log ( 'executionContextChange' , context )
209229 if ( context === 'vm' ) {
210230 executionContext = context
231+ this . currentProviderName = context
211232 vms [ currentFork ] . stateManager . revert ( ( ) => {
212233 vms [ currentFork ] . stateManager . checkpoint ( ( ) => { } )
213234 } )
@@ -222,6 +243,7 @@ function ExecutionContext () {
222243 } else {
223244 this . askPermission ( )
224245 executionContext = context
246+ this . currentProviderName = context
225247 web3 . setProvider ( injectedProvider )
226248 this . _updateBlockGasLimit ( )
227249 this . event . trigger ( 'contextChanged' , [ 'injected' ] )
@@ -230,12 +252,20 @@ function ExecutionContext () {
230252 }
231253
232254 if ( context === 'web3' ) {
255+ this . currentProviderName = context
233256 confirmCb ( cb )
234257 }
235258
236259 if ( this . customNetWorks [ context ] ) {
237260 var provider = this . customNetWorks [ context ]
238- setProviderFromEndpoint ( provider . url , 'web3' , ( ) => { cb ( ) } )
261+ this . currentProviderName = context
262+ this . setProviderFromEndpoint ( provider . url , 'web3' , ( ) => { cb ( ) } )
263+ }
264+
265+ if ( this . customWeb3Providers [ context ] ) {
266+ const provider = this . customWeb3Providers [ context ]
267+ this . currentProviderName = context
268+ this . setProviderFromEndpoint ( provider , 'web3' , ( ) => { cb ( ) } )
239269 }
240270 }
241271
@@ -269,15 +299,20 @@ function ExecutionContext () {
269299
270300 // TODO: remove this when this function is moved
271301 const self = this
272- // TODO: not used here anymore and needs to be moved
273- function setProviderFromEndpoint ( endpoint , context , cb ) {
302+
303+ this . setProviderFromEndpoint = ( endpoint , context , cb ) => {
274304 const oldProvider = web3 . currentProvider
275305
276- if ( endpoint === 'ipc' ) {
277- web3 . setProvider ( new web3 . providers . IpcProvider ( ) )
306+ if ( typeof endpoint === 'string' ) {
307+ if ( endpoint === 'ipc' ) {
308+ web3 . setProvider ( new web3 . providers . IpcProvider ( ) )
309+ } else {
310+ web3 . setProvider ( new web3 . providers . HttpProvider ( endpoint ) )
311+ }
278312 } else {
279- web3 . setProvider ( new web3 . providers . HttpProvider ( endpoint ) )
313+ web3 . setProvider ( endpoint )
280314 }
315+
281316 web3 . eth . net . isListening ( ( err , isConnected ) => {
282317 if ( ! err && isConnected ) {
283318 executionContext = context
@@ -291,7 +326,6 @@ function ExecutionContext () {
291326 }
292327 } )
293328 }
294- this . setProviderFromEndpoint = setProviderFromEndpoint
295329
296330 this . txDetailsLink = ( network , hash ) => {
297331 if ( transactionDetailsLinks [ network ] ) {
0 commit comments