From a4299567065e4ccec0f80c5c0b34400be22f933e Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Fri, 27 Dec 2019 15:28:55 -0500 Subject: [PATCH] move compiler-data into blockchain module; load blockchain module from run-tab --- src/app.js | 13 ++++++++++--- src/app/files/compiler-metadata.js | 22 ++++++++++------------ src/app/tabs/runTab/model/blockchain.js | 4 ++++ src/app/udapp/run-tab.js | 5 ++--- 4 files changed, 26 insertions(+), 18 deletions(-) diff --git a/src/app.js b/src/app.js index d37a36fa2d..7f0af7f65f 100644 --- a/src/app.js +++ b/src/app.js @@ -24,6 +24,8 @@ var CompilerImport = require('./app/compiler/compiler-imports') var executionContext = remixLib.execution.executionContext +const Blockchain = require('./app/tabs/runTab/model/blockchain.js') + const PluginManagerComponent = require('./app/components/plugin-manager-component') const CompilersArtefacts = require('./app/compiler/compiler-artefacts') @@ -222,13 +224,17 @@ Please make a backup of your contracts and start using http://remix.ethereum.org // ----------------- fileManager servive ---------------------------- const fileManager = new FileManager(editor) registry.put({api: fileManager, name: 'filemanager'}) + + // ----------------- universal dapp: run transaction, listen on transactions, decode events + const udapp = new UniversalDApp(registry.get('config').api, executionContext) + const blockchain = new Blockchain(executionContext, udapp) + // ----------------- compilation metadata generation servive ---------------------------- - const compilerMetadataGenerator = new CompilerMetadata(executionContext, fileManager, registry.get('config').api) + const compilerMetadataGenerator = new CompilerMetadata(blockchain, 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, executionContext) + const {eventsDecoder, txlistener} = makeUdapp(udapp, executionContext, compilersArtefacts, (domEl) => mainview.getTerminal().logHtml(domEl)) // ----------------- network service (resolve network id / name) ---------------------------- const networkModule = new NetworkModule(executionContext) @@ -293,6 +299,7 @@ Please make a backup of your contracts and start using http://remix.ethereum.org registry.get('filemanager').api ) const run = new RunTab( + blockchain, udapp, executionContext, registry.get('config').api, diff --git a/src/app/files/compiler-metadata.js b/src/app/files/compiler-metadata.js index 1485455049..1b8c3653e8 100644 --- a/src/app/files/compiler-metadata.js +++ b/src/app/files/compiler-metadata.js @@ -11,14 +11,13 @@ const profile = { } class CompilerMetadata extends Plugin { - constructor (executionContext, fileManager, config) { + constructor (blockchain, 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'] - self.innerPath = 'artifacts' + this.blockchain = blockchain + this.fileManager = fileManager + this.config = config + this.networks = ['VM:-', 'main:1', 'ropsten:3', 'rinkeby:4', 'kovan:42', 'görli:5', 'Custom'] + this.innerPath = 'artifacts' } _JSONFileName (path, contractName) { @@ -93,15 +92,14 @@ class CompilerMetadata extends Plugin { // TODO: is only called by dropdownLogic and can be moved there deployMetadataOf (contractName) { return new Promise((resolve, reject) => { - var self = this - var provider = self.fileManager.currentFileProvider() - var path = self.fileManager.currentPath() + var provider = this.fileManager.currentFileProvider() + var path = this.fileManager.currentPath() if (provider && path) { - self.executionContext.detectNetwork((err, { id, name } = {}) => { + this.blockchain.detectNetwork((err, { id, name } = {}) => { if (err) { console.log(err) } else { - var fileName = self._JSONFileName(path, contractName) + var fileName = this._JSONFileName(path, contractName) provider.get(fileName, (error, content) => { if (error) return reject(error) if (!content) return resolve() diff --git a/src/app/tabs/runTab/model/blockchain.js b/src/app/tabs/runTab/model/blockchain.js index ac5cecbae1..121056ecc9 100644 --- a/src/app/tabs/runTab/model/blockchain.js +++ b/src/app/tabs/runTab/model/blockchain.js @@ -183,6 +183,10 @@ class Blockchain { })(this.networkcallid) } + detectNetwork (cb) { + return this.executionContext.detectNetwork(cb) + } + newAccount (passphraseCb, cb) { return this.udapp.newAccount('', passphraseCb, cb) } diff --git a/src/app/udapp/run-tab.js b/src/app/udapp/run-tab.js index d1ebfbacde..4a32f2d034 100644 --- a/src/app/udapp/run-tab.js +++ b/src/app/udapp/run-tab.js @@ -14,7 +14,6 @@ const Recorder = require('../tabs/runTab/model/recorder.js') const RecorderUI = require('../tabs/runTab/recorder.js') const DropdownLogic = require('../tabs/runTab/model/dropdownlogic.js') const ContractDropdownUI = require('../tabs/runTab/contractDropdown.js') -const Blockchain = require('../tabs/runTab/model/blockchain.js') const UniversalDAppUI = require('../ui/universal-dapp-ui') @@ -34,13 +33,13 @@ const profile = { export class RunTab extends LibraryPlugin { - constructor (udapp, executionContext, config, fileManager, editor, filePanel, compilersArtefacts, networkModule, mainView) { + constructor (blockchain, 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.blockchain = new Blockchain(this.executionContext, udapp) + this.blockchain = blockchain this.fileManager = fileManager this.editor = editor this.logCallback = (msg) => { mainView.getTerminal().logHtml(msg) }