replace executionContext for network module with blockchain object

pull/1/head
Iuri Matias 5 years ago
parent 784a01d39f
commit 3908f1a299
  1. 2
      src/app.js
  2. 18
      src/app/tabs/network-module.js
  3. 7
      src/app/tabs/runTab/model/blockchain.js

@ -235,7 +235,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)) const {eventsDecoder, txlistener} = makeUdapp(blockchain, compilersArtefacts, (domEl) => mainview.getTerminal().logHtml(domEl))
// ----------------- network service (resolve network id / name) ---------------------------- // ----------------- network service (resolve network id / name) ----------------------------
const networkModule = new NetworkModule(executionContext) const networkModule = new NetworkModule(blockchain)
// ----------------- convert offset to line/column service ---------------------------- // ----------------- convert offset to line/column service ----------------------------
var offsetToLineColumnConverter = new OffsetToLineColumnConverter() var offsetToLineColumnConverter = new OffsetToLineColumnConverter()
registry.put({api: offsetToLineColumnConverter, name: 'offsettolinecolumnconverter'}) registry.put({api: offsetToLineColumnConverter, name: 'offsettolinecolumnconverter'})

@ -14,11 +14,11 @@ export const profile = {
// - methods: ['getNetworkProvider', 'getEndpoint', 'detectNetwork', 'addNetwork', 'removeNetwork'] // - methods: ['getNetworkProvider', 'getEndpoint', 'detectNetwork', 'addNetwork', 'removeNetwork']
export class NetworkModule extends Plugin { export class NetworkModule extends Plugin {
constructor (executionContext) { constructor (blockchain) {
super(profile) super(profile)
this.executionContext = executionContext this.blockchain = blockchain
// TODO: See with remix-lib to make sementic coherent // 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) this.emit('providerChanged', provider)
}) })
/* /*
@ -37,13 +37,13 @@ export class NetworkModule extends Plugin {
/** Return the current network provider (web3, vm, injected) */ /** Return the current network provider (web3, vm, injected) */
getNetworkProvider () { getNetworkProvider () {
return this.executionContext.getProvider() return this.blockchain.getProvider()
} }
/** Return the current network */ /** Return the current network */
detectNetwork () { detectNetwork () {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this.executionContext.detectNetwork((error, network) => { this.blockchain.detectNetwork((error, network) => {
error ? reject(error) : resolve(network) error ? reject(error) : resolve(network)
}) })
}) })
@ -51,20 +51,20 @@ export class NetworkModule extends Plugin {
/** Return the url only if network provider is 'web3' */ /** Return the url only if network provider is 'web3' */
getEndpoint () { getEndpoint () {
const provider = this.executionContext.getProvider() const provider = this.blockchain.getProvider()
if (provider !== 'web3') { if (provider !== 'web3') {
throw new Error('no endpoint: current provider is either injected or vm') 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 */ /** Add a custom network to the list of available networks */
addNetwork (customNetwork) { addNetwork (customNetwork) {
this.executionContext.addProvider(customNetwork) this.blockchain.addProvider(customNetwork)
} }
/** Remove a network to the list of availble networks */ /** Remove a network to the list of availble networks */
removeNetwork (name) { removeNetwork (name) {
this.executionContext.removeProvider(name) this.blockchain.removeProvider(name)
} }
} }

@ -323,6 +323,13 @@ class Blockchain {
this.udapp.resetEnvironment() this.udapp.resetEnvironment()
} }
addNetwork (customNetwork) {
this.executionContext.addProvider(customNetwork)
}
removeNetwork (name) {
this.executionContext.removeProvider(name)
}
} }
module.exports = Blockchain module.exports = Blockchain

Loading…
Cancel
Save