several compiler

pull/1/head
yann300 6 years ago
parent bd45d397e8
commit 5253c92c94
  1. 22
      src/app/compiler/compiler-abstract.js
  2. 55
      src/app/tabs/run-tab.js
  3. 31
      src/recorder.js
  4. 6
      src/universal-dapp-ui.js
  5. 2
      src/universal-dapp.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)
}
}

@ -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`<span>0</span>`
self._view.instanceContainer = yo`<div class="${css.instanceContainer}"></div>`
@ -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`<i title="Contract compilation failed. Please check the compile tab for more information." class="fa fa-times-circle ${css.errorIcon}" ></i>`
var info = yo`<i class="fa fa-info ${css.infoDeployAction}" aria-hidden="true" title="*.sol files allows deploying and accessing contracts. *.abi files only allows accessing contracts."></i>`
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`<select class="${css.contractNames}" disabled></select>`
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`<div>Contract creation initialization returns data with length of more than 24576 bytes. The deployment will likely fails. <br>
More info: <a href="https://github.com/ethereum/EIPs/blob/master/EIPS/eip-170.md" target="_blank">eip-170</a>
</div>`,
@ -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`<option value="${contract.name}">${contract.name}</option>`)
compiler.visitContracts((contract) => {
contractNames.appendChild(yo`<option compiler="${compilerFullName}">${contract.name}</option>`)
})
} else {
selectContractNames.setAttribute('disabled', true)

@ -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] = '<address>'
}
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] = '<address>'
}
}
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}}`

@ -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`<div class="instance ${css.instance} ${css.hidesub}" id="instance${address}"></div>`

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

Loading…
Cancel
Save