Commit 72d97a3f authored by Iuri Matias's avatar Iuri Matias Committed by yann300

replace executionContext for network module with blockchain object

parent a5160fc3
......@@ -234,7 +234,7 @@ Please make a backup of your contracts and start using http://remix.ethereum.org
const {eventsDecoder, txlistener} = makeUdapp(blockchain, compilersArtefacts, (domEl) => mainview.getTerminal().logHtml(domEl))
// ----------------- network service (resolve network id / name) ----------------------------
const networkModule = new NetworkModule(executionContext)
const networkModule = new NetworkModule(blockchain)
// ----------------- convert offset to line/column service ----------------------------
var offsetToLineColumnConverter = new OffsetToLineColumnConverter()
registry.put({api: offsetToLineColumnConverter, name: 'offsettolinecolumnconverter'})
......
......@@ -14,11 +14,11 @@ export const profile = {
// - methods: ['getNetworkProvider', 'getEndpoint', 'detectNetwork', 'addNetwork', 'removeNetwork']
export class NetworkModule extends Plugin {
constructor (executionContext) {
constructor (blockchain) {
super(profile)
this.executionContext = executionContext
this.blockchain = blockchain
// TODO: See with remix-lib to make sementic coherent
this.executionContext.event.register('contextChanged', (provider) => {
this.blockchain.event.register('contextChanged', (provider) => {
this.emit('providerChanged', provider)
})
/*
......@@ -37,13 +37,13 @@ export class NetworkModule extends Plugin {
/** Return the current network provider (web3, vm, injected) */
getNetworkProvider () {
return this.executionContext.getProvider()
return this.blockchain.getProvider()
}
/** Return the current network */
detectNetwork () {
return new Promise((resolve, reject) => {
this.executionContext.detectNetwork((error, network) => {
this.blockchain.detectNetwork((error, network) => {
error ? reject(error) : resolve(network)
})
})
......@@ -51,20 +51,20 @@ export class NetworkModule extends Plugin {
/** Return the url only if network provider is 'web3' */
getEndpoint () {
const provider = this.executionContext.getProvider()
const provider = this.blockchain.getProvider()
if (provider !== 'web3') {
throw new Error('no endpoint: current provider is either injected or vm')
}
return this.executionContext.web3().currentProvider.host
return this.blockchain.web3().currentProvider.host
}
/** Add a custom network to the list of available networks */
addNetwork (customNetwork) {
this.executionContext.addProvider(customNetwork)
this.blockchain.addProvider(customNetwork)
}
/** Remove a network to the list of availble networks */
removeNetwork (name) {
this.executionContext.removeProvider(name)
this.blockchain.removeProvider(name)
}
}
......@@ -321,6 +321,13 @@ class Blockchain {
this.udapp.resetEnvironment()
}
addNetwork (customNetwork) {
this.executionContext.addProvider(customNetwork)
}
removeNetwork (name) {
this.executionContext.removeProvider(name)
}
}
module.exports = Blockchain
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment