Commit 5afeb172 authored by Iuri Matias's avatar Iuri Matias

pass executionContext as param instead of relying in a global var

parent e448ded4
...@@ -143,10 +143,11 @@ ...@@ -143,10 +143,11 @@
"remix-ide": "./bin/remix-ide" "remix-ide": "./bin/remix-ide"
}, },
"scripts": { "scripts": {
"setupremix": "npm run linkremixdebug && npm run linkremixlib && npm run linkremixsolidity && npm run linkremixanalyzer && npm run linkremixtests", "setupremix": "npm run linkremixdebug && npm run linkremixlib && npm run linkremixsolidity && npm run linkremixanalyzer && npm run linkremixtests && npm run linkremixsimulator",
"pullremix": "git clone https://github.com/ethereum/remix", "pullremix": "git clone https://github.com/ethereum/remix",
"linkremixlib": "cd node_modules && rm -rf remix-lib && ln -s ../../remix/remix-lib remix-lib && cd ..", "linkremixlib": "cd node_modules && rm -rf remix-lib && ln -s ../../remix/remix-lib remix-lib && cd ..",
"linkremixsolidity": "cd node_modules && rm -rf remix-solidity && ln -s ../../remix/remix-solidity remix-solidity && cd ..", "linkremixsolidity": "cd node_modules && rm -rf remix-solidity && ln -s ../../remix/remix-solidity remix-solidity && cd ..",
"linkremixsimulator": "cd node_modules && rm -rf remix-simulator && ln -s ../../remix/remix-simulator remix-simulator && cd ..",
"linkremixtests": "cd node_modules && rm -rf remix-tests && ln -s ../../remix/remix-tests remix-tests && cd ..", "linkremixtests": "cd node_modules && rm -rf remix-tests && ln -s ../../remix/remix-tests remix-tests && cd ..",
"linkremixdebug": "cd node_modules && rm -rf remix-debug && ln -s ../../remix/remix-debug remix-debug && cd ..", "linkremixdebug": "cd node_modules && rm -rf remix-debug && ln -s ../../remix/remix-debug remix-debug && cd ..",
"linkremixanalyzer": "cd node_modules && rm -rf remix-analyzer && ln -s ../../remix/remix-analyzer remix-analyzer && cd ..", "linkremixanalyzer": "cd node_modules && rm -rf remix-analyzer && ln -s ../../remix/remix-analyzer remix-analyzer && cd ..",
......
...@@ -23,6 +23,8 @@ var toolTip = require('./app/ui/tooltip') ...@@ -23,6 +23,8 @@ var toolTip = require('./app/ui/tooltip')
var CompilerMetadata = require('./app/files/compiler-metadata') var CompilerMetadata = require('./app/files/compiler-metadata')
var CompilerImport = require('./app/compiler/compiler-imports') var CompilerImport = require('./app/compiler/compiler-imports')
var executionContext = require('./execution-context')
const PluginManagerComponent = require('./app/components/plugin-manager-component') const PluginManagerComponent = require('./app/components/plugin-manager-component')
const CompilersArtefacts = require('./app/compiler/compiler-artefacts') const CompilersArtefacts = require('./app/compiler/compiler-artefacts')
...@@ -222,13 +224,13 @@ Please make a backup of your contracts and start using http://remix.ethereum.org ...@@ -222,13 +224,13 @@ Please make a backup of your contracts and start using http://remix.ethereum.org
const fileManager = new FileManager(editor) const fileManager = new FileManager(editor)
registry.put({api: fileManager, name: 'filemanager'}) registry.put({api: fileManager, name: 'filemanager'})
// ----------------- compilation metadata generation servive ---------------------------- // ----------------- compilation metadata generation servive ----------------------------
const compilerMetadataGenerator = new CompilerMetadata(fileManager, registry.get('config').api) const compilerMetadataGenerator = new CompilerMetadata(executionContext, fileManager, registry.get('config').api)
// ----------------- compilation result service (can keep track of compilation results) ---------------------------- // ----------------- compilation result service (can keep track of compilation results) ----------------------------
const compilersArtefacts = new CompilersArtefacts() // store all the compilation results (key represent a compiler name) const compilersArtefacts = new CompilersArtefacts() // store all the compilation results (key represent a compiler name)
registry.put({api: compilersArtefacts, name: 'compilersartefacts'}) registry.put({api: compilersArtefacts, name: 'compilersartefacts'})
// ----------------- universal dapp: run transaction, listen on transactions, decode events // ----------------- universal dapp: run transaction, listen on transactions, decode events
const udapp = new UniversalDApp(registry.get('config').api) const udapp = new UniversalDApp(registry.get('config').api)
const {eventsDecoder, txlistener} = makeUdapp(udapp, compilersArtefacts, (domEl) => mainview.getTerminal().logHtml(domEl)) const {eventsDecoder, txlistener} = makeUdapp(udapp, executionContext, compilersArtefacts, (domEl) => mainview.getTerminal().logHtml(domEl))
// ----------------- network service (resolve network id / name) ---------------------------- // ----------------- network service (resolve network id / name) ----------------------------
const networkModule = new NetworkModule() const networkModule = new NetworkModule()
// ----------------- convert offset to line/column service ---------------------------- // ----------------- convert offset to line/column service ----------------------------
...@@ -293,6 +295,7 @@ Please make a backup of your contracts and start using http://remix.ethereum.org ...@@ -293,6 +295,7 @@ Please make a backup of your contracts and start using http://remix.ethereum.org
) )
const run = new RunTab( const run = new RunTab(
udapp, udapp,
executionContext,
registry.get('config').api, registry.get('config').api,
registry.get('filemanager').api, registry.get('filemanager').api,
registry.get('editor').api, registry.get('editor').api,
......
'use strict' 'use strict'
var executionContext = require('../../execution-context')
var CompilerAbstract = require('../compiler/compiler-abstract') var CompilerAbstract = require('../compiler/compiler-abstract')
import { Plugin } from '@remixproject/engine' import { Plugin } from '@remixproject/engine'
import * as packageJson from '../../../package.json' import * as packageJson from '../../../package.json'
...@@ -12,9 +11,10 @@ const profile = { ...@@ -12,9 +11,10 @@ const profile = {
} }
class CompilerMetadata extends Plugin { class CompilerMetadata extends Plugin {
constructor (fileManager, config) { constructor (executionContext, fileManager, config) {
super(profile) super(profile)
var self = this var self = this
self.executionContext = executionContext
self.fileManager = fileManager self.fileManager = fileManager
self.config = config self.config = config
self.networks = ['VM:-', 'main:1', 'ropsten:3', 'rinkeby:4', 'kovan:42', 'görli:5', 'Custom'] self.networks = ['VM:-', 'main:1', 'ropsten:3', 'rinkeby:4', 'kovan:42', 'görli:5', 'Custom']
...@@ -97,7 +97,7 @@ class CompilerMetadata extends Plugin { ...@@ -97,7 +97,7 @@ class CompilerMetadata extends Plugin {
var provider = self.fileManager.currentFileProvider() var provider = self.fileManager.currentFileProvider()
var path = self.fileManager.currentPath() var path = self.fileManager.currentPath()
if (provider && path) { if (provider && path) {
executionContext.detectNetwork((err, { id, name } = {}) => { self.executionContext.detectNetwork((err, { id, name } = {}) => {
if (err) { if (err) {
console.log(err) console.log(err)
} else { } else {
......
var yo = require('yo-yo') var yo = require('yo-yo')
var EventManager = require('../../lib/events') var EventManager = require('../../lib/events')
var executionContext = require('../../execution-context')
var Terminal = require('./terminal') var Terminal = require('./terminal')
var globalRegistry = require('../../global/registry') var globalRegistry = require('../../global/registry')
var { TabProxy } = require('./tab-proxy.js') var { TabProxy } = require('./tab-proxy.js')
...@@ -99,7 +101,8 @@ export class MainView { ...@@ -99,7 +101,8 @@ export class MainView {
self._components.terminal = new Terminal({ self._components.terminal = new Terminal({
appManager: this.appManager, appManager: this.appManager,
eventsDecoder: this.eventsDecoder, eventsDecoder: this.eventsDecoder,
txListener: this.txListener txListener: this.txListener,
executionContext: executionContext
}, },
{ {
getPosition: (event) => { getPosition: (event) => {
......
...@@ -10,7 +10,6 @@ var Web3 = require('web3') ...@@ -10,7 +10,6 @@ var Web3 = require('web3')
var swarmgw = require('swarmgw')() var swarmgw = require('swarmgw')()
var CommandInterpreterAPI = require('../../lib/cmdInterpreterAPI') var CommandInterpreterAPI = require('../../lib/cmdInterpreterAPI')
var executionContext = require('../../execution-context')
var AutoCompletePopup = require('../ui/auto-complete-popup') var AutoCompletePopup = require('../ui/auto-complete-popup')
var TxLogger = require('../../app/ui/txLogger') var TxLogger = require('../../app/ui/txLogger')
...@@ -42,6 +41,7 @@ class Terminal extends Plugin { ...@@ -42,6 +41,7 @@ class Terminal extends Plugin {
super(profile) super(profile)
var self = this var self = this
self.event = new EventManager() self.event = new EventManager()
self.executionContext = opts.executionContext
self._api = api self._api = api
self._opts = opts self._opts = opts
self.data = { self.data = {
...@@ -52,7 +52,7 @@ class Terminal extends Plugin { ...@@ -52,7 +52,7 @@ class Terminal extends Plugin {
} }
self._view = { el: null, bar: null, input: null, term: null, journal: null, cli: null } self._view = { el: null, bar: null, input: null, term: null, journal: null, cli: null }
self._components = {} self._components = {}
self._components.cmdInterpreter = new CommandInterpreterAPI(this) self._components.cmdInterpreter = new CommandInterpreterAPI(this, null, self.executionContext)
self._components.autoCompletePopup = new AutoCompletePopup(self._opts) self._components.autoCompletePopup = new AutoCompletePopup(self._opts)
self._components.autoCompletePopup.event.register('handleSelect', function (input) { self._components.autoCompletePopup.event.register('handleSelect', function (input) {
let textList = self._view.input.innerText.split(' ') let textList = self._view.input.innerText.split(' ')
...@@ -668,7 +668,7 @@ class Terminal extends Plugin { ...@@ -668,7 +668,7 @@ class Terminal extends Plugin {
return done(null, 'This type of command has been deprecated and is not functionning anymore. Please run remix.help() to list available commands.') return done(null, 'This type of command has been deprecated and is not functionning anymore. Please run remix.help() to list available commands.')
} }
var self = this var self = this
var context = domTerminalFeatures(self, scopedCommands) var context = domTerminalFeatures(self, scopedCommands, self.executionContext)
try { try {
var cmds = vm.createContext(Object.assign(self._jsSandboxContext, context, self._jsSandboxRegistered)) var cmds = vm.createContext(Object.assign(self._jsSandboxContext, context, self._jsSandboxRegistered))
var result = vm.runInContext(script, cmds) var result = vm.runInContext(script, cmds)
...@@ -680,7 +680,7 @@ class Terminal extends Plugin { ...@@ -680,7 +680,7 @@ class Terminal extends Plugin {
} }
} }
function domTerminalFeatures (self, scopedCommands) { function domTerminalFeatures (self, scopedCommands, executionContext) {
return { return {
swarmgw, swarmgw,
ethers, ethers,
......
...@@ -2,6 +2,7 @@ var yo = require('yo-yo') ...@@ -2,6 +2,7 @@ var yo = require('yo-yo')
var css = require('./styles/debugger-tab-styles') var css = require('./styles/debugger-tab-styles')
var DebuggerUI = require('./debugger/debuggerUI') var DebuggerUI = require('./debugger/debuggerUI')
var executionContext = require('../../execution-context')
import { ViewPlugin } from '@remixproject/engine' import { ViewPlugin } from '@remixproject/engine'
import * as packageJson from '../../../package.json' import * as packageJson from '../../../package.json'
...@@ -33,7 +34,7 @@ class DebuggerTab extends ViewPlugin { ...@@ -33,7 +34,7 @@ class DebuggerTab extends ViewPlugin {
<div class="${css.debuggerTabView}" id="debugView"> <div class="${css.debuggerTabView}" id="debugView">
<div id="debugger" class="${css.debugger}"></div> <div id="debugger" class="${css.debugger}"></div>
</div>` </div>`
this.debuggerUI = new DebuggerUI(this.el.querySelector('#debugger')) this.debuggerUI = new DebuggerUI(this.el.querySelector('#debugger'), executionContext)
return this.el return this.el
} }
......
...@@ -9,7 +9,6 @@ var SourceHighlighter = require('../../editor/sourceHighlighter') ...@@ -9,7 +9,6 @@ var SourceHighlighter = require('../../editor/sourceHighlighter')
var EventManager = require('../../../lib/events') var EventManager = require('../../../lib/events')
var executionContext = require('../../../execution-context')
var globalRegistry = require('../../../global/registry') var globalRegistry = require('../../../global/registry')
var remixLib = require('remix-lib') var remixLib = require('remix-lib')
...@@ -31,8 +30,9 @@ var css = csjs` ...@@ -31,8 +30,9 @@ var css = csjs`
class DebuggerUI { class DebuggerUI {
constructor (container) { constructor (container, executionContext) {
this.registry = globalRegistry this.registry = globalRegistry
this.executionContext = executionContext
this.event = new EventManager() this.event = new EventManager()
this.isActive = false this.isActive = false
...@@ -105,13 +105,13 @@ class DebuggerUI { ...@@ -105,13 +105,13 @@ class DebuggerUI {
getDebugWeb3 () { getDebugWeb3 () {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
executionContext.detectNetwork((error, network) => { this.executionContext.detectNetwork((error, network) => {
let web3 let web3
if (error || !network) { if (error || !network) {
web3 = init.web3DebugNode(executionContext.web3()) web3 = init.web3DebugNode(this.executionContext.web3())
} else { } else {
const webDebugNode = init.web3DebugNode(network.name) const webDebugNode = init.web3DebugNode(network.name)
web3 = !webDebugNode ? executionContext.web3() : webDebugNode web3 = !webDebugNode ? this.executionContext.web3() : webDebugNode
} }
init.extendWeb3(web3) init.extendWeb3(web3)
resolve(web3) resolve(web3)
......
var registry = require('../../global/registry') var registry = require('../../global/registry')
var remixLib = require('remix-lib') var remixLib = require('remix-lib')
var yo = require('yo-yo') var yo = require('yo-yo')
var executionContext = remixLib.execution.executionContext
var Txlistener = remixLib.execution.txListener var Txlistener = remixLib.execution.txListener
var EventsDecoder = remixLib.execution.EventsDecoder var EventsDecoder = remixLib.execution.EventsDecoder
var TransactionReceiptResolver = require('../../lib/transactionReceiptResolver') var TransactionReceiptResolver = require('../../lib/transactionReceiptResolver')
export function makeUdapp (udapp, compilersArtefacts, logHtmlCallback) { export function makeUdapp (udapp, executionContext, compilersArtefacts, logHtmlCallback) {
// ----------------- UniversalDApp ----------------- // ----------------- UniversalDApp -----------------
// TODO: to remove when possible // TODO: to remove when possible
udapp.event.register('transactionBroadcasted', (txhash, networkName) => { udapp.event.register('transactionBroadcasted', (txhash, networkName) => {
...@@ -15,7 +14,7 @@ export function makeUdapp (udapp, compilersArtefacts, logHtmlCallback) { ...@@ -15,7 +14,7 @@ export function makeUdapp (udapp, compilersArtefacts, logHtmlCallback) {
}) })
// ----------------- Tx listener ----------------- // ----------------- Tx listener -----------------
const transactionReceiptResolver = new TransactionReceiptResolver() const transactionReceiptResolver = new TransactionReceiptResolver(executionContext)
const txlistener = new Txlistener({ const txlistener = new Txlistener({
api: { api: {
......
...@@ -17,7 +17,6 @@ const DropdownLogic = require('../tabs/runTab/model/dropdownlogic.js') ...@@ -17,7 +17,6 @@ const DropdownLogic = require('../tabs/runTab/model/dropdownlogic.js')
const ContractDropdownUI = require('../tabs/runTab/contractDropdown.js') const ContractDropdownUI = require('../tabs/runTab/contractDropdown.js')
const UniversalDAppUI = require('../ui/universal-dapp-ui') const UniversalDAppUI = require('../ui/universal-dapp-ui')
const executionContext = require('../../execution-context')
const profile = { const profile = {
name: 'udapp', name: 'udapp',
...@@ -35,11 +34,12 @@ const profile = { ...@@ -35,11 +34,12 @@ const profile = {
export class RunTab extends LibraryPlugin { export class RunTab extends LibraryPlugin {
constructor (udapp, config, fileManager, editor, filePanel, compilersArtefacts, networkModule, mainView) { constructor (udapp, executionContext, config, fileManager, editor, filePanel, compilersArtefacts, networkModule, mainView) {
super(udapp, profile) super(udapp, profile)
this.event = new EventManager() this.event = new EventManager()
this.config = config this.config = config
this.udapp = udapp this.udapp = udapp
this.executionContext = executionContext
this.fileManager = fileManager this.fileManager = fileManager
this.editor = editor this.editor = editor
this.logCallback = (msg) => { mainView.getTerminal().logHtml(msg) } this.logCallback = (msg) => { mainView.getTerminal().logHtml(msg) }
...@@ -200,9 +200,9 @@ export class RunTab extends LibraryPlugin { ...@@ -200,9 +200,9 @@ export class RunTab extends LibraryPlugin {
render () { render () {
this.onActivationInternal() this.onActivationInternal()
executionContext.init(this.config) this.executionContext.init(this.config)
executionContext.stopListenOnLastBlock() this.executionContext.stopListenOnLastBlock()
executionContext.listenOnLastBlock() this.executionContext.listenOnLastBlock()
this.udapp.resetEnvironment() this.udapp.resetEnvironment()
this.renderInstanceContainer() this.renderInstanceContainer()
this.renderSettings(this.udapp) this.renderSettings(this.udapp)
......
...@@ -5,7 +5,6 @@ var remixLib = require('remix-lib') ...@@ -5,7 +5,6 @@ var remixLib = require('remix-lib')
var EventManager = require('../lib/events') var EventManager = require('../lib/events')
var CompilerImport = require('../app/compiler/compiler-imports') var CompilerImport = require('../app/compiler/compiler-imports')
var executionContext = require('../execution-context')
var toolTip = require('../app/ui/tooltip') var toolTip = require('../app/ui/tooltip')
var globalRegistry = require('../global/registry') var globalRegistry = require('../global/registry')
var SourceHighlighter = require('../app/editor/sourceHighlighter') var SourceHighlighter = require('../app/editor/sourceHighlighter')
...@@ -15,9 +14,10 @@ var solidityTypeFormatter = require('../app/tabs/debugger/debuggerUI/vmDebugger/ ...@@ -15,9 +14,10 @@ var solidityTypeFormatter = require('../app/tabs/debugger/debuggerUI/vmDebugger/
var GistHandler = require('./gist-handler') var GistHandler = require('./gist-handler')
class CmdInterpreterAPI { class CmdInterpreterAPI {
constructor (terminal, localRegistry) { constructor (terminal, localRegistry, executionContext) {
const self = this const self = this
self.event = new EventManager() self.event = new EventManager()
self.executionContext = executionContext
self._components = {} self._components = {}
self._components.registry = localRegistry || globalRegistry self._components.registry = localRegistry || globalRegistry
self._components.terminal = terminal self._components.terminal = terminal
...@@ -62,14 +62,14 @@ class CmdInterpreterAPI { ...@@ -62,14 +62,14 @@ class CmdInterpreterAPI {
debug (hash, cb) { debug (hash, cb) {
var self = this var self = this
delete self.d delete self.d
executionContext.web3().eth.getTransaction(hash, (error, tx) => { self.executionContext.web3().eth.getTransaction(hash, (error, tx) => {
if (error) return cb(error) if (error) return cb(error)
var debugSession = new RemixDebug({ var debugSession = new RemixDebug({
compilationResult: () => { compilationResult: () => {
return self._deps.compilersArtefacts['__last'].getData() return self._deps.compilersArtefacts['__last'].getData()
} }
}) })
debugSession.addProvider('web3', executionContext.web3()) debugSession.addProvider('web3', self.executionContext.web3())
debugSession.switchProvider('web3') debugSession.switchProvider('web3')
debugSession.debug(tx) debugSession.debug(tx)
self.d = debugSession self.d = debugSession
...@@ -180,7 +180,7 @@ class CmdInterpreterAPI { ...@@ -180,7 +180,7 @@ class CmdInterpreterAPI {
}) })
} }
setproviderurl (url, cb) { setproviderurl (url, cb) {
executionContext.setProviderFromEndpoint(url, 'web3', (error) => { this.executionContext.setProviderFromEndpoint(url, 'web3', (error) => {
if (error) toolTip(error) if (error) toolTip(error)
if (cb) cb() if (cb) cb()
}) })
......
'use strict' 'use strict'
var executionContext = require('../execution-context')
module.exports = class TransactionReceiptResolver { module.exports = class TransactionReceiptResolver {
constructor () { constructor (executionContext) {
this._transactionReceipts = {} this._transactionReceipts = {}
this.executionContext = executionContext
} }
resolve (tx, cb) { resolve (tx, cb) {
if (this._transactionReceipts[tx.hash]) { if (this._transactionReceipts[tx.hash]) {
return cb(null, this._transactionReceipts[tx.hash]) return cb(null, this._transactionReceipts[tx.hash])
} }
executionContext.web3().eth.getTransactionReceipt(tx.hash, (error, receipt) => { this.executionContext.web3().eth.getTransactionReceipt(tx.hash, (error, receipt) => {
if (!error) { if (!error) {
this._transactionReceipts[tx.hash] = receipt this._transactionReceipts[tx.hash] = receipt
cb(null, receipt) cb(null, receipt)
......
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