change types to fit compile results

pull/5370/head
Joseph Izang 1 year ago
parent 46d7f058d6
commit 68c3e07144
  1. 3
      apps/vyper/src/app/components/CompilerButton.tsx
  2. 1
      apps/vyper/src/app/components/VyperResult.tsx
  3. 52
      apps/vyper/src/app/utils/compiler.tsx

@ -44,6 +44,7 @@ function CompilerButton({contract, setOutput, compilerUrl, resetCompilerState}:
setOutput(_contract.name, {status: 'failed', message: e.message}) setOutput(_contract.name, {status: 'failed', message: e.message})
return return
} }
console.log({ output })
const compileReturnType = () => { const compileReturnType = () => {
const t: any = toStandardOutput(contract, output) const t: any = toStandardOutput(contract, output)
const temp = _.merge(t['contracts'][contract]) const temp = _.merge(t['contracts'][contract])
@ -110,7 +111,7 @@ function CompilerButton({contract, setOutput, compilerUrl, resetCompilerState}:
remixClient.compilationFinish(_contract.name, _contract.content, data) remixClient.compilationFinish(_contract.name, _contract.content, data)
//map data to compilation details shape //map data to compilation details shape
remixClient.call('compilationDetails' as any, 'showDetails', data) remixClient.call('compilationDetails' as any, 'showDetails', data)
} catch (err: any) { } catch (err: any) {
remixClient.changeStatus({ remixClient.changeStatus({

@ -26,6 +26,7 @@ type TabContentMembers = {
} }
function VyperResult({ output, themeColor }: VyperResultProps) { function VyperResult({ output, themeColor }: VyperResultProps) {
// const [active, setActive] = useState<keyof VyperCompilationResult>('abi')
const [active, setActive] = useState<keyof VyperCompilationResult>('abi') const [active, setActive] = useState<keyof VyperCompilationResult>('abi')
if (!output) if (!output)

@ -51,7 +51,7 @@ export function normalizeContractPath(contractPath: string): string[] {
* @param url The url of the compiler * @param url The url of the compiler
* @param contract The name and content of the contract * @param contract The name and content of the contract
*/ */
export async function compile(url: string, contract: Contract): Promise<VyperCompilationOutput> { export async function compile(url: string, contract: Contract): Promise<any> {
if (!contract.name) { if (!contract.name) {
throw new Error('Set your Vyper contract file.') throw new Error('Set your Vyper contract file.')
} }
@ -69,41 +69,12 @@ export async function compile(url: string, contract: Contract): Promise<VyperCom
// files.append('files', content, `${nameResult[2]}.vy`) // files.append('files', content, `${nameResult[2]}.vy`)
// files.append('data', JSON.stringify({vyper_version: '0.3.10'})) // files.append('data', JSON.stringify({vyper_version: '0.3.10'}))
type ByteCodeType = { bytecode: string, linkReferences: { offset: any; length: number; name?: string; }; linkDependencies?: { offsets: number[]; }; } type ByteCodeType = { bytecode: string, linkReferences: { offset: any; length: number; name?: string; }; linkDependencies?: { offsets: number[]; }; }
const contractName = contract['name']
const compilePackage: ETHPM3Format = { const compilePackage = {
manifest: 'ethpm/3', manifest: 'ethpm/3',
name: nameResult[2],
version: '0.3.10',
meta: {
authors: [],
license: '',
description: '',
keywords: []
},
sources: { sources: {
[contract.name] : { [contractName] : {content : contract.content}
content: contract.content, }
checksum: {
'keccak256': '',
hash: ''
},
type: '',
license: ''
}
},
buildDependencies: {},
compilers: {} as CompilerInformationObject[],
contractTypes: {
[nameResult[2]]: {
content: contract.content
},
contractName: nameResult[2],
abi: {} as ABI[],
ast: {} as AST,
depolymentBytecode: {} as ByteCodeType,
runtimeBytecode: {} as any,
},
deployments: {}
} }
const response = await axios.post(`${url}compile`, compilePackage ) const response = await axios.post(`${url}compile`, compilePackage )
console.log({response}) console.log({response})
@ -122,7 +93,7 @@ export async function compile(url: string, contract: Contract): Promise<VyperCom
})).data })).data
if (status === 'SUCCESS') { if (status === 'SUCCESS') {
result = await(await axios.get(url + 'compiled_artifact/' + compileCode , { result = await(await axios.get(url + 'artifacts/' + compileCode , {
method: 'Get' method: 'Get'
})).data })).data
console.log({result}) console.log({result})
@ -131,6 +102,7 @@ export async function compile(url: string, contract: Contract): Promise<VyperCom
result = await(await axios.get(url + 'exceptions/' + compileCode , { result = await(await axios.get(url + 'exceptions/' + compileCode , {
method: 'Get' method: 'Get'
})).data })).data
console.log({result})
return result.data return result.data
} }
await new Promise((resolve) => setTimeout(() => resolve({}), 2000)) await new Promise((resolve) => setTimeout(() => resolve({}), 2000))
@ -141,19 +113,19 @@ export async function compile(url: string, contract: Contract): Promise<VyperCom
* @param name Name of the contract file * @param name Name of the contract file
* @param compilationResult Result returned by the compiler * @param compilationResult Result returned by the compiler
*/ */
export function toStandardOutput(fileName: string, compilationResult: VyperCompilationResultType): CompilationResult { export function toStandardOutput(fileName: string, compilationResult: any): any {
const contractName = normalizeContractPath(fileName)[2] const contractName = normalizeContractPath(fileName)[2]
const compiledAbi = compilationResult['contractTypes'][contractName].abi const compiledAbi = compilationResult['contractTypes'][contractName].abi
const deployedBytecode = compilationResult['contractTypes'][contractName].deploymentBytecode.bytecode.replace('0x', '') const deployedBytecode = compilationResult['contractTypes'][contractName].deploymentBytecode.bytecode.replace('0x', '')
const bytecode = compilationResult['contractTypes'][contractName].runtimeBytecode.bytecode.replace('0x', '') const bytecode = compilationResult['contractTypes'][contractName].runtimeBytecode.bytecode.replace('0x', '')
const compiledAst = compilationResult['contractTypes'][contractName].abi const compiledAst = compilationResult['contractTypes'][contractName].ast
const methodIdentifiers = compilationResult['contractTypes'][contractName].methodIdentifiers
//const methodIdentifiers = JSON.parse(JSON.stringify(compilationResult['method_identifiers']).replace(/0x/g, '')) //const methodIdentifiers = JSON.parse(JSON.stringify(compilationResult['method_identifiers']).replace(/0x/g, ''))
return { return {
sources: { sources: {
[fileName]: { [fileName]: {
id: 1, id: 1,
ast: compiledAst, ast: compiledAst
legacyAST: {} as any
} }
}, },
contracts: { contracts: {
@ -175,7 +147,7 @@ export function toStandardOutput(fileName: string, compilationResult: VyperCompi
object: bytecode, object: bytecode,
opcodes: '' opcodes: ''
}, },
// methodIdentifiers: methodIdentifiers methodIdentifiers: methodIdentifiers
} }
} }
} as any } as any

Loading…
Cancel
Save