diff --git a/src/app.js b/src/app.js index 78995ef2f2..fe9f4f2b77 100644 --- a/src/app.js +++ b/src/app.js @@ -229,7 +229,7 @@ Please make a backup of your contracts and start using http://remix.ethereum.org const compilersArtefacts = new CompilersArtefacts() // store all the compilation results (key represent a compiler name) registry.put({api: compilersArtefacts, name: 'compilersartefacts'}) // ----------------- 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, executionContext) const {eventsDecoder, txlistener} = makeUdapp(udapp, executionContext, compilersArtefacts, (domEl) => mainview.getTerminal().logHtml(domEl)) // ----------------- network service (resolve network id / name) ---------------------------- const networkModule = new NetworkModule(executionContext) diff --git a/src/app/tabs/runTab/model/dropdownlogic.js b/src/app/tabs/runTab/model/dropdownlogic.js index a5c603d6fe..742fa7d05c 100644 --- a/src/app/tabs/runTab/model/dropdownlogic.js +++ b/src/app/tabs/runTab/model/dropdownlogic.js @@ -2,7 +2,6 @@ var ethJSUtil = require('ethereumjs-util') var remixLib = require('remix-lib') var txHelper = remixLib.execution.txHelper var txFormat = remixLib.execution.txFormat -var executionContext = remixLib.execution.executionContext var typeConversion = remixLib.execution.typeConversion var txExecution = remixLib.execution.txExecution var CompilerAbstract = require('../../../compiler/compiler-abstract') @@ -10,8 +9,9 @@ var EventManager = remixLib.EventManager var Web3 = require('web3') class DropdownLogic { - constructor (fileManager, compilersArtefacts, config, editor, udapp, filePanel, runView) { + constructor (executionContext, fileManager, compilersArtefacts, config, editor, udapp, filePanel, runView) { this.compilersArtefacts = compilersArtefacts + this.executionContext = executionContext this.config = config this.editor = editor this.udapp = udapp @@ -121,11 +121,11 @@ class DropdownLogic { } getGasPrice (cb) { - return executionContext.web3().eth.getGasPrice(cb) + return this.executionContext.web3().eth.getGasPrice(cb) } isVM () { - return executionContext.isVM() + return this.executionContext.isVM() } // TODO: check if selectedContract and data can be joined @@ -159,7 +159,7 @@ class DropdownLogic { cb(txFeeText, priceStatus) }, (cb) => { - executionContext.web3().eth.getGasPrice((error, gasPrice) => { + this.executionContext.web3().eth.getGasPrice((error, gasPrice) => { var warnMessage = ' Please fix this issue before sending any transaction. ' if (error) { return cb('Unable to retrieve the current network gas price.' + warnMessage + error) @@ -197,7 +197,7 @@ class DropdownLogic { if (error) { return finalCb(`creation of ${selectedContract.name} errored: ${error}`) } - var isVM = executionContext.isVM() + var isVM = this.executionContext.isVM() if (isVM) { var vmError = txExecution.checkVMError(txResult) if (vmError.error) { diff --git a/src/app/tabs/runTab/model/recorder.js b/src/app/tabs/runTab/model/recorder.js index c6c68f4d94..d81481fd55 100644 --- a/src/app/tabs/runTab/model/recorder.js +++ b/src/app/tabs/runTab/model/recorder.js @@ -2,7 +2,6 @@ var async = require('async') var ethutil = require('ethereumjs-util') var remixLib = require('remix-lib') var EventManager = remixLib.EventManager -var executionContext = remixLib.execution.executionContext var format = remixLib.execution.txFormat var txHelper = remixLib.execution.txHelper var typeConversion = remixLib.execution.typeConversion @@ -15,9 +14,10 @@ var Web3 = require('web3') * */ class Recorder { - constructor (udapp, fileManager, config) { + constructor (executionContext, udapp, fileManager, config) { var self = this self.event = new EventManager() + self.executionContext = executionContext self.data = { _listen: true, _replay: false, journal: [], _createdContracts: {}, _createdContractsReverse: {}, _usedAccounts: {}, _abis: {}, _contractABIReferences: {}, _linkReferences: {} } this.udapp = udapp this.fileManager = fileManager @@ -74,7 +74,7 @@ class Recorder { if (error) return console.log(error) if (call) return - const rawAddress = executionContext.isVM() ? txResult.result.createdAddress : txResult.result.contractAddress + const rawAddress = this.executionContext.isVM() ? txResult.result.createdAddress : txResult.result.contractAddress if (!rawAddress) return // not a contract creation const stringAddress = this.addressToString(rawAddress) const address = ethutil.toChecksumAddress(stringAddress) @@ -82,7 +82,7 @@ class Recorder { this.data._createdContracts[address] = timestamp this.data._createdContractsReverse[timestamp] = address }) - executionContext.event.register('contextChanged', this.clearAll.bind(this)) + this.executionContext.event.register('contextChanged', this.clearAll.bind(this)) this.event.register('newTxRecorded', (count) => { this.event.trigger('recorderCountChange', [count]) }) @@ -261,7 +261,7 @@ class Recorder { console.error(err) logCallBack(err + '. Execution failed at ' + index) } else { - const rawAddress = executionContext.isVM() ? txResult.result.createdAddress : txResult.result.contractAddress + const rawAddress = this.executionContext.isVM() ? txResult.result.createdAddress : txResult.result.contractAddress if (rawAddress) { const stringAddress = self.addressToString(rawAddress) const address = ethutil.toChecksumAddress(stringAddress) @@ -335,7 +335,7 @@ class Recorder { cb(txFeeText, priceStatus) }, (cb) => { - executionContext.web3().eth.getGasPrice((error, gasPrice) => { + this.executionContext.web3().eth.getGasPrice((error, gasPrice) => { var warnMessage = ' Please fix this issue before sending any transaction. ' if (error) { return cb('Unable to retrieve the current network gas price.' + warnMessage + error) diff --git a/src/app/tabs/runTab/model/settings.js b/src/app/tabs/runTab/model/settings.js index 3d514487d2..e126e583f0 100644 --- a/src/app/tabs/runTab/model/settings.js +++ b/src/app/tabs/runTab/model/settings.js @@ -4,11 +4,11 @@ var remixLib = require('remix-lib') var Web3 = require('web3') const addTooltip = require('../../../ui/tooltip') var EventManager = remixLib.EventManager -var executionContext = remixLib.execution.executionContext class Settings { - constructor (udapp) { + constructor (executionContext, udapp) { + this.executionContext = executionContext this.udapp = udapp this.event = new EventManager() @@ -16,15 +16,15 @@ class Settings { this.event.trigger('transactionExecuted', [error, from, to, data, lookupOnly, txResult]) }) - executionContext.event.register('contextChanged', (context, silent) => { + this.executionContext.event.register('contextChanged', (context, silent) => { this.event.trigger('contextChanged', [context, silent]) }) - executionContext.event.register('addProvider', (network) => { + this.executionContext.event.register('addProvider', (network) => { this.event.trigger('addProvider', [network]) }) - executionContext.event.register('removeProvider', (name) => { + this.executionContext.event.register('removeProvider', (name) => { this.event.trigger('removeProvider', [name]) }) @@ -32,15 +32,15 @@ class Settings { } changeExecutionContext (context, confirmCb, infoCb, cb) { - return executionContext.executionContextChange(context, null, confirmCb, infoCb, cb) + return this.executionContext.executionContextChange(context, null, confirmCb, infoCb, cb) } setProviderFromEndpoint (target, context, cb) { - return executionContext.setProviderFromEndpoint(target, context, cb) + return this.executionContext.setProviderFromEndpoint(target, context, cb) } getProvider () { - return executionContext.getProvider() + return this.executionContext.getProvider() } getAccountBalanceForAddress (address, cb) { @@ -50,7 +50,7 @@ class Settings { updateNetwork (cb) { this.networkcallid++ ((callid) => { - executionContext.detectNetwork((err, { id, name } = {}) => { + this.executionContext.detectNetwork((err, { id, name } = {}) => { if (this.networkcallid > callid) return this.networkcallid++ if (err) { @@ -70,18 +70,18 @@ class Settings { } isWeb3Provider () { - var isVM = executionContext.isVM() - var isInjected = executionContext.getProvider() === 'injected' + var isVM = this.executionContext.isVM() + var isInjected = this.executionContext.getProvider() === 'injected' return (!isVM && !isInjected) } isInjectedWeb3 () { - return executionContext.getProvider() === 'injected' + return this.executionContext.getProvider() === 'injected' } signMessage (message, account, passphrase, cb) { - var isVM = executionContext.isVM() - var isInjected = executionContext.getProvider() === 'injected' + var isVM = this.executionContext.isVM() + var isInjected = this.executionContext.getProvider() === 'injected' if (isVM) { const personalMsg = ethJSUtil.hashPersonalMessage(Buffer.from(message)) @@ -99,7 +99,7 @@ class Settings { const hashedMsg = Web3.utils.sha3(message) try { addTooltip('Please check your provider to approve') - executionContext.web3().eth.sign(account, hashedMsg, (error, signedData) => { + this.executionContext.web3().eth.sign(account, hashedMsg, (error, signedData) => { cb(error.message, hashedMsg, signedData) }) } catch (e) { @@ -110,7 +110,7 @@ class Settings { const hashedMsg = Web3.utils.sha3(message) try { - var personal = new Personal(executionContext.web3().currentProvider) + var personal = new Personal(this.executionContext.web3().currentProvider) personal.sign(hashedMsg, account, passphrase, (error, signedData) => { cb(error.message, hashedMsg, signedData) }) diff --git a/src/app/udapp/make-udapp.js b/src/app/udapp/make-udapp.js index d168432d73..04f32fef74 100644 --- a/src/app/udapp/make-udapp.js +++ b/src/app/udapp/make-udapp.js @@ -28,7 +28,7 @@ export function makeUdapp (udapp, executionContext, compilersArtefacts, logHtmlC }, event: { udapp: udapp.event - }}) + }}, executionContext) registry.put({api: txlistener, name: 'txlistener'}) udapp.startListening(txlistener) diff --git a/src/app/udapp/run-tab.js b/src/app/udapp/run-tab.js index 2bd67d3b8d..781545e404 100644 --- a/src/app/udapp/run-tab.js +++ b/src/app/udapp/run-tab.js @@ -122,7 +122,7 @@ export class RunTab extends LibraryPlugin { } renderSettings (udapp) { - var settings = new Settings(udapp) + var settings = new Settings(this.executionContext, udapp) this.settingsUI = new SettingsUI(settings, this.networkModule) this.settingsUI.event.register('clearInstance', () => { @@ -131,7 +131,7 @@ export class RunTab extends LibraryPlugin { } renderDropdown (udappUI, fileManager, compilersArtefacts, config, editor, udapp, filePanel, logCallback) { - const dropdownLogic = new DropdownLogic(fileManager, compilersArtefacts, config, editor, udapp, filePanel, this) + const dropdownLogic = new DropdownLogic(this.executionContext, fileManager, compilersArtefacts, config, editor, udapp, filePanel, this) this.contractDropdownUI = new ContractDropdownUI(dropdownLogic, logCallback) this.contractDropdownUI.event.register('clearInstance', () => { @@ -149,7 +149,7 @@ export class RunTab extends LibraryPlugin { renderRecorder (udapp, udappUI, fileManager, config, logCallback) { this.recorderCount = yo`0` - const recorder = new Recorder(udapp, fileManager, config) + const recorder = new Recorder(this.executionContext, udapp, fileManager, config) recorder.event.register('recorderCountChange', (count) => { this.recorderCount.innerText = count })