pass executionContext as param instead of relying in a global var

pull/1/head
Iuri Matias 5 years ago
parent 5afeb1729a
commit 6436db7c3b
  1. 3
      package.json
  2. 4
      src/app.js
  3. 7
      src/app/panels/main-view.js
  4. 2
      src/app/panels/terminal.js
  5. 6
      src/app/tabs/debugger-tab.js
  6. 18
      src/app/tabs/network-module.js
  7. 2
      src/app/udapp/run-tab.js
  8. 17
      src/app/ui/txLogger.js
  9. 11
      src/app/ui/universal-dapp-ui.js

@ -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 ..",

@ -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,

@ -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) => {

@ -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')

@ -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 {
<div class="${css.debuggerTabView}" id="debugView">
<div id="debugger" class="${css.debugger}"></div>
</div>`
this.debuggerUI = new DebuggerUI(this.el.querySelector('#debugger'), executionContext)
this.debuggerUI = new DebuggerUI(this.el.querySelector('#debugger'), this.executionContext)
return this.el
}

@ -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)
}
}

@ -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())

@ -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) {
<span id="tx${data.tx.hash}">
<div class="${css.log}" onclick=${e => txDetails(e, tx, data, obj)}>
${checkTxStatus(data.receipt, txType)}
${context(self, {from, to, data})}
${context(self, {from, to, data}, executionContext)}
<div class=${css.buttons}>
<button class="${css.debug} btn btn-primary btn-sm" onclick=${(e) => debug(e, data, self)}>Debug</div>
</div>
@ -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) {
<span id="tx${data.tx.hash}">
<div class="${css.log}" onclick=${e => txDetails(e, tx, data, obj)}>
${checkTxStatus(data.receipt || data.tx, txType)}
${context(self, {from, to, data})}
${context(self, {from, to, data}, executionContext)}
<div class=${css.buttons}>
<div class="${css.debug} btn btn-primary btn-sm" onclick=${(e) => debug(e, data, self)}>Debug</div>
</div>
@ -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

@ -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 {

Loading…
Cancel
Save