pass executionContext as param instead of relying in a global var

pull/1/head
Iuri Matias 5 years ago
parent e448ded402
commit 5afeb1729a
  1. 3
      package.json
  2. 7
      src/app.js
  3. 6
      src/app/files/compiler-metadata.js
  4. 5
      src/app/panels/main-view.js
  5. 8
      src/app/panels/terminal.js
  6. 3
      src/app/tabs/debugger-tab.js
  7. 10
      src/app/tabs/debugger/debuggerUI.js
  8. 5
      src/app/udapp/make-udapp.js
  9. 10
      src/app/udapp/run-tab.js
  10. 10
      src/lib/cmdInterpreterAPI.js
  11. 6
      src/lib/transactionReceiptResolver.js

@ -143,10 +143,11 @@
"remix-ide": "./bin/remix-ide"
},
"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",
"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 ..",

@ -23,6 +23,8 @@ var toolTip = require('./app/ui/tooltip')
var CompilerMetadata = require('./app/files/compiler-metadata')
var CompilerImport = require('./app/compiler/compiler-imports')
var executionContext = require('./execution-context')
const PluginManagerComponent = require('./app/components/plugin-manager-component')
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
const fileManager = new FileManager(editor)
registry.put({api: fileManager, name: 'filemanager'})
// ----------------- 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) ----------------------------
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 {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) ----------------------------
const networkModule = new NetworkModule()
// ----------------- convert offset to line/column service ----------------------------
@ -293,6 +295,7 @@ Please make a backup of your contracts and start using http://remix.ethereum.org
)
const run = new RunTab(
udapp,
executionContext,
registry.get('config').api,
registry.get('filemanager').api,
registry.get('editor').api,

@ -1,5 +1,4 @@
'use strict'
var executionContext = require('../../execution-context')
var CompilerAbstract = require('../compiler/compiler-abstract')
import { Plugin } from '@remixproject/engine'
import * as packageJson from '../../../package.json'
@ -12,9 +11,10 @@ const profile = {
}
class CompilerMetadata extends Plugin {
constructor (fileManager, config) {
constructor (executionContext, fileManager, config) {
super(profile)
var self = this
self.executionContext = executionContext
self.fileManager = fileManager
self.config = config
self.networks = ['VM:-', 'main:1', 'ropsten:3', 'rinkeby:4', 'kovan:42', 'görli:5', 'Custom']
@ -97,7 +97,7 @@ class CompilerMetadata extends Plugin {
var provider = self.fileManager.currentFileProvider()
var path = self.fileManager.currentPath()
if (provider && path) {
executionContext.detectNetwork((err, { id, name } = {}) => {
self.executionContext.detectNetwork((err, { id, name } = {}) => {
if (err) {
console.log(err)
} else {

@ -1,6 +1,8 @@
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')
@ -99,7 +101,8 @@ export class MainView {
self._components.terminal = new Terminal({
appManager: this.appManager,
eventsDecoder: this.eventsDecoder,
txListener: this.txListener
txListener: this.txListener,
executionContext: executionContext
},
{
getPosition: (event) => {

@ -10,7 +10,6 @@ var Web3 = require('web3')
var swarmgw = require('swarmgw')()
var CommandInterpreterAPI = require('../../lib/cmdInterpreterAPI')
var executionContext = require('../../execution-context')
var AutoCompletePopup = require('../ui/auto-complete-popup')
var TxLogger = require('../../app/ui/txLogger')
@ -42,6 +41,7 @@ class Terminal extends Plugin {
super(profile)
var self = this
self.event = new EventManager()
self.executionContext = opts.executionContext
self._api = api
self._opts = opts
self.data = {
@ -52,7 +52,7 @@ class Terminal extends Plugin {
}
self._view = { el: null, bar: null, input: null, term: null, journal: null, cli: null }
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.event.register('handleSelect', function (input) {
let textList = self._view.input.innerText.split(' ')
@ -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.')
}
var self = this
var context = domTerminalFeatures(self, scopedCommands)
var context = domTerminalFeatures(self, scopedCommands, self.executionContext)
try {
var cmds = vm.createContext(Object.assign(self._jsSandboxContext, context, self._jsSandboxRegistered))
var result = vm.runInContext(script, cmds)
@ -680,7 +680,7 @@ class Terminal extends Plugin {
}
}
function domTerminalFeatures (self, scopedCommands) {
function domTerminalFeatures (self, scopedCommands, executionContext) {
return {
swarmgw,
ethers,

@ -2,6 +2,7 @@ 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'
@ -33,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.debuggerUI = new DebuggerUI(this.el.querySelector('#debugger'), executionContext)
return this.el
}

@ -9,7 +9,6 @@ var SourceHighlighter = require('../../editor/sourceHighlighter')
var EventManager = require('../../../lib/events')
var executionContext = require('../../../execution-context')
var globalRegistry = require('../../../global/registry')
var remixLib = require('remix-lib')
@ -31,8 +30,9 @@ var css = csjs`
class DebuggerUI {
constructor (container) {
constructor (container, executionContext) {
this.registry = globalRegistry
this.executionContext = executionContext
this.event = new EventManager()
this.isActive = false
@ -105,13 +105,13 @@ class DebuggerUI {
getDebugWeb3 () {
return new Promise((resolve, reject) => {
executionContext.detectNetwork((error, network) => {
this.executionContext.detectNetwork((error, network) => {
let web3
if (error || !network) {
web3 = init.web3DebugNode(executionContext.web3())
web3 = init.web3DebugNode(this.executionContext.web3())
} else {
const webDebugNode = init.web3DebugNode(network.name)
web3 = !webDebugNode ? executionContext.web3() : webDebugNode
web3 = !webDebugNode ? this.executionContext.web3() : webDebugNode
}
init.extendWeb3(web3)
resolve(web3)

@ -1,12 +1,11 @@
var registry = require('../../global/registry')
var remixLib = require('remix-lib')
var yo = require('yo-yo')
var executionContext = remixLib.execution.executionContext
var Txlistener = remixLib.execution.txListener
var EventsDecoder = remixLib.execution.EventsDecoder
var TransactionReceiptResolver = require('../../lib/transactionReceiptResolver')
export function makeUdapp (udapp, compilersArtefacts, logHtmlCallback) {
export function makeUdapp (udapp, executionContext, compilersArtefacts, logHtmlCallback) {
// ----------------- UniversalDApp -----------------
// TODO: to remove when possible
udapp.event.register('transactionBroadcasted', (txhash, networkName) => {
@ -15,7 +14,7 @@ export function makeUdapp (udapp, compilersArtefacts, logHtmlCallback) {
})
// ----------------- Tx listener -----------------
const transactionReceiptResolver = new TransactionReceiptResolver()
const transactionReceiptResolver = new TransactionReceiptResolver(executionContext)
const txlistener = new Txlistener({
api: {

@ -17,7 +17,6 @@ const DropdownLogic = require('../tabs/runTab/model/dropdownlogic.js')
const ContractDropdownUI = require('../tabs/runTab/contractDropdown.js')
const UniversalDAppUI = require('../ui/universal-dapp-ui')
const executionContext = require('../../execution-context')
const profile = {
name: 'udapp',
@ -35,11 +34,12 @@ const profile = {
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)
this.event = new EventManager()
this.config = config
this.udapp = udapp
this.executionContext = executionContext
this.fileManager = fileManager
this.editor = editor
this.logCallback = (msg) => { mainView.getTerminal().logHtml(msg) }
@ -200,9 +200,9 @@ export class RunTab extends LibraryPlugin {
render () {
this.onActivationInternal()
executionContext.init(this.config)
executionContext.stopListenOnLastBlock()
executionContext.listenOnLastBlock()
this.executionContext.init(this.config)
this.executionContext.stopListenOnLastBlock()
this.executionContext.listenOnLastBlock()
this.udapp.resetEnvironment()
this.renderInstanceContainer()
this.renderSettings(this.udapp)

@ -5,7 +5,6 @@ var remixLib = require('remix-lib')
var EventManager = require('../lib/events')
var CompilerImport = require('../app/compiler/compiler-imports')
var executionContext = require('../execution-context')
var toolTip = require('../app/ui/tooltip')
var globalRegistry = require('../global/registry')
var SourceHighlighter = require('../app/editor/sourceHighlighter')
@ -15,9 +14,10 @@ var solidityTypeFormatter = require('../app/tabs/debugger/debuggerUI/vmDebugger/
var GistHandler = require('./gist-handler')
class CmdInterpreterAPI {
constructor (terminal, localRegistry) {
constructor (terminal, localRegistry, executionContext) {
const self = this
self.event = new EventManager()
self.executionContext = executionContext
self._components = {}
self._components.registry = localRegistry || globalRegistry
self._components.terminal = terminal
@ -62,14 +62,14 @@ class CmdInterpreterAPI {
debug (hash, cb) {
var self = this
delete self.d
executionContext.web3().eth.getTransaction(hash, (error, tx) => {
self.executionContext.web3().eth.getTransaction(hash, (error, tx) => {
if (error) return cb(error)
var debugSession = new RemixDebug({
compilationResult: () => {
return self._deps.compilersArtefacts['__last'].getData()
}
})
debugSession.addProvider('web3', executionContext.web3())
debugSession.addProvider('web3', self.executionContext.web3())
debugSession.switchProvider('web3')
debugSession.debug(tx)
self.d = debugSession
@ -180,7 +180,7 @@ class CmdInterpreterAPI {
})
}
setproviderurl (url, cb) {
executionContext.setProviderFromEndpoint(url, 'web3', (error) => {
this.executionContext.setProviderFromEndpoint(url, 'web3', (error) => {
if (error) toolTip(error)
if (cb) cb()
})

@ -1,16 +1,16 @@
'use strict'
var executionContext = require('../execution-context')
module.exports = class TransactionReceiptResolver {
constructor () {
constructor (executionContext) {
this._transactionReceipts = {}
this.executionContext = executionContext
}
resolve (tx, cb) {
if (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) {
this._transactionReceipts[tx.hash] = receipt
cb(null, receipt)

Loading…
Cancel
Save