use blockchain module instead of executio ncontext for cmd interpreter

pull/5370/head
Iuri Matias 5 years ago
parent a429956706
commit 7837314227
  1. 2
      src/app.js
  2. 6
      src/app/panels/main-view.js
  3. 9
      src/app/panels/terminal.js
  4. 3
      src/app/tabs/runTab/model/blockchain.js
  5. 10
      src/lib/cmdInterpreterAPI.js

@ -255,7 +255,7 @@ Please make a backup of your contracts and start using http://remix.ethereum.org
// LAYOUT & SYSTEM VIEWS // LAYOUT & SYSTEM VIEWS
const appPanel = new MainPanel() const appPanel = new MainPanel()
const mainview = new MainView(editor, appPanel, fileManager, appManager, txlistener, eventsDecoder, executionContext) const mainview = new MainView(editor, appPanel, fileManager, appManager, txlistener, eventsDecoder, executionContext, blockchain)
registry.put({ api: mainview, name: 'mainview' }) registry.put({ api: mainview, name: 'mainview' })
appManager.register([ appManager.register([

@ -20,7 +20,7 @@ var css = csjs`
` `
export class MainView { export class MainView {
constructor (editor, mainPanel, fileManager, appManager, txListener, eventsDecoder, executionContext) { constructor (editor, mainPanel, fileManager, appManager, txListener, eventsDecoder, executionContext, blockchain) {
var self = this var self = this
self.event = new EventManager() self.event = new EventManager()
self._view = {} self._view = {}
@ -32,6 +32,7 @@ export class MainView {
self.txListener = txListener self.txListener = txListener
self.eventsDecoder = eventsDecoder self.eventsDecoder = eventsDecoder
self.executionContext = executionContext self.executionContext = executionContext
self.blockchain = blockchain
this.appManager = appManager this.appManager = appManager
this.init() this.init()
} }
@ -101,7 +102,8 @@ export class MainView {
appManager: this.appManager, appManager: this.appManager,
eventsDecoder: this.eventsDecoder, eventsDecoder: this.eventsDecoder,
txListener: this.txListener, txListener: this.txListener,
executionContext: this.executionContext executionContext: this.executionContext,
blockchain: this.blockchain
}, },
{ {
getPosition: (event) => { getPosition: (event) => {

@ -42,6 +42,7 @@ class Terminal extends Plugin {
var self = this var self = this
self.event = new EventManager() self.event = new EventManager()
self.executionContext = opts.executionContext self.executionContext = opts.executionContext
self.blockchain = opts.blockchain
self._api = api self._api = api
self._opts = opts self._opts = opts
self.data = { self.data = {
@ -52,7 +53,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, null, self.executionContext) self._components.cmdInterpreter = new CommandInterpreterAPI(this, null, self.blockchain)
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 +669,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, self.executionContext) var context = domTerminalFeatures(self, scopedCommands, self.blockchain)
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,12 +681,12 @@ class Terminal extends Plugin {
} }
} }
function domTerminalFeatures (self, scopedCommands, executionContext) { function domTerminalFeatures (self, scopedCommands, blockchain) {
return { return {
swarmgw, swarmgw,
ethers, ethers,
remix: self._components.cmdInterpreter, remix: self._components.cmdInterpreter,
web3: new Web3(executionContext.web3().currentProvider), web3: new Web3(blockchain.web3().currentProvider),
console: { console: {
log: function () { scopedCommands.log.apply(scopedCommands, arguments) }, log: function () { scopedCommands.log.apply(scopedCommands, arguments) },
info: function () { scopedCommands.info.apply(scopedCommands, arguments) }, info: function () { scopedCommands.info.apply(scopedCommands, arguments) },

@ -244,6 +244,9 @@ class Blockchain {
} }
} }
web3 () {
return this.executionContext.web3()
}
} }
module.exports = Blockchain module.exports = Blockchain

@ -14,10 +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, executionContext) { constructor (terminal, localRegistry, blockchain) {
const self = this const self = this
self.event = new EventManager() self.event = new EventManager()
self.executionContext = executionContext self.blockchain = blockchain
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 {
debug (hash, cb) { debug (hash, cb) {
var self = this var self = this
delete self.d delete self.d
self.executionContext.web3().eth.getTransaction(hash, (error, tx) => { self.blockchain.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', self.executionContext.web3()) debugSession.addProvider('web3', self.blockchain.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 {
}) })
} }
setproviderurl (url, cb) { setproviderurl (url, cb) {
this.executionContext.setProviderFromEndpoint(url, 'web3', (error) => { this.blockchain.setProviderFromEndpoint(url, 'web3', (error) => {
if (error) toolTip(error) if (error) toolTip(error)
if (cb) cb() if (cb) cb()
}) })

Loading…
Cancel
Save