Skip to content

Commit 0b2a49b

Browse files
committed
Warn user at deploy time if contract size above ethereum/EIPs#170
1 parent 69ea9d5 commit 0b2a49b

File tree

1 file changed

+38
-18
lines changed

1 file changed

+38
-18
lines changed

src/app/tabs/run-tab.js

+38-18
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ var Recorder = require('../../recorder')
1818
var addTooltip = require('../ui/tooltip')
1919
var css = require('./styles/run-tab-styles')
2020
var MultiParamManager = require('../../multiParamManager')
21+
var modalDialog = require('../ui/modaldialog')
2122

2223
function runTab (opts, localRegistry) {
2324
/* -------------------------
@@ -421,24 +422,43 @@ function contractDropdown (events, self) {
421422
return
422423
}
423424

424-
var constructor = txHelper.getConstructorInterface(selectedContract.contract.object.abi)
425-
self._deps.filePanel.compilerMetadata().metadataOf(selectedContract.name, (error, contractMetadata) => {
426-
if (error) return self._deps.logCallback(`creation of ${selectedContract.name} errored: ` + error)
427-
if (contractMetadata.autoDeployLib) {
428-
txFormat.buildData(selectedContract.name, selectedContract.contract.object, self._deps.compiler.getContracts(), true, constructor, args, (error, data) => {
429-
createInstanceCallback(error, selectedContract, data)
430-
}, (msg) => {
431-
self._deps.logCallback(msg)
432-
}, (data, runTxCallback) => {
433-
// called for libraries deployment
434-
self._deps.udapp.runTx(data, runTxCallback)
435-
})
436-
} else {
437-
txFormat.encodeConstructorCallAndLinkLibraries(selectedContract.contract.object, args, constructor, contractMetadata.linkReferences, selectedContract.contract.object.evm.bytecode.linkReferences, (error, data) => {
438-
createInstanceCallback(error, selectedContract, data)
439-
})
440-
}
441-
})
425+
var forceSend = () => {
426+
var constructor = txHelper.getConstructorInterface(selectedContract.contract.object.abi)
427+
self._deps.filePanel.compilerMetadata().metadataOf(selectedContract.name, (error, contractMetadata) => {
428+
if (error) return self._deps.logCallback(`creation of ${selectedContract.name} errored: ` + error)
429+
if (contractMetadata.autoDeployLib) {
430+
txFormat.buildData(selectedContract.name, selectedContract.contract.object, self._deps.compiler.getContracts(), true, constructor, args, (error, data) => {
431+
createInstanceCallback(error, selectedContract, data)
432+
}, (msg) => {
433+
self._deps.logCallback(msg)
434+
}, (data, runTxCallback) => {
435+
// called for libraries deployment
436+
self._deps.udapp.runTx(data, runTxCallback)
437+
})
438+
} else {
439+
txFormat.encodeConstructorCallAndLinkLibraries(selectedContract.contract.object, args, constructor, contractMetadata.linkReferences, selectedContract.contract.object.evm.bytecode.linkReferences, (error, data) => {
440+
createInstanceCallback(error, selectedContract, data)
441+
})
442+
}
443+
})
444+
}
445+
446+
// check contract code size limit. Refs: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-170.md
447+
if (selectedContract.contract.object.evm.deployedBytecode.object.length > 24576) {
448+
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.</div>`,
449+
{
450+
label: 'Force Send',
451+
fn: () => {
452+
forceSend()
453+
}}, {
454+
label: 'Cancel',
455+
fn: () => {
456+
self._deps.logCallback(`creation of ${selectedContract.name} canceled by user.`)
457+
}
458+
})
459+
} else {
460+
forceSend()
461+
}
442462
}
443463

444464
// ACCESS DEPLOYED INSTANCE

0 commit comments

Comments
 (0)