Skip to content

Commit

Permalink
Merge pull request #2582 from ethereum/refactor_iuri
Browse files Browse the repository at this point in the history
refactor, abstract and remove dependencies on executionContext and udapp - 2
  • Loading branch information
yann300 authored Feb 5, 2020
2 parents c721844 + 1800813 commit 50b2c87
Show file tree
Hide file tree
Showing 11 changed files with 815 additions and 388 deletions.
18 changes: 7 additions & 11 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ var toolTip = require('./app/ui/tooltip')
var CompilerMetadata = require('./app/files/compiler-metadata')
var CompilerImport = require('./app/compiler/compiler-imports')

var executionContext = remixLib.execution.executionContext

const Blockchain = require('./app/tabs/runTab/model/blockchain.js')
const Blockchain = require('./blockchain/blockchain.js')
const PluginUDapp = require('./blockchain/pluginUDapp.js')

const PluginManagerComponent = require('./app/components/plugin-manager-component')
const CompilersArtefacts = require('./app/compiler/compiler-artefacts')
Expand All @@ -50,7 +49,6 @@ import { HiddenPanel } from './app/components/hidden-panel'
import { VerticalIcons } from './app/components/vertical-icons'
import { LandingPage } from './app/ui/landing-page/landing-page'
import { MainPanel } from './app/components/main-panel'
import { UniversalDApp } from 'remix-lib'

import migrateFileSystem from './migrateFileSystem'

Expand Down Expand Up @@ -225,9 +223,8 @@ Please make a backup of your contracts and start using http://remix.ethereum.org
const fileManager = new FileManager(editor)
registry.put({api: fileManager, name: 'filemanager'})

// ----------------- universal dapp: run transaction, listen on transactions, decode events
const udapp = new UniversalDApp(registry.get('config').api, executionContext)
const blockchain = new Blockchain(executionContext, udapp)
const blockchain = new Blockchain(registry.get('config').api)
const pluginUdapp = new PluginUDapp(blockchain)

// ----------------- compilation metadata generation servive ----------------------------
const compilerMetadataGenerator = new CompilerMetadata(blockchain, fileManager, registry.get('config').api)
Expand All @@ -237,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'})
Expand Down Expand Up @@ -300,8 +297,7 @@ Please make a backup of your contracts and start using http://remix.ethereum.org
)
const run = new RunTab(
blockchain,
udapp,
executionContext,
pluginUdapp,
registry.get('config').api,
registry.get('filemanager').api,
registry.get('editor').api,
Expand All @@ -311,7 +307,7 @@ Please make a backup of your contracts and start using http://remix.ethereum.org
mainview
)
const analysis = new AnalysisTab(registry)
const debug = new DebuggerTab(executionContext)
const debug = new DebuggerTab(blockchain)
const test = new TestTab(
registry.get('filemanager').api,
filePanel,
Expand Down
6 changes: 3 additions & 3 deletions src/app/tabs/debugger-tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ const profile = {

class DebuggerTab extends ViewPlugin {

constructor (executionContext) {
constructor (blockchain) {
super(profile)
this.el = null
this.executionContext = executionContext
this.blockchain = blockchain
}

render () {
Expand All @@ -34,7 +34,7 @@ class DebuggerTab extends ViewPlugin {
<div class="${css.debuggerTabView}" id="debugView">
<div id="debugger" class="${css.debugger}"></div>
</div>`
this.debuggerUI = new DebuggerUI(this.el.querySelector('#debugger'), this.executionContext)
this.debuggerUI = new DebuggerUI(this.el.querySelector('#debugger'), this.blockchain)
return this.el
}

Expand Down
10 changes: 5 additions & 5 deletions src/app/tabs/debugger/debuggerUI.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ var css = csjs`

class DebuggerUI {

constructor (container, executionContext) {
constructor (container, blockchain) {
this.registry = globalRegistry
this.executionContext = executionContext
this.blockchain = blockchain
this.event = new EventManager()

this.isActive = false
Expand Down Expand Up @@ -105,13 +105,13 @@ class DebuggerUI {

getDebugWeb3 () {
return new Promise((resolve, reject) => {
this.executionContext.detectNetwork((error, network) => {
this.blockchain.detectNetwork((error, network) => {
let web3
if (error || !network) {
web3 = init.web3DebugNode(this.executionContext.web3())
web3 = init.web3DebugNode(this.blockchain.web3())
} else {
const webDebugNode = init.web3DebugNode(network.name)
web3 = !webDebugNode ? this.executionContext.web3() : webDebugNode
web3 = !webDebugNode ? this.blockchain.web3() : webDebugNode
}
init.extendWeb3(web3)
resolve(web3)
Expand Down
18 changes: 9 additions & 9 deletions src/app/tabs/network-module.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
/*
Expand All @@ -37,34 +37,34 @@ 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)
})
})
}

/** 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)
}
}
Loading

0 comments on commit 50b2c87

Please sign in to comment.