From e4d426913642d3877e7c4f9ee5f5deea45486e08 Mon Sep 17 00:00:00 2001 From: yann300 Date: Sat, 8 Sep 2018 22:05:18 +0200 Subject: [PATCH 01/10] support sending data to remix --- src/app/panels/righthand-panel.js | 4 +++- src/app/plugin/pluginAPI.js | 3 +++ src/app/plugin/pluginManager.js | 16 ++++++++++++++++ src/app/tabs/run-tab.js | 13 +++++++++++-- 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/app/panels/righthand-panel.js b/src/app/panels/righthand-panel.js index 969d5f5525..0be20ce6f8 100644 --- a/src/app/panels/righthand-panel.js +++ b/src/app/panels/righthand-panel.js @@ -52,7 +52,9 @@ module.exports = class RighthandPanel { self._deps.fileProviders, self._deps.fileManager, self._deps.udapp - ) + ) + + self._components.registry.put({api: pluginManager, name: 'pluginmanager'}) var analysisTab = new AnalysisTab(self._components.registry) analysisTab.event.register('newStaticAnaysisWarningMessage', (msg, settings) => { self._components.compile.addWarning(msg, settings) }) diff --git a/src/app/plugin/pluginAPI.js b/src/app/plugin/pluginAPI.js index 99a738e168..83cd36ff27 100644 --- a/src/app/plugin/pluginAPI.js +++ b/src/app/plugin/pluginAPI.js @@ -44,6 +44,9 @@ module.exports = (pluginManager, fileProviders, fileManager, compiler, udapp) => compiler: { getCompilationResult: (mod, cb) => { cb(null, compiler.lastCompilationResult) + }, + sendCompilactionResult: (mod, file, languageVersion, data, cb) => { + pluginManager.receivedDataFrom('sendCompilationResult', mod, file, languageVersion, data) } }, udapp: { diff --git a/src/app/plugin/pluginManager.js b/src/app/plugin/pluginManager.js index 6daec2ea64..808da385d8 100644 --- a/src/app/plugin/pluginManager.js +++ b/src/app/plugin/pluginManager.js @@ -1,4 +1,6 @@ 'use strict' +var remixLib = require('remix-lib') +var EventManager = remixLib.EventManager var executionContext = require('../../execution-context') const PluginAPI = require('./pluginAPI') /** @@ -80,6 +82,7 @@ const PluginAPI = require('./pluginAPI') module.exports = class PluginManager { constructor (app, compiler, txlistener, fileProviders, fileManager, udapp) { const self = this + self.event = new EventManager() var pluginAPI = new PluginAPI( this, fileProviders, @@ -90,6 +93,14 @@ module.exports = class PluginManager { self.plugins = {} self.origins = {} self.inFocus + fileManager.event.register('currentFileChanged', (file, provider) => { + self.broadcast(JSON.stringify({ + action: 'notification', + key: 'editor', + type: 'currentFileChanged', + value: [ file ] + })) + }) compiler.event.register('compilationFinished', (success, data, source) => { self.broadcast(JSON.stringify({ action: 'notification', @@ -184,6 +195,11 @@ module.exports = class PluginManager { this.post(this.origins[origin], value) } } + receivedDataFrom (methodName, mod) { + // TODO check whether 'mod' as right to do that + arguments.shift() + this.event.trigger(methodName, [arguments]) + } post (name, value) { const self = this if (self.plugins[name]) { diff --git a/src/app/tabs/run-tab.js b/src/app/tabs/run-tab.js index ed540c2ed4..afa6f87b2d 100644 --- a/src/app/tabs/run-tab.js +++ b/src/app/tabs/run-tab.js @@ -76,7 +76,8 @@ function runTab (opts, localRegistry) { fileManager: self._components.registry.get('filemanager').api, editor: self._components.registry.get('editor').api, logCallback: self._components.registry.get('logCallback').api, - filePanel: self._components.registry.get('filepanel').api + filePanel: self._components.registry.get('filepanel').api, + pluginManager: self._components.registry.get('pluginmanager').api } self._deps.udapp.resetAPI(self._components.transactionContextAPI) self._view.recorderCount = yo`0` @@ -293,7 +294,8 @@ function contractDropdown (events, self) { instanceContainer.appendChild(self._view.noInstancesText) var compFails = yo`` var info = yo`` - self._deps.compiler.event.register('compilationFinished', function (success, data, source) { + + var newlyCompiled = (success, data, source) => { getContractNames(success, data) if (success) { compFails.style.display = 'none' @@ -302,8 +304,15 @@ function contractDropdown (events, self) { compFails.style.display = 'block' document.querySelector(`.${css.contractNames}`).classList.add(css.contractNamesError) } + } + + self._deps.pluginManager.event.register('sendCompilationResult', (mod, file, source, languageVersion, data) => { + // TODO check whether the tab is configured + newlyCompiled(true, data, source) }) + self._deps.compiler.event.register('compilationFinished', newlyCompiled) + var deployAction = (value) => { self._view.createPanel.style.display = value self._view.orLabel.style.display = value From 52fa5c15a7a84317576f371178be01dbb7997757 Mon Sep 17 00:00:00 2001 From: yann300 Date: Fri, 14 Sep 2018 10:10:41 +0200 Subject: [PATCH 02/10] typo --- src/app/plugin/pluginAPI.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/plugin/pluginAPI.js b/src/app/plugin/pluginAPI.js index 83cd36ff27..591d08410f 100644 --- a/src/app/plugin/pluginAPI.js +++ b/src/app/plugin/pluginAPI.js @@ -45,7 +45,7 @@ module.exports = (pluginManager, fileProviders, fileManager, compiler, udapp) => getCompilationResult: (mod, cb) => { cb(null, compiler.lastCompilationResult) }, - sendCompilactionResult: (mod, file, languageVersion, data, cb) => { + sendCompilationResult: (mod, file, languageVersion, data, cb) => { pluginManager.receivedDataFrom('sendCompilationResult', mod, file, languageVersion, data) } }, From 1670587d5e442c1a6413ee78f5935bb13fbfe8c5 Mon Sep 17 00:00:00 2001 From: yann300 Date: Fri, 14 Sep 2018 11:34:33 +0200 Subject: [PATCH 03/10] support passing bytes to fallback --- src/multiParamManager.js | 3 +++ src/universal-dapp.js | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/multiParamManager.js b/src/multiParamManager.js index 6600b78381..6278a54ae1 100644 --- a/src/multiParamManager.js +++ b/src/multiParamManager.js @@ -183,6 +183,9 @@ class MultiParamManager { if (this.funABI.inputs && this.funABI.inputs.length > 0) { contractProperty.classList.add(css.hasArgs) + } else if (this.funABI.type === 'fallback') { + contractProperty.classList.add(css.hasArgs) + this.contractActionsContainerSingle.querySelector('i').style.visibility = 'hidden' } else { this.contractActionsContainerSingle.querySelector('i').style.visibility = 'hidden' this.basicInputField.style.display = 'none' diff --git a/src/universal-dapp.js b/src/universal-dapp.js index 2982ede212..2bac935b35 100644 --- a/src/universal-dapp.js +++ b/src/universal-dapp.js @@ -205,7 +205,7 @@ UniversalDApp.prototype.call = function (isUserAction, args, value, lookupOnly, } } // contractsDetails is used to resolve libraries - txFormat.buildData(args.contractName, args.contractAbi, self.data.contractsDetails, false, args.funABI, value, (error, data) => { + txFormat.buildData(args.contractName, args.contractAbi, self.data.contractsDetails, false, args.funABI, args.funABI.type !== 'fallback' ? value : '', (error, data) => { if (!error) { if (isUserAction) { if (!args.funABI.constant) { @@ -214,6 +214,7 @@ UniversalDApp.prototype.call = function (isUserAction, args, value, lookupOnly, self._deps.logCallback(`${logMsg}`) } } + if (args.funABI.type === 'fallback') data.dataHex = value self.callFunction(args.address, data, args.funABI, (error, txResult) => { if (!error) { var isVM = executionContext.isVM() From b7dc9debdb8661c682feefe97056021431c36f56 Mon Sep 17 00:00:00 2001 From: jesush Date: Fri, 21 Sep 2018 03:41:58 -0400 Subject: [PATCH 04/10] Fix sendCompilationResults API call --- src/app/plugin/pluginAPI.js | 4 ++-- src/app/plugin/pluginManager.js | 6 +++--- src/app/tabs/run-tab.js | 5 +++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/app/plugin/pluginAPI.js b/src/app/plugin/pluginAPI.js index 591d08410f..e83b6c618b 100644 --- a/src/app/plugin/pluginAPI.js +++ b/src/app/plugin/pluginAPI.js @@ -45,8 +45,8 @@ module.exports = (pluginManager, fileProviders, fileManager, compiler, udapp) => getCompilationResult: (mod, cb) => { cb(null, compiler.lastCompilationResult) }, - sendCompilationResult: (mod, file, languageVersion, data, cb) => { - pluginManager.receivedDataFrom('sendCompilationResult', mod, file, languageVersion, data) + sendCompilationResult: (mod, file, source, languageVersion, data, cb) => { + pluginManager.receivedDataFrom('sendCompilationResult', mod, [file, source, languageVersion, data]) } }, udapp: { diff --git a/src/app/plugin/pluginManager.js b/src/app/plugin/pluginManager.js index 808da385d8..b6f55e50ca 100644 --- a/src/app/plugin/pluginManager.js +++ b/src/app/plugin/pluginManager.js @@ -195,10 +195,10 @@ module.exports = class PluginManager { this.post(this.origins[origin], value) } } - receivedDataFrom (methodName, mod) { + receivedDataFrom (methodName, mod, argumentsArray) { // TODO check whether 'mod' as right to do that - arguments.shift() - this.event.trigger(methodName, [arguments]) + console.log(argumentsArray) + this.event.trigger(methodName, argumentsArray) } post (name, value) { const self = this diff --git a/src/app/tabs/run-tab.js b/src/app/tabs/run-tab.js index afa6f87b2d..ff56e2dfd4 100644 --- a/src/app/tabs/run-tab.js +++ b/src/app/tabs/run-tab.js @@ -306,9 +306,10 @@ function contractDropdown (events, self) { } } - self._deps.pluginManager.event.register('sendCompilationResult', (mod, file, source, languageVersion, data) => { + self._deps.pluginManager.event.register('sendCompilationResult', (file, source, languageVersion, data) => { // TODO check whether the tab is configured - newlyCompiled(true, data, source) + self._deps.compiler.ldCompilationResult(file, source, languageVersion, data) + newlyCompiled(true) }) self._deps.compiler.event.register('compilationFinished', newlyCompiled) From b6ca45c0b5202906278a1f2df3ec0967dd0cfcb9 Mon Sep 17 00:00:00 2001 From: yann300 Date: Tue, 25 Sep 2018 11:09:19 +0200 Subject: [PATCH 05/10] several compiler --- src/app/compiler/compiler-abstract.js | 22 +++++++++++ src/app/tabs/run-tab.js | 55 ++++++++++++++++----------- src/recorder.js | 31 +++++++-------- src/universal-dapp-ui.js | 6 +-- src/universal-dapp.js | 2 +- 5 files changed, 73 insertions(+), 43 deletions(-) create mode 100644 src/app/compiler/compiler-abstract.js diff --git a/src/app/compiler/compiler-abstract.js b/src/app/compiler/compiler-abstract.js new file mode 100644 index 0000000000..1ae9ee6aed --- /dev/null +++ b/src/app/compiler/compiler-abstract.js @@ -0,0 +1,22 @@ +'use strict' +var remixLib = require('remix-lib') +var txHelper = remixLib.execution.txHelper + +module.exports = class CompilerAbstract { + constructor (languageversion, data) { + this.languageversion = languageversion + this.data = data + } + + getContracts () { + return this.data.contracts + } + + getContract (name) { + return txHelper.getContract(name, this.data.contracts) + } + + visitContracts (calllback) { + return txHelper.visitContracts(this.data.contracts, calllback) + } +} diff --git a/src/app/tabs/run-tab.js b/src/app/tabs/run-tab.js index ff56e2dfd4..50502c12e8 100644 --- a/src/app/tabs/run-tab.js +++ b/src/app/tabs/run-tab.js @@ -21,6 +21,7 @@ var addTooltip = require('../ui/tooltip') var css = require('./styles/run-tab-styles') var MultiParamManager = require('../../multiParamManager') var modalDialog = require('../ui/modaldialog') +var CompilerAbstract = require('../compiler/compiler-abstract') function runTab (opts, localRegistry) { /* ------------------------- @@ -38,6 +39,7 @@ function runTab (opts, localRegistry) { } self._components = {} self._components.registry = localRegistry || globlalRegistry + self._components.compilersArtefacts = {} self._components.transactionContextAPI = { getAddress: (cb) => { cb(null, $('#txorigin').val()) @@ -79,6 +81,7 @@ function runTab (opts, localRegistry) { filePanel: self._components.registry.get('filepanel').api, pluginManager: self._components.registry.get('pluginmanager').api } + self._components.compilersArtefacts['solidity'] = self._deps.compiler self._deps.udapp.resetAPI(self._components.transactionContextAPI) self._view.recorderCount = yo`0` self._view.instanceContainer = yo`
` @@ -194,7 +197,7 @@ function updateAccountBalances (container, self) { RECORDER ------------------------------------------------ */ function makeRecorder (registry, runTabEvent, self) { - var recorder = new Recorder(self._deps.compiler, self._deps.udapp, self._deps.logCallback) + var recorder = new Recorder(self._deps.udapp, self._deps.logCallback) recorder.event.register('newTxRecorded', (count) => { self.data.count = count @@ -295,8 +298,8 @@ function contractDropdown (events, self) { var compFails = yo`` var info = yo`` - var newlyCompiled = (success, data, source) => { - getContractNames(success, data) + var newlyCompiled = (success, data, source, compiler, compilerFullName) => { + getContractNames(success, data, compiler, compilerFullName) if (success) { compFails.style.display = 'none' document.querySelector(`.${css.contractNames}`).classList.remove(css.contractNamesError) @@ -308,11 +311,12 @@ function contractDropdown (events, self) { self._deps.pluginManager.event.register('sendCompilationResult', (file, source, languageVersion, data) => { // TODO check whether the tab is configured - self._deps.compiler.ldCompilationResult(file, source, languageVersion, data) - newlyCompiled(true) + let compiler = new CompilerAbstract(languageVersion, data) + self._components.compilersArtefacts[languageVersion] = compiler + newlyCompiled(true, data, source, compiler, languageVersion) }) - self._deps.compiler.event.register('compilationFinished', newlyCompiled) + self._deps.compiler.event.register('compilationFinished', (success, data, source) => { newlyCompiled(success, data, source, self._deps.compiler, 'solidity') }) var deployAction = (value) => { self._view.createPanel.style.display = value @@ -337,11 +341,16 @@ function contractDropdown (events, self) { var selectContractNames = yo`` function getSelectedContract () { - var contractName = selectContractNames.children[selectContractNames.selectedIndex].innerHTML + var contract = selectContractNames.children[selectContractNames.selectedIndex] + var contractName = contract.innerHTML + var compiler = self._components.compilersArtefacts[contract.getAttribute('compiler')] + if (!compiler) return null + if (contractName) { return { name: contractName, - contract: self._deps.compiler.getContract(contractName) + contract: compiler.getContract(contractName), + compiler } } return null @@ -367,11 +376,12 @@ function contractDropdown (events, self) { function setInputParamsPlaceHolder () { self._view.createPanel.innerHTML = '' - if (self._deps.compiler.getContract && selectContractNames.selectedIndex >= 0 && selectContractNames.children.length > 0) { - var ctrabi = txHelper.getConstructorInterface(getSelectedContract().contract.object.abi) - var ctrEVMbc = getSelectedContract().contract.object.evm.bytecode.object + if (selectContractNames.selectedIndex >= 0 && selectContractNames.children.length > 0) { + var selectedContract = getSelectedContract() + var ctrabi = txHelper.getConstructorInterface(selectedContract.contract.object.abi) + var ctrEVMbc = selectedContract.contract.object.evm.bytecode.object var createConstructorInstance = new MultiParamManager(0, ctrabi, (valArray, inputsValues) => { - createInstance(inputsValues) + createInstance(inputsValues, selectedContract.compiler) }, txHelper.inputParametersDeclarationToString(ctrabi.inputs), 'Deploy', ctrEVMbc) self._view.createPanel.appendChild(createConstructorInstance.render()) return @@ -410,7 +420,7 @@ function contractDropdown (events, self) { } // DEPLOY INSTANCE - function createInstance (args) { + function createInstance (args, compiler) { var selectedContract = getSelectedContract() if (selectedContract.contract.object.evm.bytecode.object.length === 0) { @@ -423,7 +433,9 @@ function contractDropdown (events, self) { self._deps.filePanel.compilerMetadata().metadataOf(selectedContract.name, (error, contractMetadata) => { if (error) return self._deps.logCallback(`creation of ${selectedContract.name} errored: ` + error) if (!contractMetadata || (contractMetadata && contractMetadata.autoDeployLib)) { - txFormat.buildData(selectedContract.name, selectedContract.contract.object, self._deps.compiler.getContracts(), true, constructor, args, (error, data) => { + txFormat.buildData(selectedContract.name, selectedContract.contract.object, compiler.getContracts(), true, constructor, args, (error, data) => { + data.contractName = selectedContract.name + data.linkReferences = selectedContract.contract.object.evm.bytecode.linkReferences createInstanceCallback(error, selectedContract, data) }, (msg) => { self._deps.logCallback(msg) @@ -441,7 +453,7 @@ function contractDropdown (events, self) { }) } - if (selectedContract.contract.object.evm.deployedBytecode.object.length / 2 > 24576) { + if (selectedContract.contract.object.evm.deployedBytecode && selectedContract.contract.object.evm.deployedBytecode.object.length / 2 > 24576) { 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
`, @@ -464,7 +476,7 @@ function contractDropdown (events, self) { function loadFromAddress () { var noInstancesText = self._view.noInstancesText if (noInstancesText.parentNode) { noInstancesText.parentNode.removeChild(noInstancesText) } - var contractNames = document.querySelector(`.${css.contractNames.classNames[0]}`) + var selectedContract = getSelectedContract() var address = atAddressButtonInput.value if (!ethJSUtil.isValidAddress(address)) { return modalDialogCustom.alert('Invalid address.') @@ -480,22 +492,21 @@ function contractDropdown (events, self) { } catch (e) { return modalDialogCustom.alert('Failed to parse the current file as JSON ABI.') } - instanceContainer.appendChild(self._deps.udappUI.renderInstanceFromABI(abi, address, address)) + instanceContainer.appendChild(self._deps.udappUI.renderInstanceFromABI(abi, address, address, selectedContract.compiler)) }) } else { - var contract = self._deps.compiler.getContract(contractNames.children[contractNames.selectedIndex].innerHTML) - instanceContainer.appendChild(self._deps.udappUI.renderInstance(contract.object, address, selectContractNames.value)) + instanceContainer.appendChild(self._deps.udappUI.renderInstance(selectedContract.contract.object, address, selectContractNames.value, selectedContract.compiler)) } } // GET NAMES OF ALL THE CONTRACTS - function getContractNames (success, data) { + function getContractNames (success, data, compiler, compilerFullName) { var contractNames = document.querySelector(`.${css.contractNames.classNames[0]}`) contractNames.innerHTML = '' if (success) { selectContractNames.removeAttribute('disabled') - self._deps.compiler.visitContracts((contract) => { - contractNames.appendChild(yo``) + compiler.visitContracts((contract) => { + contractNames.appendChild(yo``) }) } else { selectContractNames.setAttribute('disabled', true) diff --git a/src/recorder.js b/src/recorder.js index 1f14c472ca..030ae9cbb7 100644 --- a/src/recorder.js +++ b/src/recorder.js @@ -13,7 +13,7 @@ var modal = require('./app/ui/modal-dialog-custom') * */ class Recorder { - constructor (compiler, udapp, logCallBack) { + constructor (udapp, logCallBack) { var self = this self.logCallBack = logCallBack self.event = new EventManager() @@ -27,25 +27,22 @@ class Recorder { if (this.data._listen) { var record = { value, parameters: payLoad.funArgs } if (!to) { - var selectedContract = compiler.getContract(payLoad.contractName) - if (selectedContract) { - var abi = selectedContract.object.abi - var sha3 = ethutil.bufferToHex(ethutil.sha3(abi)) - record.abi = sha3 - record.contractName = payLoad.contractName - record.bytecode = payLoad.contractBytecode - record.linkReferences = selectedContract.object.evm.bytecode.linkReferences - if (record.linkReferences && Object.keys(record.linkReferences).length) { - for (var file in record.linkReferences) { - for (var lib in record.linkReferences[file]) { - self.data._linkReferences[lib] = '
' - } + var abi = payLoad.contractABI + var sha3 = ethutil.bufferToHex(ethutil.sha3(abi)) + record.abi = sha3 + record.contractName = payLoad.contractName + record.bytecode = payLoad.contractBytecode + record.linkReferences = payLoad.linkReferences + if (record.linkReferences && Object.keys(record.linkReferences).length) { + for (var file in record.linkReferences) { + for (var lib in record.linkReferences[file]) { + self.data._linkReferences[lib] = '
' } } - self.data._abis[sha3] = abi - - this.data._contractABIReferences[timestamp] = sha3 } + self.data._abis[sha3] = abi + + this.data._contractABIReferences[timestamp] = sha3 } else { var creationTimestamp = this.data._createdContracts[to] record.to = `created{${creationTimestamp}}` diff --git a/src/universal-dapp-ui.js b/src/universal-dapp-ui.js index a900ff2cd9..3d640decc5 100644 --- a/src/universal-dapp-ui.js +++ b/src/universal-dapp-ui.js @@ -12,20 +12,20 @@ function UniversalDAppUI (udapp, opts = {}) { this.udapp = udapp } -UniversalDAppUI.prototype.renderInstance = function (contract, address, contractName) { +UniversalDAppUI.prototype.renderInstance = function (contract, address, contractName, compiler) { var noInstances = document.querySelector('[class^="noInstancesText"]') if (noInstances) { noInstances.parentNode.removeChild(noInstances) } var abi = this.udapp.getABI(contract) - return this.renderInstanceFromABI(abi, address, contractName) + return this.renderInstanceFromABI(abi, address, contractName, compiler) } // TODO this function was named before "appendChild". // this will render an instance: contract name, contract address, and all the public functions // basically this has to be called for the "atAddress" (line 393) and when a contract creation succeed // this returns a DOM element -UniversalDAppUI.prototype.renderInstanceFromABI = function (contractABI, address, contractName) { +UniversalDAppUI.prototype.renderInstanceFromABI = function (contractABI, address, contractName, compiler) { var self = this address = (address.slice(0, 2) === '0x' ? '' : '0x') + address.toString('hex') var instance = yo`
` diff --git a/src/universal-dapp.js b/src/universal-dapp.js index 2bac935b35..fdbfc0eda5 100644 --- a/src/universal-dapp.js +++ b/src/universal-dapp.js @@ -350,7 +350,7 @@ UniversalDApp.prototype.runTx = function (args, cb) { }, function runTransaction (fromAddress, value, gasLimit, next) { var tx = { to: args.to, data: args.data.dataHex, useCall: args.useCall, from: fromAddress, value: value, gasLimit: gasLimit } - var payLoad = { funAbi: args.data.funAbi, funArgs: args.data.funArgs, contractBytecode: args.data.contractBytecode, contractName: args.data.contractName } + var payLoad = { funAbi: args.data.funAbi, funArgs: args.data.funArgs, contractBytecode: args.data.contractBytecode, contractName: args.data.contractName, contractABI: args.data.contractABI, linkReferences: args.data.linkReferences } var timestamp = Date.now() self.event.trigger('initiatingTransaction', [timestamp, tx, payLoad]) From 92d613d373b11f5576d5655c8a1d2c81d4d92dee Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 1 Oct 2018 14:41:39 +0200 Subject: [PATCH 06/10] remove use of compiler in universal-dapp --- src/app/tabs/run-tab.js | 6 +++--- src/universal-dapp-ui.js | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/app/tabs/run-tab.js b/src/app/tabs/run-tab.js index 50502c12e8..643d27e324 100644 --- a/src/app/tabs/run-tab.js +++ b/src/app/tabs/run-tab.js @@ -476,7 +476,6 @@ function contractDropdown (events, self) { function loadFromAddress () { var noInstancesText = self._view.noInstancesText if (noInstancesText.parentNode) { noInstancesText.parentNode.removeChild(noInstancesText) } - var selectedContract = getSelectedContract() var address = atAddressButtonInput.value if (!ethJSUtil.isValidAddress(address)) { return modalDialogCustom.alert('Invalid address.') @@ -492,10 +491,11 @@ function contractDropdown (events, self) { } catch (e) { return modalDialogCustom.alert('Failed to parse the current file as JSON ABI.') } - instanceContainer.appendChild(self._deps.udappUI.renderInstanceFromABI(abi, address, address, selectedContract.compiler)) + instanceContainer.appendChild(self._deps.udappUI.renderInstanceFromABI(abi, address, address)) }) } else { - instanceContainer.appendChild(self._deps.udappUI.renderInstance(selectedContract.contract.object, address, selectContractNames.value, selectedContract.compiler)) + var selectedContract = getSelectedContract() + instanceContainer.appendChild(self._deps.udappUI.renderInstance(selectedContract.contract.object, address, selectContractNames.value)) } } diff --git a/src/universal-dapp-ui.js b/src/universal-dapp-ui.js index 3d640decc5..a900ff2cd9 100644 --- a/src/universal-dapp-ui.js +++ b/src/universal-dapp-ui.js @@ -12,20 +12,20 @@ function UniversalDAppUI (udapp, opts = {}) { this.udapp = udapp } -UniversalDAppUI.prototype.renderInstance = function (contract, address, contractName, compiler) { +UniversalDAppUI.prototype.renderInstance = function (contract, address, contractName) { var noInstances = document.querySelector('[class^="noInstancesText"]') if (noInstances) { noInstances.parentNode.removeChild(noInstances) } var abi = this.udapp.getABI(contract) - return this.renderInstanceFromABI(abi, address, contractName, compiler) + return this.renderInstanceFromABI(abi, address, contractName) } // TODO this function was named before "appendChild". // this will render an instance: contract name, contract address, and all the public functions // basically this has to be called for the "atAddress" (line 393) and when a contract creation succeed // this returns a DOM element -UniversalDAppUI.prototype.renderInstanceFromABI = function (contractABI, address, contractName, compiler) { +UniversalDAppUI.prototype.renderInstanceFromABI = function (contractABI, address, contractName) { var self = this address = (address.slice(0, 2) === '0x' ? '' : '0x') + address.toString('hex') var instance = yo`
` From f617762b8649a422f907646ba4dc5a25df27aba5 Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 1 Oct 2018 15:24:26 +0200 Subject: [PATCH 07/10] provide remix ide URL --- ci/browser_tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/browser_tests.sh b/ci/browser_tests.sh index abae1828e9..aa7c886022 100755 --- a/ci/browser_tests.sh +++ b/ci/browser_tests.sh @@ -7,7 +7,7 @@ setupRemixd () { cd contracts echo 'sharing folder: ' echo $PWD - ./../node_modules/remixd/bin/remixd -s $PWD & + ./../node_modules/remixd/bin/remixd -s $PWD --remix-ide http://127.0.0.1:8080 & cd .. } From f35cd1f09c4394b5884e1b48a8d9bc95f8080bc1 Mon Sep 17 00:00:00 2001 From: yann300 Date: Tue, 9 Oct 2018 14:19:10 +0200 Subject: [PATCH 08/10] fix error feedback --- src/app/tabs/run-tab.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/app/tabs/run-tab.js b/src/app/tabs/run-tab.js index 643d27e324..f979bf2d51 100644 --- a/src/app/tabs/run-tab.js +++ b/src/app/tabs/run-tab.js @@ -392,9 +392,12 @@ function contractDropdown (events, self) { selectContractNames.addEventListener('change', setInputParamsPlaceHolder) - function createInstanceCallback (error, selectedContract, data) { - if (error) return self._deps.logCallback(`creation of ${selectedContract.name} errored: ` + error) + function createInstanceCallback (selectedContract, data) { self._deps.logCallback(`creation of ${selectedContract.name} pending...`) + if (data) { + data.contractName = selectedContract.name + data.linkReferences = selectedContract.contract.object.evm.bytecode.linkReferences + } self._deps.udapp.createContract(data, (error, txResult) => { if (!error) { var isVM = executionContext.isVM() @@ -434,9 +437,8 @@ function contractDropdown (events, self) { if (error) return self._deps.logCallback(`creation of ${selectedContract.name} errored: ` + error) if (!contractMetadata || (contractMetadata && contractMetadata.autoDeployLib)) { txFormat.buildData(selectedContract.name, selectedContract.contract.object, compiler.getContracts(), true, constructor, args, (error, data) => { - data.contractName = selectedContract.name - data.linkReferences = selectedContract.contract.object.evm.bytecode.linkReferences - createInstanceCallback(error, selectedContract, data) + if (error) return self._deps.logCallback(`creation of ${selectedContract.name} errored: ` + error) + createInstanceCallback(selectedContract, data) }, (msg) => { self._deps.logCallback(msg) }, (data, runTxCallback) => { @@ -446,8 +448,8 @@ function contractDropdown (events, self) { } else { if (Object.keys(selectedContract.contract.object.evm.bytecode.linkReferences).length) self._deps.logCallback(`linking ${JSON.stringify(selectedContract.contract.object.evm.bytecode.linkReferences, null, '\t')} using ${JSON.stringify(contractMetadata.linkReferences, null, '\t')}`) txFormat.encodeConstructorCallAndLinkLibraries(selectedContract.contract.object, args, constructor, contractMetadata.linkReferences, selectedContract.contract.object.evm.bytecode.linkReferences, (error, data) => { - if (data) data.contractName = selectedContract.name - createInstanceCallback(error, selectedContract, data) + if (error) return self._deps.logCallback(`creation of ${selectedContract.name} errored: ` + error) + createInstanceCallback(selectedContract, data) }) } }) From f28fcc623df09cc0b0cf8838aaff54e50f069523 Mon Sep 17 00:00:00 2001 From: yann300 Date: Tue, 9 Oct 2018 21:35:26 +0200 Subject: [PATCH 09/10] move compilersArtefacts to app.js --- src/app.js | 7 ++++--- src/app/compiler/compiler-abstract.js | 4 ++++ src/app/debugger/debugger.js | 8 +++----- src/app/tabs/run-tab.js | 18 ++++++++++++------ 4 files changed, 23 insertions(+), 14 deletions(-) diff --git a/src/app.js b/src/app.js index b3a8b1926f..0cb07b0aa3 100644 --- a/src/app.js +++ b/src/app.js @@ -396,6 +396,9 @@ Please make a backup of your contracts and start using http://remix.ethereum.org var offsetToLineColumnConverter = new OffsetToLineColumnConverter(self._components.compiler.event) registry.put({api: offsetToLineColumnConverter, name: 'offsettolinecolumnconverter'}) + self._components.compilersArtefacts = {} // store all the possible compilation data (key represent a compiler name) + registry.put({api: self._components.compilersArtefacts, name: 'compilersartefacts'}) + // ----------------- UniversalDApp ----------------- var udapp = new UniversalDApp({ removable: false, @@ -412,9 +415,7 @@ Please make a backup of your contracts and start using http://remix.ethereum.org var txlistener = new Txlistener({ api: { contracts: function () { - if (self._components.compiler.lastCompilationResult && self._components.compiler.lastCompilationResult.data) { - return self._components.compiler.lastCompilationResult.data.contracts - } + if (self._components.compilersArtefacts['__last']) return self._components.compilersArtefacts['__last'].getContracts() return null }, resolveReceipt: function (tx, cb) { diff --git a/src/app/compiler/compiler-abstract.js b/src/app/compiler/compiler-abstract.js index 1ae9ee6aed..9cd28c4a59 100644 --- a/src/app/compiler/compiler-abstract.js +++ b/src/app/compiler/compiler-abstract.js @@ -19,4 +19,8 @@ module.exports = class CompilerAbstract { visitContracts (calllback) { return txHelper.visitContracts(this.data.contracts, calllback) } + + getData () { + return this.data + } } diff --git a/src/app/debugger/debugger.js b/src/app/debugger/debugger.js index 2cf969d405..9d547a5319 100644 --- a/src/app/debugger/debugger.js +++ b/src/app/debugger/debugger.js @@ -17,16 +17,14 @@ function Debugger (container, sourceHighlighter, localRegistry) { this._deps = { offsetToLineColumnConverter: this._components.registry.get('offsettolinecolumnconverter').api, editor: this._components.registry.get('editor').api, - compiler: this._components.registry.get('compiler').api + compiler: this._components.registry.get('compiler').api, + compilersArtefacts: this._components.registry.get('compilersartefacts').api } this.debugger = new Ethdebugger( { executionContext: executionContext, compilationResult: () => { - var compilationResult = this._deps.compiler.lastCompilationResult - if (compilationResult) { - return compilationResult.data - } + if (this._deps.compilersArtefacts['__last']) return this._deps.compilersArtefacts['__last'].getData() return null } }) diff --git a/src/app/tabs/run-tab.js b/src/app/tabs/run-tab.js index f979bf2d51..3effe04f37 100644 --- a/src/app/tabs/run-tab.js +++ b/src/app/tabs/run-tab.js @@ -39,7 +39,6 @@ function runTab (opts, localRegistry) { } self._components = {} self._components.registry = localRegistry || globlalRegistry - self._components.compilersArtefacts = {} self._components.transactionContextAPI = { getAddress: (cb) => { cb(null, $('#txorigin').val()) @@ -79,9 +78,9 @@ function runTab (opts, localRegistry) { editor: self._components.registry.get('editor').api, logCallback: self._components.registry.get('logCallback').api, filePanel: self._components.registry.get('filepanel').api, - pluginManager: self._components.registry.get('pluginmanager').api + pluginManager: self._components.registry.get('pluginmanager').api, + compilersArtefacts: self._components.registry.get('compilersartefacts').api } - self._components.compilersArtefacts['solidity'] = self._deps.compiler self._deps.udapp.resetAPI(self._components.transactionContextAPI) self._view.recorderCount = yo`0` self._view.instanceContainer = yo`
` @@ -312,11 +311,18 @@ function contractDropdown (events, self) { self._deps.pluginManager.event.register('sendCompilationResult', (file, source, languageVersion, data) => { // TODO check whether the tab is configured let compiler = new CompilerAbstract(languageVersion, data) - self._components.compilersArtefacts[languageVersion] = compiler + self._deps.compilersArtefacts[languageVersion] = compiler + self._deps.compilersArtefacts['__last'] = compiler newlyCompiled(true, data, source, compiler, languageVersion) }) - self._deps.compiler.event.register('compilationFinished', (success, data, source) => { newlyCompiled(success, data, source, self._deps.compiler, 'solidity') }) + self._deps.compiler.event.register('compilationFinished', (success, data, source) => { + var name = 'solidity' + let compiler = new CompilerAbstract(name, data) + self._deps.compilersArtefacts[name] = compiler + self._deps.compilersArtefacts['__last'] = compiler + newlyCompiled(success, data, source, self._deps.compiler, name) + }) var deployAction = (value) => { self._view.createPanel.style.display = value @@ -343,7 +349,7 @@ function contractDropdown (events, self) { function getSelectedContract () { var contract = selectContractNames.children[selectContractNames.selectedIndex] var contractName = contract.innerHTML - var compiler = self._components.compilersArtefacts[contract.getAttribute('compiler')] + var compiler = self._deps.compilersArtefacts[contract.getAttribute('compiler')] if (!compiler) return null if (contractName) { From 7aa8d4f076a543d7fbd0304adbfe527894ccd6e5 Mon Sep 17 00:00:00 2001 From: yann300 Date: Wed, 10 Oct 2018 15:27:05 +0200 Subject: [PATCH 10/10] standard --- src/app/tabs/run-tab.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/tabs/run-tab.js b/src/app/tabs/run-tab.js index 3effe04f37..d722ecfbc7 100644 --- a/src/app/tabs/run-tab.js +++ b/src/app/tabs/run-tab.js @@ -321,7 +321,7 @@ function contractDropdown (events, self) { let compiler = new CompilerAbstract(name, data) self._deps.compilersArtefacts[name] = compiler self._deps.compilersArtefacts['__last'] = compiler - newlyCompiled(success, data, source, self._deps.compiler, name) + newlyCompiled(success, data, source, self._deps.compiler, name) }) var deployAction = (value) => {