@ -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 >
< / d i v > ` ,
@ -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 . n ame } "> ${ contract . name } </option> ` )
compiler . visitContracts ( ( contract ) => {
contractNames . appendChild ( yo ` <option compiler=" ${ compilerFullN ame } "> ${ contract . name } </option> ` )
} )
} else {
selectContractNames . setAttribute ( 'disabled' , true )