From bca08be13a4157467b9d0bef59fb11056add9a73 Mon Sep 17 00:00:00 2001 From: yann300 Date: Wed, 9 Oct 2024 10:42:34 +0200 Subject: [PATCH] fix compilation --- apps/vyper/src/app/app.tsx | 16 ++-- .../src/app/components/CompileErrorCard.tsx | 3 +- apps/vyper/src/app/utils/compiler.tsx | 92 +++++-------------- apps/vyper/src/app/utils/types.ts | 18 +++- 4 files changed, 51 insertions(+), 78 deletions(-) diff --git a/apps/vyper/src/app/app.tsx b/apps/vyper/src/app/app.tsx index 304f87b48d..c08224206a 100644 --- a/apps/vyper/src/app/app.tsx +++ b/apps/vyper/src/app/app.tsx @@ -15,6 +15,7 @@ import { CustomTooltip } from '@remix-ui/helper' import { Form } from 'react-bootstrap' import { CompileErrorCard } from './components/CompileErrorCard' import CustomAccordionToggle from './components/CustomAccordionToggle' +import { VyperCompilationError, VyperCompilationResultType } from './utils/types' interface AppState { status: 'idle' | 'inProgress' @@ -29,7 +30,7 @@ interface OutputMap { const App = () => { const [contract, setContract] = useState() - const [output, setOutput] = useState(remixClient.compilerOutput) + const [output, setOutput] = useState(remixClient.compilerOutput) const [state, setState] = useState({ status: 'idle', environment: 'remote', @@ -109,6 +110,7 @@ const App = () => { const [cloneCount, setCloneCount] = useState(0) + console.log((output)) return (
@@ -165,15 +167,17 @@ const App = () => {
setOutput({ ...output, [name]: update })} resetCompilerState={resetCompilerResultState} output={output} remixClient={remixClient}/>
-
- {output && Object.keys(output).length > 0 && output.status !== 'failed' ? ( + {output && output.status === 'success' && <> - ) : output.status === 'failed' ? ( - - ) : null} + } + {output && output.status === 'failed' && + output.errors && output.errors.map((error) => { + return + }) + }
diff --git a/apps/vyper/src/app/components/CompileErrorCard.tsx b/apps/vyper/src/app/components/CompileErrorCard.tsx index e0d49c87e9..5ed10645bb 100644 --- a/apps/vyper/src/app/components/CompileErrorCard.tsx +++ b/apps/vyper/src/app/components/CompileErrorCard.tsx @@ -1,8 +1,9 @@ import {CopyToClipboard} from '@remix-ui/clipboard' import Reaact from 'react' import { RemixClient } from '../utils' +import { VyperCompilationError} from '../utils/types' -export function CompileErrorCard(props: { output: any, plugin: RemixClient }) { +export function CompileErrorCard(props: { output: VyperCompilationError, plugin: RemixClient }) { return (
output.status === 'failed' @@ -45,35 +25,6 @@ export function normalizeContractPath(contractPath: string): string[] { return [folders,resultingPath, filename] } -function parseErrorString(errorStructure: string[]) { - // Split the string into lines - let errorType = '' - let message = '' - let tline = '' - errorStructure.forEach(errorMsg => { - const choppedup = errorMsg.split(': ') - errorType = choppedup[0].trim().split('\n')[1] - message = choppedup[1] - // if (errorStructure.length > 2) { - // console.log(choppedup[2].split(',')[1]) - // } - // console.log(choppedup) - }) - let lines = errorStructure[0].trim().split('\n') - - const errorObject = { - status: 'failed', - message: `${errorType} - ${message}`, - column: '', - line: '' - } - message = null - // targetLine = null - lines = null - tline = null - return errorObject -} - const buildError = (output) => { if (isCompilationError(output)) { const line = output.line @@ -120,8 +71,9 @@ const compileReturnType = (output, contract) => { const depByteCode = evm.deployedBytecode const runtimeBytecode = evm.bytecode const methodIdentifiers = evm.methodIdentifiers - const version = output?.compilers[0]?.version ?? '0.4.0' - const optimized = output?.compilers[0]?.settings?.optimize ?? true + // TODO: verify this is correct + const version = output.version || '0.4.0' + const optimized = output.optimize || true const evmVersion = '' const result: { @@ -179,7 +131,7 @@ const fixContractContent = (content: string) => { * @param url The url of the compiler * @param contract The name and content of the contract */ -export async function compile(url: string, contract: Contract): Promise { +export async function compile(url: string, contract: Contract): Promise { if (!contract.name) { throw new Error('Set your Vyper contract file.') } @@ -211,7 +163,6 @@ export async function compile(url: string, contract: Contract): Promise { contractName = null response = null let result: any - let intermediateError const status = await (await axios.get(url + 'status/' + compileCode , { method: 'Get' @@ -226,10 +177,7 @@ export async function compile(url: string, contract: Contract): Promise { const intermediate = await(await axios.get(url + 'exceptions/' + compileCode , { method: 'Get' })).data - // console.log('Errors found', intermediate) - result = parseErrorString(intermediate) - intermediateError = intermediate - return result + return intermediate } await new Promise((resolve) => setTimeout(() => resolve({}), 3000)) } @@ -293,12 +241,13 @@ export async function compileContract(contract: string, compilerUrl: string, set try { _contract = await remixClient.getContract() } catch (e: any) { - const errorGettingContract = { + const errorGettingContract: VyperCompilationError = { status: 'failed', - message: e.message + message: e.mesaage, + error_type: 'fetch_contract' } - remixClient.eventEmitter.emit('setOutput', errorGettingContract) + remixClient.eventEmitter.emit('setOutput', { status: 'failed', errors: [errorGettingContract] } ) return } remixClient.changeStatus({ @@ -306,10 +255,9 @@ export async function compileContract(contract: string, compilerUrl: string, set type: 'info', title: 'Compiling' }) - let output // try { - output = await compile(compilerUrl, _contract) - if (output.status === 'failed') { + let output = await compile(compilerUrl, _contract) + if (output && output[0] && output[0].status === 'failed') { remixClient.changeStatus({ key: 'failed', type: 'error', @@ -317,13 +265,11 @@ export async function compileContract(contract: string, compilerUrl: string, set }) setLoadingSpinnerState && setLoadingSpinnerState(false) - remixClient.eventEmitter.emit('setOutput', { status: 'failed', message: output.message, title: 'Error compiling...', line: output.line, column: output.column, key: 1 }) - output = null + remixClient.eventEmitter.emit('setOutput', { status: 'failed', errors: output }) return } // SUCCESS - // remixClient.discardHighlight() remixClient.changeStatus({ key: 'succeed', type: 'success', @@ -336,9 +282,9 @@ export async function compileContract(contract: string, compilerUrl: string, set const contractName = _contract['name'] const compileResult = compileReturnType(output, contractName) if (setOutput === null || setOutput === undefined) { - remixClient.eventEmitter.emit('setOutput', { contractName, compileResult }) + remixClient.eventEmitter.emit('setOutput', { status: 'success', contractName, compileResult }) } else { - remixClient.eventEmitter.emit('setOutput', { contractName, compileResult }) + remixClient.eventEmitter.emit('setOutput', { status: 'success', contractName, compileResult }) } } catch (err: any) { remixClient.changeStatus({ @@ -347,8 +293,14 @@ export async function compileContract(contract: string, compilerUrl: string, set title: `1 error occurred ${err.message}` }) + const errorGettingContract: VyperCompilationError = { + status: 'failed', + message: err.mesaage, + error_type: 'unknown_error' + } + setLoadingSpinnerState && setLoadingSpinnerState(false) - remixClient.eventEmitter.emit('setOutput', { status: 'failed', message: err.message }) + remixClient.eventEmitter.emit('setOutput', { status: 'failed', errors: [errorGettingContract] }) } } diff --git a/apps/vyper/src/app/utils/types.ts b/apps/vyper/src/app/utils/types.ts index 928f30ed07..98eacd4b4c 100644 --- a/apps/vyper/src/app/utils/types.ts +++ b/apps/vyper/src/app/utils/types.ts @@ -11,11 +11,27 @@ export interface VyperCompilationResult { } } -export interface VyperCompilationError { +export type VyperCompilationError = { status: 'failed' column?: number line?: number message: string + error_type: string +} + +export type VyperCompilationOutput = VyperCompilationResult | VyperCompilationError + + +export type VyperCompilationResult = { + contractName: string + abi: any, + bytecode: any, + runtimeBytecode: any, + ir: string, + methodIdentifiers: any, + version?: string, + evmVersion?: string + optimized?: boolean } export type VyperCompilationResultType = {