From 6436db7c3b8fb93bae35eff60742f6343f03a91a Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Fri, 13 Dec 2019 19:26:29 -0500 Subject: [PATCH] pass executionContext as param instead of relying in a global var --- package.json | 3 +-- src/app.js | 4 ++-- src/app/panels/main-view.js | 7 +++---- src/app/panels/terminal.js | 2 +- src/app/tabs/debugger-tab.js | 6 +++--- src/app/tabs/network-module.js | 18 +++++++++--------- src/app/udapp/run-tab.js | 2 +- src/app/ui/txLogger.js | 17 ++++++++--------- src/app/ui/universal-dapp-ui.js | 11 +++++------ 9 files changed, 33 insertions(+), 37 deletions(-) diff --git a/package.json b/package.json index d141ff2c7d..b1cc9d5e56 100644 --- a/package.json +++ b/package.json @@ -143,11 +143,10 @@ "remix-ide": "./bin/remix-ide" }, "scripts": { - "setupremix": "npm run linkremixdebug && npm run linkremixlib && npm run linkremixsolidity && npm run linkremixanalyzer && npm run linkremixtests && npm run linkremixsimulator", + "setupremix": "npm run linkremixdebug && npm run linkremixlib && npm run linkremixsolidity && npm run linkremixanalyzer && npm run linkremixtests", "pullremix": "git clone https://github.com/ethereum/remix", "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 ..", - "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 ..", "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 ..", diff --git a/src/app.js b/src/app.js index ab26cd44fe..78995ef2f2 100644 --- a/src/app.js +++ b/src/app.js @@ -232,7 +232,7 @@ Please make a backup of your contracts and start using http://remix.ethereum.org const udapp = new UniversalDApp(registry.get('config').api) const {eventsDecoder, txlistener} = makeUdapp(udapp, executionContext, compilersArtefacts, (domEl) => mainview.getTerminal().logHtml(domEl)) // ----------------- network service (resolve network id / name) ---------------------------- - const networkModule = new NetworkModule() + const networkModule = new NetworkModule(executionContext) // ----------------- convert offset to line/column service ---------------------------- var offsetToLineColumnConverter = new OffsetToLineColumnConverter() registry.put({api: offsetToLineColumnConverter, name: 'offsettolinecolumnconverter'}) @@ -305,7 +305,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() + const debug = new DebuggerTab(executionContext) const test = new TestTab( registry.get('filemanager').api, filePanel, diff --git a/src/app/panels/main-view.js b/src/app/panels/main-view.js index d7b8b69751..6d8f1bde65 100644 --- a/src/app/panels/main-view.js +++ b/src/app/panels/main-view.js @@ -1,8 +1,6 @@ var yo = require('yo-yo') var EventManager = require('../../lib/events') -var executionContext = require('../../execution-context') - var Terminal = require('./terminal') var globalRegistry = require('../../global/registry') var { TabProxy } = require('./tab-proxy.js') @@ -22,7 +20,7 @@ var css = csjs` ` export class MainView { - constructor (editor, mainPanel, fileManager, appManager, txListener, eventsDecoder) { + constructor (editor, mainPanel, fileManager, appManager, txListener, eventsDecoder, executionContext) { var self = this self.event = new EventManager() self._view = {} @@ -33,6 +31,7 @@ export class MainView { self.mainPanel = mainPanel self.txListener = txListener self.eventsDecoder = eventsDecoder + self.executionContext = executionContext this.appManager = appManager this.init() } @@ -102,7 +101,7 @@ export class MainView { appManager: this.appManager, eventsDecoder: this.eventsDecoder, txListener: this.txListener, - executionContext: executionContext + executionContext: this.executionContext }, { getPosition: (event) => { diff --git a/src/app/panels/terminal.js b/src/app/panels/terminal.js index ca8e2673fa..ea9d103cc6 100644 --- a/src/app/panels/terminal.js +++ b/src/app/panels/terminal.js @@ -437,7 +437,7 @@ class Terminal extends Plugin { self._shell('remix.help()', self.commands, () => {}) self.commands.html(intro) - self._components.txLogger = new TxLogger(self._opts.eventsDecoder, self._opts.txListener, this) + self._components.txLogger = new TxLogger(self._opts.eventsDecoder, self._opts.txListener, this, self.executionContext) self._components.txLogger.event.register('debuggingRequested', (hash) => { // TODO should probably be in the run module if (!self._opts.appManager.isActive('debugger')) self._opts.appManager.activateOne('debugger') diff --git a/src/app/tabs/debugger-tab.js b/src/app/tabs/debugger-tab.js index 270db01fe6..d86db9aef5 100644 --- a/src/app/tabs/debugger-tab.js +++ b/src/app/tabs/debugger-tab.js @@ -2,7 +2,6 @@ var yo = require('yo-yo') var css = require('./styles/debugger-tab-styles') var DebuggerUI = require('./debugger/debuggerUI') -var executionContext = require('../../execution-context') import { ViewPlugin } from '@remixproject/engine' import * as packageJson from '../../../package.json' @@ -22,9 +21,10 @@ const profile = { class DebuggerTab extends ViewPlugin { - constructor () { + constructor (executionContext) { super(profile) this.el = null + this.executionContext = executionContext } render () { @@ -34,7 +34,7 @@ class DebuggerTab extends ViewPlugin {
` - this.debuggerUI = new DebuggerUI(this.el.querySelector('#debugger'), executionContext) + this.debuggerUI = new DebuggerUI(this.el.querySelector('#debugger'), this.executionContext) return this.el } diff --git a/src/app/tabs/network-module.js b/src/app/tabs/network-module.js index c57893578b..4ead25261e 100644 --- a/src/app/tabs/network-module.js +++ b/src/app/tabs/network-module.js @@ -1,4 +1,3 @@ -const executionContext = require('../../execution-context') import { Plugin } from '@remixproject/engine' import * as packageJson from '../../../package.json' @@ -15,10 +14,11 @@ export const profile = { // - methods: ['getNetworkProvider', 'getEndpoint', 'detectNetwork', 'addNetwork', 'removeNetwork'] export class NetworkModule extends Plugin { - constructor () { + constructor (executionContext) { super(profile) + this.executionContext = executionContext // TODO: See with remix-lib to make sementic coherent - executionContext.event.register('contextChanged', (provider) => { + this.executionContext.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 executionContext.getProvider() + return this.executionContext.getProvider() } /** Return the current network */ detectNetwork () { return new Promise((resolve, reject) => { - executionContext.detectNetwork((error, network) => { + this.executionContext.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 = executionContext.getProvider() + const provider = this.executionContext.getProvider() if (provider !== 'web3') { throw new Error('no endpoint: current provider is either injected or vm') } - return executionContext.web3().currentProvider.host + return this.executionContext.web3().currentProvider.host } /** Add a custom network to the list of available networks */ addNetwork (customNetwork) { - executionContext.addProvider(customNetwork) + this.executionContext.addProvider(customNetwork) } /** Remove a network to the list of availble networks */ removeNetwork (name) { - executionContext.removeProvider(name) + this.executionContext.removeProvider(name) } } diff --git a/src/app/udapp/run-tab.js b/src/app/udapp/run-tab.js index 349e1b43a3..2bd67d3b8d 100644 --- a/src/app/udapp/run-tab.js +++ b/src/app/udapp/run-tab.js @@ -49,7 +49,7 @@ export class RunTab extends LibraryPlugin { } onActivationInternal () { - this.udappUI = new UniversalDAppUI(this.udapp, this.logCallback) + this.udappUI = new UniversalDAppUI(this.udapp, this.logCallback, this.executionContext) this.udapp.resetAPI({ getAddress: (cb) => { cb(null, $('#txorigin').val()) diff --git a/src/app/ui/txLogger.js b/src/app/ui/txLogger.js index 0d694b2295..010a277715 100644 --- a/src/app/ui/txLogger.js +++ b/src/app/ui/txLogger.js @@ -8,7 +8,6 @@ var remixLib = require('remix-lib') var EventManager = require('../../lib/events') var helper = require('../../lib/helper') -var executionContext = require('../../execution-context') var modalDialog = require('./modal-dialog-custom') var typeConversion = remixLib.execution.typeConversion var globlalRegistry = require('../../global/registry') @@ -117,7 +116,7 @@ var css = csjs` * */ class TxLogger { - constructor (eventsDecoder, txListener, terminal) { + constructor (eventsDecoder, txListener, terminal, executionContext) { this.event = new EventManager() this.seen = {} function filterTx (value, query) { @@ -140,7 +139,7 @@ class TxLogger { if (data.tx.isCall) { el = renderCall(this, data) } else { - el = renderKnownTransaction(this, data) + el = renderKnownTransaction(this, data, executionContext) } this.seen[data.tx.hash] = el append(el) @@ -149,7 +148,7 @@ class TxLogger { this.logUnknownTX = this.terminal.registerCommand('unknownTransaction', (args, cmds, append) => { // triggered for transaction AND call var data = args[0] - var el = renderUnknownTransaction(this, data) + var el = renderUnknownTransaction(this, data, executionContext) append(el) }, { activate: false, filterFn: filterTx }) @@ -205,7 +204,7 @@ function log (self, tx, receipt) { } } -function renderKnownTransaction (self, data) { +function renderKnownTransaction (self, data, executionContext) { var from = data.tx.from var to = data.resolvedData.contractName + '.' + data.resolvedData.fn var obj = {from, to} @@ -214,7 +213,7 @@ function renderKnownTransaction (self, data) {
txDetails(e, tx, data, obj)}> ${checkTxStatus(data.receipt, txType)} - ${context(self, {from, to, data})} + ${context(self, {from, to, data}, executionContext)}
@@ -251,7 +250,7 @@ function renderCall (self, data) { return tx } -function renderUnknownTransaction (self, data) { +function renderUnknownTransaction (self, data, executionContext) { var from = data.tx.from var to = data.tx.to var obj = {from, to} @@ -260,7 +259,7 @@ function renderUnknownTransaction (self, data) {
txDetails(e, tx, data, obj)}> ${checkTxStatus(data.receipt || data.tx, txType)} - ${context(self, {from, to, data})} + ${context(self, {from, to, data}, executionContext)}
debug(e, data, self)}>Debug
@@ -291,7 +290,7 @@ function checkTxStatus (tx, type) { } } -function context (self, opts) { +function context (self, opts, executionContext) { var data = opts.data || '' var from = opts.from ? helper.shortenHexData(opts.from) : '' var to = opts.to diff --git a/src/app/ui/universal-dapp-ui.js b/src/app/ui/universal-dapp-ui.js index cc9a8c3e44..a02e616280 100644 --- a/src/app/ui/universal-dapp-ui.js +++ b/src/app/ui/universal-dapp-ui.js @@ -15,17 +15,16 @@ var typeConversion = remixLib.execution.typeConversion var txExecution = remixLib.execution.txExecution var txFormat = remixLib.execution.txFormat -var executionContext = require('../../execution-context') - var confirmDialog = require('./confirmDialog') var modalCustom = require('./modal-dialog-custom') var modalDialog = require('./modaldialog') var TreeView = require('./TreeView') -function UniversalDAppUI (udapp, logCallback) { +function UniversalDAppUI (udapp, logCallback, executionContext) { this.udapp = udapp this.logCallback = logCallback this.compilerData = {contractsDetails: {}} + this.executionContext = executionContext } function decodeResponseToTreeView (response, fnabi) { @@ -181,7 +180,7 @@ UniversalDAppUI.prototype.getCallButton = function (args) { cb(txFeeText, priceStatus) }, (cb) => { - executionContext.web3().eth.getGasPrice((error, gasPrice) => { + self.executionContext.web3().eth.getGasPrice((error, gasPrice) => { const warnMessage = ' Please fix this issue before sending any transaction. ' if (error) { return cb('Unable to retrieve the current network gas price.' + warnMessage + error) @@ -263,7 +262,7 @@ UniversalDAppUI.prototype.getCallButton = function (args) { if (args.funABI.type === 'fallback') data.dataHex = value self.udapp.callFunction(args.address, data, args.funABI, confirmationCb, continueCb, promptCb, (error, txResult) => { if (!error) { - var isVM = executionContext.isVM() + var isVM = self.executionContext.isVM() if (isVM) { var vmError = txExecution.checkVMError(txResult) if (vmError.error) { @@ -272,7 +271,7 @@ UniversalDAppUI.prototype.getCallButton = function (args) { } } if (lookupOnly) { - const decoded = decodeResponseToTreeView(executionContext.isVM() ? txResult.result.execResult.returnValue : ethJSUtil.toBuffer(txResult.result), args.funABI) + const decoded = decodeResponseToTreeView(self.executionContext.isVM() ? txResult.result.execResult.returnValue : ethJSUtil.toBuffer(txResult.result), args.funABI) outputCb(decoded) } } else {