intermediate commiy

pull/5370/head
aniket-engg 3 years ago committed by yann300
parent 34f92accd5
commit ac5423018b
  1. 34
      apps/solidity-compiler/src/app/compiler-api.ts
  2. 1
      apps/solidity-compiler/webpack.config.js
  3. 1
      libs/remix-lib/src/types/ICompilerApi.ts
  4. 31
      libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx
  5. 35
      libs/remix-ui/solidity-compiler/src/lib/logic/compileTabLogic.ts
  6. 6
      libs/remix-ui/solidity-compiler/src/lib/solidity-compiler.tsx
  7. 1
      libs/remix-ui/solidity-compiler/src/lib/types/index.ts
  8. 1231
      package-lock.json
  9. 2
      package.json

@ -1,6 +1,11 @@
import React from 'react';
import { compile, helper } from '@remix-project/remix-solidity' import { compile, helper } from '@remix-project/remix-solidity'
import { CompileTabLogic, parseContracts } from '@remix-ui/solidity-compiler' // eslint-disable-line import { CompileTabLogic, parseContracts } from '@remix-ui/solidity-compiler' // eslint-disable-line
import type { ConfigurationSettings } from '@remix-project/remix-lib-ts' import type { ConfigurationSettings } from '@remix-project/remix-lib-ts'
import Schema from "@truffle/contract-schema"
import Config from '@truffle/config'
import { Compile } from "@truffle/compile-solidity"
import { Shims } from "@truffle/compile-common"
export const CompilerApiMixin = (Base) => class extends Base { export const CompilerApiMixin = (Base) => class extends Base {
currentFile: string currentFile: string
@ -100,6 +105,35 @@ export const CompilerApiMixin = (Base) => class extends Base {
return this.call('hardhat', 'compile', configFile) return this.call('hardhat', 'compile', configFile)
} }
async compileWithTruffle (fileName, CompConfig) {
console.log('fileName-in compileWithTruffle-->', fileName)
console.log('config-in compileWithTruffle-->', CompConfig)
const sources = {
Example: await this.call('fileManager', 'getFile', fileName)
}
let config = Config.default().with(CompConfig)
console.log('config---->', config)
console.log('sources---->', sources)
// Compile first
const { compilations } = await Compile.sources({
sources,
options: config
});
console.log('compilations----->', compilations)
const { contracts } = compilations[0];
// use forEach
const exampleContract = contracts.find(
contract => contract.contractName === "Owner"
);
const compiled = Schema.normalize(
Shims.NewToLegacy.forContract(exampleContract)
);
if(!compiled.updatedAt) compiled.updatedAt = new Date().toISOString()
console.log('compiled----->', compiled)
return "done"
}
logToTerminal (content) { logToTerminal (content) {
return this.call('terminal', 'log', content) return this.call('terminal', 'log', content)
} }

@ -7,6 +7,7 @@ module.exports = config => {
...nxWebpackConfig, ...nxWebpackConfig,
node: { node: {
fs: 'empty', fs: 'empty',
path: 'empty',
tls: 'empty', tls: 'empty',
readline: 'empty', readline: 'empty',
net: 'empty', net: 'empty',

@ -41,6 +41,7 @@ export interface ICompilerApi {
logToTerminal: (log: terminalLog) => void logToTerminal: (log: terminalLog) => void
compileWithHardhat: (configPath: string) => Promise<string> compileWithHardhat: (configPath: string) => Promise<string>
compileWithTruffle: (file: string, config: Record<string, any>) => Promise<string>
statusChanged: (data: { key: string, title?: string, type?: string }) => void, statusChanged: (data: { key: string, title?: string, type?: string }) => void,
emit?: (key: string, ...payload: any) => void emit?: (key: string, ...payload: any) => void
} }

@ -20,7 +20,7 @@ declare global {
const _paq = window._paq = window._paq || [] //eslint-disable-line const _paq = window._paq = window._paq || [] //eslint-disable-line
export const CompilerContainer = (props: CompilerContainerProps) => { export const CompilerContainer = (props: CompilerContainerProps) => {
const { api, compileTabLogic, tooltip, modal, compiledFileName, updateCurrentVersion, configurationSettings, isHardhatProject } = props // eslint-disable-line const { api, compileTabLogic, tooltip, modal, compiledFileName, updateCurrentVersion, configurationSettings, isHardhatProject, isTruffleProject } = props // eslint-disable-line
const [state, setState] = useState({ const [state, setState] = useState({
hideWarnings: false, hideWarnings: false,
autoCompile: false, autoCompile: false,
@ -42,6 +42,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
const compileIcon = useRef(null) const compileIcon = useRef(null)
const promptMessageInput = useRef(null) const promptMessageInput = useRef(null)
const [hhCompilation, sethhCompilation] = useState(false) const [hhCompilation, sethhCompilation] = useState(false)
const [truffleCompilation, setTruffleCompilation] = useState(false)
const [compilerContainer, dispatch] = useReducer(compilerReducer, compilerInitialState) const [compilerContainer, dispatch] = useReducer(compilerReducer, compilerInitialState)
useEffect(() => { useEffect(() => {
@ -325,7 +326,10 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
if (!isSolFileSelected()) return if (!isSolFileSelected()) return
_setCompilerVersionFromPragma(currentFile) _setCompilerVersionFromPragma(currentFile)
compileTabLogic.runCompiler(hhCompilation) let externalCompType
if (hhCompilation) externalCompType = 'hardhat'
else if (truffleCompilation) externalCompType = 'truffle'
compileTabLogic.runCompiler(externalCompType)
} }
const _updateVersionSelector = (version, customUrl = '') => { const _updateVersionSelector = (version, customUrl = '') => {
@ -500,6 +504,13 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
api.setAppParameter('hardhat-compilation', checked) api.setAppParameter('hardhat-compilation', checked)
} }
const updateTruffleCompilation = (event) => {
const checked = event.target.checked
setTruffleCompilation(checked)
api.setAppParameter('truffle-compilation', checked)
}
/* /*
The following functions map with the above event handlers. The following functions map with the above event handlers.
They are an external API for modifying the compiler configuration. They are an external API for modifying the compiler configuration.
@ -594,6 +605,22 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
</a> </a>
</div> </div>
} }
{
isTruffleProject &&
<div className="mt-3 remixui_compilerConfig custom-control custom-checkbox">
<input className="remixui_autocompile custom-control-input" onChange={updateTruffleCompilation} id="enableTruffle" type="checkbox" title="Enable Truffle Compilation" checked={truffleCompilation} />
<label className="form-check-label custom-control-label" htmlFor="enableTruffle">Enable Truffle Compilation</label>
<a className="mt-1 text-nowrap" href='https://remix-ide.readthedocs.io/en/latest/' target={'_blank'}>
<OverlayTrigger placement={'right'} overlay={
<Tooltip className="text-nowrap" id="overlay-tooltip">
<span className="p-1 pr-3" style={{ backgroundColor: 'black', minWidth: '230px' }}>Learn how to use Truffle Compilation</span>
</Tooltip>
}>
<i style={{ fontSize: 'medium' }} className={'ml-2 fal fa-info-circle'} aria-hidden="true"></i>
</OverlayTrigger>
</a>
</div>
}
<button id="compileBtn" data-id="compilerContainerCompileBtn" className="btn btn-primary btn-block remixui_disabled mt-3" title="Compile" onClick={compile} disabled={disableCompileButton}> <button id="compileBtn" data-id="compilerContainerCompileBtn" className="btn btn-primary btn-block remixui_disabled mt-3" title="Compile" onClick={compile} disabled={disableCompileButton}>
<span> <span>
{ <i ref={compileIcon} className="fas fa-sync remixui_iconbtn" aria-hidden="true"></i> } { <i ref={compileIcon} className="fas fa-sync remixui_iconbtn" aria-hidden="true"></i> }

@ -109,9 +109,16 @@ export class CompileTabLogic {
} else return false } else return false
} }
runCompiler (hhCompilation) { async isTruffleProject () {
return true
// if (this.api.getFileManagerMode() === 'localhost') {
// return await this.api.fileExists('truffle.config.js')
// } else return false
}
runCompiler (externalCompType) {
try { try {
if (this.api.getFileManagerMode() === 'localhost' && hhCompilation) { if (this.api.getFileManagerMode() === 'localhost' && externalCompType === 'hardhat') {
const { currentVersion, optimize, runs } = this.compiler.state const { currentVersion, optimize, runs } = this.compiler.state
if (currentVersion) { if (currentVersion) {
const fileContent = `module.exports = { const fileContent = `module.exports = {
@ -133,6 +140,30 @@ export class CompileTabLogic {
this.api.logToTerminal({ type: 'error', value: error }) this.api.logToTerminal({ type: 'error', value: error })
}) })
} }
} else if (externalCompType === 'truffle') {
const fileName = this.api.currentFile
const { currentVersion, optimize, runs, evmVersion} = this.compiler.state
if (currentVersion) {
const compConfig = {
compilers: {
solc: {
version: `'${currentVersion.substring(0, currentVersion.indexOf('+commit'))}'`,
settings: {
optimizer: {
enabled: optimize,
runs: runs
},
evmVersion: evmVersion
}
}
}
}
this.api.compileWithTruffle(fileName, compConfig).then((result) => {
this.api.logToTerminal({ type: 'info', value: result })
}).catch((error) => {
this.api.logToTerminal({ type: 'error', value: error })
})
}
} }
// TODO readd saving current file // TODO readd saving current file
this.api.saveCurrentFile() this.api.saveCurrentFile()

@ -12,6 +12,7 @@ export const SolidityCompiler = (props: SolidityCompilerProps) => {
const { api, api: { currentFile, compileTabLogic, configurationSettings } } = props const { api, api: { currentFile, compileTabLogic, configurationSettings } } = props
const [state, setState] = useState({ const [state, setState] = useState({
isHardhatProject: false, isHardhatProject: false,
isTruffleProject: false,
currentFile, currentFile,
loading: false, loading: false,
compileTabLogic: null, compileTabLogic: null,
@ -64,8 +65,9 @@ export const SolidityCompiler = (props: SolidityCompilerProps) => {
api.onSetWorkspace = async (isLocalhost: boolean) => { api.onSetWorkspace = async (isLocalhost: boolean) => {
const isHardhat = isLocalhost && await compileTabLogic.isHardhatProject() const isHardhat = isLocalhost && await compileTabLogic.isHardhatProject()
const isTruffle = await compileTabLogic.isTruffleProject()
setState(prevState => { setState(prevState => {
return { ...prevState, currentFile, isHardhatProject: isHardhat } return { ...prevState, currentFile, isHardhatProject: isHardhat, isTruffleProject: isTruffle }
}) })
} }
@ -148,7 +150,7 @@ export const SolidityCompiler = (props: SolidityCompilerProps) => {
return ( return (
<> <>
<div id="compileTabView"> <div id="compileTabView">
<CompilerContainer api={api} isHardhatProject={state.isHardhatProject} compileTabLogic={compileTabLogic} tooltip={toast} modal={modal} compiledFileName={currentFile} updateCurrentVersion={updateCurrentVersion} configurationSettings={configurationSettings} /> <CompilerContainer api={api} isHardhatProject={state.isHardhatProject} isTruffleProject={state.isTruffleProject} compileTabLogic={compileTabLogic} tooltip={toast} modal={modal} compiledFileName={currentFile} updateCurrentVersion={updateCurrentVersion} configurationSettings={configurationSettings} />
{ contractsFile[currentFile] && contractsFile[currentFile].contractsDetails && <ContractSelection api={api} contractsDetails={contractsFile[currentFile].contractsDetails} contractList={contractsFile[currentFile].contractList} modal={modal} /> } { contractsFile[currentFile] && contractsFile[currentFile].contractsDetails && <ContractSelection api={api} contractsDetails={contractsFile[currentFile].contractsDetails} contractList={contractsFile[currentFile].contractList} modal={modal} /> }
{ compileErrors[currentFile] && { compileErrors[currentFile] &&
<div className="remixui_errorBlobs p-4" data-id="compiledErrors"> <div className="remixui_errorBlobs p-4" data-id="compiledErrors">

@ -10,6 +10,7 @@ export interface CompilerContainerProps {
api: ICompilerApi, api: ICompilerApi,
compileTabLogic: CompileTabLogic, compileTabLogic: CompileTabLogic,
isHardhatProject: boolean, isHardhatProject: boolean,
isTruffleProject: boolean,
tooltip: (message: string | JSX.Element) => void, tooltip: (message: string | JSX.Element) => void,
modal: (title: string, message: string | JSX.Element, okLabel: string, okFn: () => void, cancelLabel?: string, cancelFn?: () => void) => void, modal: (title: string, message: string | JSX.Element, okLabel: string, okFn: () => void, cancelLabel?: string, cancelFn?: () => void) => void,
compiledFileName: string, compiledFileName: string,

1231
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -159,6 +159,8 @@
"@remixproject/plugin-utils": "^0.3.28", "@remixproject/plugin-utils": "^0.3.28",
"@remixproject/plugin-webview": "^0.3.28", "@remixproject/plugin-webview": "^0.3.28",
"@remixproject/plugin-ws": "^0.3.28", "@remixproject/plugin-ws": "^0.3.28",
"@truffle/compile-solidity": "^6.0.17",
"@truffle/contract-schema": "^3.4.6",
"ansi-gray": "^0.1.1", "ansi-gray": "^0.1.1",
"async": "^2.6.2", "async": "^2.6.2",
"axios": ">=0.26.0", "axios": ">=0.26.0",

Loading…
Cancel
Save