diff --git a/src/app/tabs/runTab/contractDropdown.js b/src/app/tabs/runTab/contractDropdown.js index d602f86333..d7eb237453 100644 --- a/src/app/tabs/runTab/contractDropdown.js +++ b/src/app/tabs/runTab/contractDropdown.js @@ -1,13 +1,10 @@ var yo = require('yo-yo') var css = require('../styles/run-tab-styles') -var executionContext = require('../../../execution-context') var modalDialogCustom = require('../../ui/modal-dialog-custom') var remixLib = require('remix-lib') var txExecution = remixLib.execution.txExecution var txFormat = remixLib.execution.txFormat -var txHelper = remixLib.execution.txHelper var EventManager = remixLib.EventManager -var typeConversion = remixLib.execution.typeConversion var confirmDialog = require('../../execution/confirmDialog') var modalDialog = require('../../ui/modaldialog') var MultiParamManager = require('../../../multiParamManager') @@ -100,11 +97,9 @@ class ContractDropdownUI { } var selectedContract = this.getSelectedContract() - var ctrabi = txHelper.getConstructorInterface(selectedContract.abi) - var ctrEVMbc = selectedContract.bytecodeObject - var createConstructorInstance = new MultiParamManager(0, ctrabi, (valArray, inputsValues) => { + var createConstructorInstance = new MultiParamManager(0, selectedContract.getConstructorInterface(), (valArray, inputsValues) => { this.createInstance(inputsValues, selectedContract.compiler) - }, txHelper.inputParametersDeclarationToString(ctrabi.inputs), 'Deploy', ctrEVMbc) + }, selectedContract.getConstructorInputs(), 'Deploy', selectedContract.bytecodeObject) this.createPanel.appendChild(createConstructorInstance.render()) } @@ -129,15 +124,15 @@ class ContractDropdownUI { if (network.name !== 'Main') { return continueTxExecution(null) } - var amount = executionContext.web3().fromWei(typeConversion.toInt(tx.value), 'ether') + var amount = this.dropdownLogic.fromWei(tx.value, true) var content = confirmDialog(tx, amount, gasEstimation, this.parentSelf, (gasPrice, cb) => { let txFeeText, priceStatus // TODO: this try catch feels like an anti pattern, can/should be // removed, but for now keeping the original logic try { - var fee = executionContext.web3().toBigNumber(tx.gas).mul(executionContext.web3().toBigNumber(executionContext.web3().toWei(gasPrice.toString(10), 'gwei'))) - txFeeText = ' ' + executionContext.web3().fromWei(fee.toString(10), 'ether') + ' Ether' + var fee = this.dropdownLogic.calculateFee(tx.gas, gasPrice, 'gwei') + txFeeText = ' ' + this.dropdownLogic.fromWei(fee) + ' Ether' priceStatus = true } catch (e) { txFeeText = ' Please fix this issue before sending any transaction. ' + e.message @@ -146,13 +141,13 @@ class ContractDropdownUI { cb(txFeeText, priceStatus) }, (cb) => { - executionContext.web3().eth.getGasPrice((error, gasPrice) => { + this.dropdownLogic.getGasPrice((error, gasPrice) => { var warnMessage = ' Please fix this issue before sending any transaction. ' if (error) { return cb('Unable to retrieve the current network gas price.' + warnMessage + error) } try { - var gasPriceValue = executionContext.web3().fromWei(gasPrice.toString(10), 'gwei') + var gasPriceValue = this.dropdownLogic.fromWei(gasPrice, false, 'gwei') cb(null, gasPriceValue) } catch (e) { cb(warnMessage + e.message, null, false) @@ -168,7 +163,7 @@ class ContractDropdownUI { if (!content.gasPriceStatus) { cancelCb('Given gas price is not correct') } else { - var gasPrice = executionContext.web3().toWei(content.querySelector('#gasprice').value, 'gwei') + var gasPrice = this.dropdownLogic.toWei(content.querySelector('#gasprice').value, 'gwei') continueTxExecution(gasPrice) } }}, { @@ -206,17 +201,15 @@ class ContractDropdownUI { if (error) { return this.parentSelf._deps.logCallback(`creation of ${selectedContract.name} errored: ${error}`) } - var isVM = executionContext.isVM() + var isVM = this.dropdownLogic.isVM() if (isVM) { var vmError = txExecution.checkVMError(txResult) if (vmError.error) { - this.parentSelf._deps.logCallback(vmError.message) - return + return this.parentSelf._deps.logCallback(vmError.message) } } if (txResult.result.status && txResult.result.status === '0x0') { - this.parentSelf._deps.logCallback(`creation of ${selectedContract.name} errored: transaction execution failed`) - return + return this.parentSelf._deps.logCallback(`creation of ${selectedContract.name} errored: transaction execution failed`) } this.event.trigger('clearInstance') var address = isVM ? txResult.result.createdAddress : txResult.result.contractAddress @@ -234,7 +227,7 @@ class ContractDropdownUI { } var forceSend = () => { - var constructor = txHelper.getConstructorInterface(selectedContract.abi) + var constructor = selectedContract.getConstructorInterface() this.parentSelf._deps.filePanel.compilerMetadata().deployMetadataOf(selectedContract.name, (error, contractMetadata) => { if (error) return this.parentSelf._deps.logCallback(`creation of ${selectedContract.name} errored: ` + error) if (!contractMetadata || (contractMetadata && contractMetadata.autoDeployLib)) { @@ -250,15 +243,15 @@ class ContractDropdownUI { if (network.name !== 'Main') { return continueTxExecution(null) } - var amount = executionContext.web3().fromWei(typeConversion.toInt(tx.value), 'ether') + var amount = this.dropdownLogic.fromWei(tx.value, true, 'ether') var content = confirmDialog(tx, amount, gasEstimation, this.parentSelf, (gasPrice, cb) => { let txFeeText, priceStatus // TODO: this try catch feels like an anti pattern, can/should be // removed, but for now keeping the original logic try { - var fee = executionContext.web3().toBigNumber(tx.gas).mul(executionContext.web3().toBigNumber(executionContext.web3().toWei(gasPrice.toString(10), 'gwei'))) - txFeeText = ' ' + executionContext.web3().fromWei(fee.toString(10), 'ether') + ' Ether' + var fee = this.dropdownLogic.calculateFee(tx.gas, gasPrice) + txFeeText = ' ' + this.dropdownLogic.fromWei(fee, false, 'ether') + ' Ether' priceStatus = true } catch (e) { txFeeText = ' Please fix this issue before sending any transaction. ' + e.message @@ -267,13 +260,13 @@ class ContractDropdownUI { cb(txFeeText, priceStatus) }, (cb) => { - executionContext.web3().eth.getGasPrice((error, gasPrice) => { + this.dropdownLogic.getGasPrice((error, gasPrice) => { var warnMessage = ' Please fix this issue before sending any transaction. ' if (error) { return cb('Unable to retrieve the current network gas price.' + warnMessage + error) } try { - var gasPriceValue = executionContext.web3().fromWei(gasPrice.toString(10), 'gwei') + var gasPriceValue = this.dropdownLogic.fromWei(gasPrice, false, 'gwei') cb(null, gasPriceValue) } catch (e) { cb(warnMessage + e.message, null, false) @@ -289,7 +282,7 @@ class ContractDropdownUI { if (!content.gasPriceStatus) { cancelCb('Given gas price is not correct') } else { - var gasPrice = executionContext.web3().toWei(content.querySelector('#gasprice').value, 'gwei') + var gasPrice = this.dropdownLogic.toWei(content.querySelector('#gasprice').value, 'gwei') continueTxExecution(gasPrice) } }}, { @@ -314,7 +307,7 @@ class ContractDropdownUI { }) } - if (selectedContract.deployedBytecode && selectedContract.deployedBytecode.object.length / 2 > 24576) { + if (selectedContract.isOverSizeLimit()) { 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
`, diff --git a/src/app/tabs/runTab/model/dropdownlogic.js b/src/app/tabs/runTab/model/dropdownlogic.js index f5a2f4ab91..de525fb40f 100644 --- a/src/app/tabs/runTab/model/dropdownlogic.js +++ b/src/app/tabs/runTab/model/dropdownlogic.js @@ -1,5 +1,8 @@ var ethJSUtil = require('ethereumjs-util') var remixLib = require('remix-lib') +var txHelper = remixLib.execution.txHelper +var executionContext = remixLib.execution.executionContext +var typeConversion = remixLib.execution.typeConversion var CompilerAbstract = require('../../../compiler/compiler-abstract') var EventManager = remixLib.EventManager @@ -78,9 +81,44 @@ class DropdownLogic { bytecodeObject: contract.object.evm.bytecode.object, bytecodeLinkReferences: contract.object.evm.bytecode.linkReferences, object: contract.object, - deployedBytecode: contract.object.evm.deployedBytecode + deployedBytecode: contract.object.evm.deployedBytecode, + getConstructorInterface: () => { + return txHelper.getConstructorInterface(contract.object.abi) + }, + getConstructorInputs: () => { + var constructorInteface = txHelper.getConstructorInterface(contract.object.abi) + return txHelper.inputParametersDeclarationToString(constructorInteface.inputs) + }, + isOverSizeLimit: () => { + var deployedBytecode = contract.object.evm.deployedBytecode + return (deployedBytecode && deployedBytecode.object.length / 2 > 24576) + } } } + + fromWei (value, doTypeConversion, unit) { + if (doTypeConversion) { + return executionContext.web3().fromWei(typeConversion.toInt(value), unit || 'ether') + } + return executionContext.web3().fromWei(value.toString(10), unit || 'ether') + } + + toWei (value, unit) { + return executionContext.web3().toWei(value, unit || 'gwei') + } + + calculateFee (gas, gasPrice, unit) { + return executionContext.web3().toBigNumber(gas).mul(executionContext.web3().toBigNumber(executionContext.web3().toWei(gasPrice.toString(10), unit || 'gwei'))) + } + + getGasPrice (cb) { + return executionContext.web3().eth.getGasPrice(cb) + } + + isVM () { + return executionContext.isVM() + } + } module.exports = DropdownLogic