From f37bee213fa3c302775203d828a1b6623a01689c Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Mon, 23 Dec 2019 18:33:48 -0500 Subject: [PATCH] refactor contract dropdown logic --- src/app/tabs/runTab/contractDropdown.js | 18 ++++++++++----- src/app/tabs/runTab/model/dropdownlogic.js | 26 ++++++---------------- src/app/udapp/run-tab.js | 6 +++-- 3 files changed, 24 insertions(+), 26 deletions(-) diff --git a/src/app/tabs/runTab/contractDropdown.js b/src/app/tabs/runTab/contractDropdown.js index 2f6c6ae945..8215c36a82 100644 --- a/src/app/tabs/runTab/contractDropdown.js +++ b/src/app/tabs/runTab/contractDropdown.js @@ -8,9 +8,10 @@ var modalDialog = require('../../ui/modaldialog') var MultiParamManager = require('../../ui/multiParamManager') class ContractDropdownUI { - constructor (dropdownLogic, logCallback) { + constructor (dropdownLogic, logCallback, runView) { this.dropdownLogic = dropdownLogic this.logCallback = logCallback + this.runView = runView this.event = new EventManager() this.listenToEvents() @@ -39,8 +40,6 @@ class ContractDropdownUI { document.querySelector(`.${css.contractNames}`).classList.add(css.contractNamesError) } }) - - this.dropdownLogic.event.register('currentFileChanged', this.changeCurrentFile.bind(this)) } render () { @@ -176,6 +175,15 @@ class ContractDropdownUI { this.event.trigger('newContractInstanceAdded', [contractObject, address, contractObject.name]) } + let contractMetadata + try { + contractMetadata = await this.runView.call('compilerMetadata', 'deployMetadataOf', selectedContract.name) + } catch (error) { + return statusCb(`creation of ${selectedContract.name} errored: ` + error) + } + + const compilerContracts = this.dropdownLogic.getCompilerContracts() + if (selectedContract.isOverSizeLimit()) { return modalDialog('Contract code size over limit', yo`
Contract creation initialization returns data with length of more than 24576 bytes. The deployment will likely fails.
More info: eip-170 @@ -183,7 +191,7 @@ class ContractDropdownUI { { label: 'Force Send', fn: () => { - this.dropdownLogic.deployContract(selectedContract, args, {continueCb, promptCb, statusCb, finalCb}, {modalDialog, confirmDialog}) + this.dropdownLogic.deployContract(selectedContract, args, contractMetadata, compilerContracts, {continueCb, promptCb, statusCb, finalCb}, {modalDialog, confirmDialog}) }}, { label: 'Cancel', fn: () => { @@ -191,7 +199,7 @@ class ContractDropdownUI { } }) } - this.dropdownLogic.deployContract(selectedContract, args, {continueCb, promptCb, statusCb, finalCb}, {modalDialog, confirmDialog}) + this.dropdownLogic.deployContract(selectedContract, args, contractMetadata, compilerContracts, {continueCb, promptCb, statusCb, finalCb}, {modalDialog, confirmDialog}) } loadFromAddress () { diff --git a/src/app/tabs/runTab/model/dropdownlogic.js b/src/app/tabs/runTab/model/dropdownlogic.js index 1773de933c..c2dd5b8318 100644 --- a/src/app/tabs/runTab/model/dropdownlogic.js +++ b/src/app/tabs/runTab/model/dropdownlogic.js @@ -9,22 +9,17 @@ var EventManager = remixLib.EventManager var Web3 = require('web3') class DropdownLogic { - constructor (executionContext, fileManager, compilersArtefacts, config, editor, udapp, filePanel, runView) { + constructor (executionContext, compilersArtefacts, config, editor, udapp, runView) { this.compilersArtefacts = compilersArtefacts this.executionContext = executionContext this.config = config this.editor = editor this.udapp = udapp this.runView = runView - this.filePanel = filePanel this.event = new EventManager() this.listenToCompilationEvents() - - fileManager.events.on('currentFileChanged', (currentFile) => { - this.event.trigger('currentFileChanged', [currentFile]) - }) } // TODO: can be moved up; the event in contractDropdown will have to refactored a method instead @@ -124,10 +119,6 @@ class DropdownLogic { return this.executionContext.web3().eth.getGasPrice(cb) } - isVM () { - return this.executionContext.isVM() - } - // TODO: check if selectedContract and data can be joined createContract (selectedContract, data, continueCb, promptCb, modalDialog, confirmDialog, finalCb) { if (data) { @@ -224,20 +215,17 @@ class DropdownLogic { this.udapp.runTx(data, confirmationCb, continueCb, promptCb, finalCb) } - async deploContract (selectedContract, args, callbacks, dialogs) { + getCompilerContracts() { + return this.compilersArtefacts['__last'].getData().contracts + } + + async deploContract (selectedContract, args, contractMetadata, compilerContracts, callbacks, dialogs) { const {continueCb, promptCb, statusCb, finalCb} = callbacks const {modalDialog, confirmDialog} = dialogs var constructor = selectedContract.getConstructorInterface() - // TODO: deployMetadataOf can be moved here - let contractMetadata - try { - contractMetadata = await this.runView.call('compilerMetadata', 'deployMetadataOf', selectedContract.name) - } catch (error) { - return statusCb(`creation of ${selectedContract.name} errored: ` + error) - } if (!contractMetadata || (contractMetadata && contractMetadata.autoDeployLib)) { - return txFormat.buildData(selectedContract.name, selectedContract.object, this.compilersArtefacts['__last'].getData().contracts, true, constructor, args, (error, data) => { + return txFormat.buildData(selectedContract.name, selectedContract.object, compilerContracts, true, constructor, args, (error, data) => { if (error) return statusCb(`creation of ${selectedContract.name} errored: ` + error) statusCb(`creation of ${selectedContract.name} pending...`) diff --git a/src/app/udapp/run-tab.js b/src/app/udapp/run-tab.js index 781545e404..4566982ac6 100644 --- a/src/app/udapp/run-tab.js +++ b/src/app/udapp/run-tab.js @@ -131,8 +131,10 @@ export class RunTab extends LibraryPlugin { } renderDropdown (udappUI, fileManager, compilersArtefacts, config, editor, udapp, filePanel, logCallback) { - const dropdownLogic = new DropdownLogic(this.executionContext, fileManager, compilersArtefacts, config, editor, udapp, filePanel, this) - this.contractDropdownUI = new ContractDropdownUI(dropdownLogic, logCallback) + const dropdownLogic = new DropdownLogic(this.executionContext, compilersArtefacts, config, editor, udapp, this) + this.contractDropdownUI = new ContractDropdownUI(dropdownLogic, logCallback, this) + + fileManager.events.on('currentFileChanged', contractDropdownUI.changeCurrentFile.bind(contractDropdownUI)) this.contractDropdownUI.event.register('clearInstance', () => { const noInstancesText = this.noInstancesText