diff --git a/apps/remix-ide/src/app/tabs/compileTab/compileTab.js b/apps/remix-ide/src/app/tabs/compileTab/compileTab.js deleted file mode 100644 index a9c17192cc..0000000000 --- a/apps/remix-ide/src/app/tabs/compileTab/compileTab.js +++ /dev/null @@ -1,135 +0,0 @@ -import * as packageJson from '../../../../../../package.json' -import { Plugin } from '@remixproject/engine' -const EventEmitter = require('events') -var Compiler = require('@remix-project/remix-solidity').Compiler - -const profile = { - name: 'solidity-logic', - displayName: 'Solidity compiler logic', - description: 'Compile solidity contracts - Logic', - methods: ['getCompilerState'], - version: packageJson.version -} - -class CompileTab extends Plugin { - constructor (queryParams, fileManager, editor, config, fileProvider, contentImport) { - super(profile) - this.event = new EventEmitter() - this.queryParams = queryParams - this.compilerImport = contentImport - this.compiler = new Compiler((url, cb) => this.compilerImport.resolveAndSave(url).then((result) => cb(null, result)).catch((error) => cb(error.message))) - this.fileManager = fileManager - this.editor = editor - this.config = config - this.fileProvider = fileProvider - } - - init () { - this.optimize = this.queryParams.get().optimize - this.optimize = this.optimize === 'true' - this.queryParams.update({ optimize: this.optimize }) - this.compiler.set('optimize', this.optimize) - - this.runs = this.queryParams.get().runs - this.runs = this.runs || 200 - this.queryParams.update({ runs: this.runs }) - this.compiler.set('runs', this.runs) - - this.evmVersion = this.queryParams.get().evmVersion - if (this.evmVersion === 'undefined' || this.evmVersion === 'null' || !this.evmVersion) { - this.evmVersion = null - } - this.queryParams.update({ evmVersion: this.evmVersion }) - this.compiler.set('evmVersion', this.evmVersion) - } - - setOptimize (newOptimizeValue) { - this.optimize = newOptimizeValue - this.queryParams.update({ optimize: this.optimize }) - this.compiler.set('optimize', this.optimize) - } - - setRuns (runs) { - this.runs = runs - this.queryParams.update({ runs: this.runs }) - this.compiler.set('runs', this.runs) - } - - setEvmVersion (newEvmVersion) { - this.evmVersion = newEvmVersion - this.queryParams.update({ evmVersion: this.evmVersion }) - this.compiler.set('evmVersion', this.evmVersion) - } - - /** - * Set the compiler to using Solidity or Yul (default to Solidity) - * @params lang {'Solidity' | 'Yul'} ... - */ - setLanguage (lang) { - this.compiler.set('language', lang) - } - - getCompilerState () { - return this.compiler.state - } - - /** - * Compile a specific file of the file manager - * @param {string} target the path to the file to compile - */ - compileFile (target) { - if (!target) throw new Error('No target provided for compiliation') - const provider = this.fileManager.fileProviderOf(target) - if (!provider) throw new Error(`cannot compile ${target}. Does not belong to any explorer`) - return new Promise((resolve, reject) => { - provider.get(target, (error, content) => { - if (error) return reject(error) - const sources = { [target]: { content } } - this.event.emit('startingCompilation') - // setTimeout fix the animation on chrome... (animation triggered by 'staringCompilation') - setTimeout(() => { this.compiler.compile(sources, target); resolve() }, 100) - }) - }) - } - - async isHardhatProject () { - if (this.fileManager.mode === 'localhost') { - return await this.fileManager.exists('hardhat.config.js') - } else return false - } - - runCompiler (hhCompilation) { - try { - if (this.fileManager.mode === 'localhost' && hhCompilation) { - const { currentVersion, optimize, runs } = this.compiler.state - if (currentVersion) { - const fileContent = `module.exports = { - solidity: '${currentVersion.substring(0, currentVersion.indexOf('+commit'))}', - settings: { - optimizer: { - enabled: ${optimize}, - runs: ${runs} - } - } - } - ` - const configFilePath = 'remix-compiler.config.js' - this.fileManager.setFileContent(configFilePath, fileContent) - this.call('hardhat', 'compile', configFilePath).then((result) => { - this.call('terminal', 'log', { type: 'info', value: result }) - }).catch((error) => { - this.call('terminal', 'log', { type: 'error', value: error }) - }) - } - } - this.fileManager.saveCurrentFile() - this.event.emit('removeAnnotations') - var currentFile = this.config.get('currentFile') - return this.compileFile(currentFile) - } catch (err) { - console.error(err) - } - } -} - -module.exports = CompileTab diff --git a/apps/remix-ide/src/app/tabs/compileTab/contractParser.js b/apps/remix-ide/src/app/tabs/compileTab/contractParser.js deleted file mode 100644 index cd603c859a..0000000000 --- a/apps/remix-ide/src/app/tabs/compileTab/contractParser.js +++ /dev/null @@ -1,122 +0,0 @@ -'use strict' - -var solcTranslate = require('solc/translate') -var remixLib = require('@remix-project/remix-lib') -var txHelper = remixLib.execution.txHelper - -module.exports = (contractName, contract, compiledSource) => { - return getDetails(contractName, contract, compiledSource) -} - -var getDetails = function (contractName, contract, source) { - var detail = {} - detail.name = contractName - detail.metadata = contract.metadata - if (contract.evm.bytecode.object) { - detail.bytecode = contract.evm.bytecode.object - } - - detail.abi = contract.abi - - if (contract.evm.bytecode.object) { - detail.bytecode = contract.evm.bytecode - detail.web3Deploy = gethDeploy(contractName.toLowerCase(), contract.abi, contract.evm.bytecode.object) - - detail.metadataHash = retrieveMetadataHash(contract.evm.bytecode.object) - if (detail.metadataHash) { - detail.swarmLocation = 'bzzr://' + detail.metadataHash - } - } - - detail.functionHashes = {} - for (var fun in contract.evm.methodIdentifiers) { - detail.functionHashes[contract.evm.methodIdentifiers[fun]] = fun - } - - detail.gasEstimates = formatGasEstimates(contract.evm.gasEstimates) - - detail.devdoc = contract.devdoc - detail.userdoc = contract.userdoc - - if (contract.evm.deployedBytecode && contract.evm.deployedBytecode.object.length > 0) { - detail['Runtime Bytecode'] = contract.evm.deployedBytecode - } - - if (source && contract.assembly !== null) { - detail.Assembly = solcTranslate.prettyPrintLegacyAssemblyJSON(contract.evm.legacyAssembly, source.content) - } - - return detail -} - -var retrieveMetadataHash = function (bytecode) { - var match = /a165627a7a72305820([0-9a-f]{64})0029$/.exec(bytecode) - if (!match) { - match = /a265627a7a72305820([0-9a-f]{64})6c6578706572696d656e74616cf50037$/.exec(bytecode) - } - if (match) { - return match[1] - } -} - -var gethDeploy = function (contractName, jsonInterface, bytecode) { - var code = '' - var funABI = txHelper.getConstructorInterface(jsonInterface) - - funABI.inputs.forEach(function (inp) { - code += 'var ' + inp.name + ' = /* var of type ' + inp.type + ' here */ ;\n' - }) - - contractName = contractName.replace(/[:./]/g, '_') - code += 'var ' + contractName + 'Contract = new web3.eth.Contract(' + JSON.stringify(jsonInterface).replace('\n', '') + ');' + - '\nvar ' + contractName + ' = ' + contractName + 'Contract.deploy({' + - "\n data: '0x" + bytecode + "', " + - '\n arguments: [' - - funABI.inputs.forEach(function (inp) { - code += '\n ' + inp.name + ',' - }) - - code += '\n ]' + - '\n}).send({' + - '\n from: web3.eth.accounts[0], ' + - "\n gas: '4700000'" + - '\n }, function (e, contract){' + - '\n console.log(e, contract);' + - "\n if (typeof contract.address !== 'undefined') {" + - "\n console.log('Contract mined! address: ' + contract.address + ' transactionHash: ' + contract.transactionHash);" + - '\n }' + - '\n })' - - return code -} - -var formatGasEstimates = function (data) { - if (!data) return {} - if (data.creation === undefined && data.external === undefined && data.internal === undefined) return {} - - var gasToText = function (g) { - return g === null ? 'unknown' : g - } - - var ret = {} - var fun - if ('creation' in data) { - ret.Creation = data.creation - } - - if ('external' in data) { - ret.External = {} - for (fun in data.external) { - ret.External[fun] = gasToText(data.external[fun]) - } - } - - if ('internal' in data) { - ret.Internal = {} - for (fun in data.internal) { - ret.Internal[fun] = gasToText(data.internal[fun]) - } - } - return ret -}