remove excessive coupling with structure of contract object

pull/3094/head
Iuri Matias 6 years ago committed by yann300
parent 539b0f930e
commit 4a9f5dc7b5
  1. 37
      src/app/tabs/runTab/contractDropdown.js
  2. 20
      src/app/tabs/runTab/model/dropdownlogic.js

@ -100,8 +100,8 @@ class ContractDropdownUI {
} }
var selectedContract = this.getSelectedContract() var selectedContract = this.getSelectedContract()
var ctrabi = txHelper.getConstructorInterface(selectedContract.contract.object.abi) var ctrabi = txHelper.getConstructorInterface(selectedContract.abi)
var ctrEVMbc = selectedContract.contract.object.evm.bytecode.object var ctrEVMbc = selectedContract.bytecodeObject
var createConstructorInstance = new MultiParamManager(0, ctrabi, (valArray, inputsValues) => { var createConstructorInstance = new MultiParamManager(0, ctrabi, (valArray, inputsValues) => {
this.createInstance(inputsValues, selectedContract.compiler) this.createInstance(inputsValues, selectedContract.compiler)
}, txHelper.inputParametersDeclarationToString(ctrabi.inputs), 'Deploy', ctrEVMbc) }, txHelper.inputParametersDeclarationToString(ctrabi.inputs), 'Deploy', ctrEVMbc)
@ -111,23 +111,17 @@ class ContractDropdownUI {
getSelectedContract () { getSelectedContract () {
var contract = this.selectContractNames.children[this.selectContractNames.selectedIndex] var contract = this.selectContractNames.children[this.selectContractNames.selectedIndex]
var contractName = contract.innerHTML var contractName = contract.innerHTML
var compiler = this.dropdownLogic.getContractCompiler(contract.getAttribute('compiler')) var compilerAtributeName = contract.getAttribute('compiler')
if (!compiler) return null
if (!contractName) return null return this.dropdownLogic.getSelectedContract(contractName, compilerAtributeName)
return {
name: contractName,
contract: compiler.getContract(contractName),
compiler
}
} }
createInstanceCallback (selectedContract, data) { createInstanceCallback (selectedContract, data) {
this.parentSelf._deps.logCallback(`creation of ${selectedContract.name} pending...`) this.parentSelf._deps.logCallback(`creation of ${selectedContract.name} pending...`)
if (data) { if (data) {
data.contractName = selectedContract.name data.contractName = selectedContract.name
data.linkReferences = selectedContract.contract.object.evm.bytecode.linkReferences data.linkReferences = selectedContract.bytecodeLinkReferences
data.contractABI = selectedContract.contract.object.abi data.contractABI = selectedContract.abi
} }
this.parentSelf._deps.udapp.createContract(data, this.parentSelf._deps.udapp.createContract(data,
@ -226,7 +220,7 @@ class ContractDropdownUI {
} }
this.event.trigger('clearInstance') this.event.trigger('clearInstance')
var address = isVM ? txResult.result.createdAddress : txResult.result.contractAddress var address = isVM ? txResult.result.createdAddress : txResult.result.contractAddress
this.event.trigger('newContractInstanceAdded', [selectedContract.contract.object, address, this.selectContractNames.value]) this.event.trigger('newContractInstanceAdded', [selectedContract, address, this.selectContractNames.value])
} }
) )
} }
@ -235,17 +229,16 @@ class ContractDropdownUI {
createInstance (args, compiler) { createInstance (args, compiler) {
var selectedContract = this.getSelectedContract() var selectedContract = this.getSelectedContract()
if (selectedContract.contract.object.evm.bytecode.object.length === 0) { if (selectedContract.bytecodeObject.length === 0) {
modalDialogCustom.alert('This contract may be abstract, not implement an abstract parent\'s methods completely or not invoke an inherited contract\'s constructor correctly.') return modalDialogCustom.alert('This contract may be abstract, not implement an abstract parent\'s methods completely or not invoke an inherited contract\'s constructor correctly.')
return
} }
var forceSend = () => { var forceSend = () => {
var constructor = txHelper.getConstructorInterface(selectedContract.contract.object.abi) var constructor = txHelper.getConstructorInterface(selectedContract.abi)
this.parentSelf._deps.filePanel.compilerMetadata().deployMetadataOf(selectedContract.name, (error, contractMetadata) => { this.parentSelf._deps.filePanel.compilerMetadata().deployMetadataOf(selectedContract.name, (error, contractMetadata) => {
if (error) return this.parentSelf._deps.logCallback(`creation of ${selectedContract.name} errored: ` + error) if (error) return this.parentSelf._deps.logCallback(`creation of ${selectedContract.name} errored: ` + error)
if (!contractMetadata || (contractMetadata && contractMetadata.autoDeployLib)) { if (!contractMetadata || (contractMetadata && contractMetadata.autoDeployLib)) {
txFormat.buildData(selectedContract.name, selectedContract.contract.object, compiler.getContracts(), true, constructor, args, (error, data) => { txFormat.buildData(selectedContract.name, selectedContract.object, compiler.getContracts(), true, constructor, args, (error, data) => {
if (error) return this.parentSelf._deps.logCallback(`creation of ${selectedContract.name} errored: ` + error) if (error) return this.parentSelf._deps.logCallback(`creation of ${selectedContract.name} errored: ` + error)
this.createInstanceCallback(selectedContract, data) this.createInstanceCallback(selectedContract, data)
}, (msg) => { }, (msg) => {
@ -312,8 +305,8 @@ class ContractDropdownUI {
runTxCallback) runTxCallback)
}) })
} else { } else {
if (Object.keys(selectedContract.contract.object.evm.bytecode.linkReferences).length) this.parentSelf._deps.logCallback(`linking ${JSON.stringify(selectedContract.contract.object.evm.bytecode.linkReferences, null, '\t')} using ${JSON.stringify(contractMetadata.linkReferences, null, '\t')}`) if (Object.keys(selectedContract.bytecodeLinkReferences).length) this.parentSelf._deps.logCallback(`linking ${JSON.stringify(selectedContract.bytecodeLinkReferences, 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) => { txFormat.encodeConstructorCallAndLinkLibraries(selectedContract.object, args, constructor, contractMetadata.linkReferences, selectedContract.bytecodeLinkReferences, (error, data) => {
if (error) return this.parentSelf._deps.logCallback(`creation of ${selectedContract.name} errored: ` + error) if (error) return this.parentSelf._deps.logCallback(`creation of ${selectedContract.name} errored: ` + error)
this.createInstanceCallback(selectedContract, data) this.createInstanceCallback(selectedContract, data)
}) })
@ -321,7 +314,7 @@ class ContractDropdownUI {
}) })
} }
if (selectedContract.contract.object.evm.deployedBytecode && selectedContract.contract.object.evm.deployedBytecode.object.length / 2 > 24576) { if (selectedContract.deployedBytecode && selectedContract.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> 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> More info: <a href="https://github.com/ethereum/EIPs/blob/master/EIPS/eip-170.md" target="_blank">eip-170</a>
</div>`, </div>`,
@ -356,7 +349,7 @@ class ContractDropdownUI {
return this.event.trigger('newContractABIAdded', [abi, address]) return this.event.trigger('newContractABIAdded', [abi, address])
} }
var selectedContract = this.getSelectedContract() var selectedContract = this.getSelectedContract()
this.event.trigger('newContractInstanceAdded', [selectedContract.contract.object, address, this.selectContractNames.value]) this.event.trigger('newContractInstanceAdded', [selectedContract.object, address, this.selectContractNames.value])
} }
) )
} }

@ -62,8 +62,24 @@ class DropdownLogic {
return contracts return contracts
} }
getContractCompiler (name) { getSelectedContract (contractName, compilerAtributeName) {
return this.parentSelf._deps.compilersArtefacts[name] if (!contractName) return null
var compiler = this.parentSelf._deps.compilersArtefacts[compilerAtributeName]
if (!compiler) return null
var contract = compiler.getContract(contractName)
return {
name: contractName,
contract: contract,
compiler: compiler,
abi: contract.object.abi,
bytecodeObject: contract.object.evm.bytecode.object,
bytecodeLinkReferences: contract.object.evm.bytecode.linkReferences,
object: contract.object,
deployedBytecode: contract.object.evm.deployedBytecode
}
} }
} }

Loading…
Cancel
Save