changes to type for request

pull/5370/head
Joseph Izang 1 year ago
parent 2dcf0aba10
commit 46d7f058d6
  1. 55
      apps/vyper/src/app/utils/compiler.tsx
  2. 190
      apps/vyper/src/app/utils/types.ts

@ -1,6 +1,6 @@
import {CompilationResult, ABIDescription} from '@remixproject/plugin-api'
import axios from 'axios'
import { VyperCompilationResultType } from './types'
import { VyperCompilationResultType, CompileFormat, BytecodeObject, AST, ABI, ETHPM3Format, CompilerInformationObject } from './types'
export interface Contract {
name: string
@ -59,16 +59,53 @@ export async function compile(url: string, contract: Contract): Promise<VyperCom
if (extension !== 'vy') {
throw new Error('Use extension .vy for Vyper.')
}
const nameResult = normalizeContractPath(contract.name)
const files = new FormData();
const content = new Blob([contract.content], {
type: 'text/plain'
});
// const files = new FormData();
// const content = new Blob([contract.content], {
// type: 'text/plain'
// });
const nameResult = normalizeContractPath(contract.name)
files.append('files', content, `${nameResult[2]}.vy`)
files.append('data', JSON.stringify({vyper_version: '0.3.10'}))
const response = await axios.post(url + 'compile?vyper_version=0.3.10', files)
// files.append('files', content, `${nameResult[2]}.vy`)
// files.append('data', JSON.stringify({vyper_version: '0.3.10'}))
type ByteCodeType = { bytecode: string, linkReferences: { offset: any; length: number; name?: string; }; linkDependencies?: { offsets: number[]; }; }
const compilePackage: ETHPM3Format = {
manifest: 'ethpm/3',
name: nameResult[2],
version: '0.3.10',
meta: {
authors: [],
license: '',
description: '',
keywords: []
},
sources: {
[contract.name] : {
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 )
console.log({response})
if (response.status === 404) {
throw new Error(`Vyper compiler not found at "${url}".`)

@ -174,10 +174,13 @@ export interface Items {
}
export interface BytecodeObject {
title: string;
type: TypeEnum;
anyOf: BytecodeObjectAnyOf[];
properties: BytecodeObjectProperties;
title: string
type: TypeEnum
offsets: number[]
anyOf: BytecodeObjectAnyOf[]
properties: BytecodeObjectProperties
bytecode: string
linkReferences?: { offset?: any; length?: number; name?: string}[]
}
export interface BytecodeObjectAnyOf {
@ -356,3 +359,182 @@ export interface Version {
title: string;
type: TypeEnum;
}
export type CompileFormat = {
contractTypes: {
abi?: ABI[]
ast?: AST
contractName?: string
depolymentBytecode?: BytecodeObject
devMessages?: { [key: string]: string }
devdoc?: Devdoc
methodIdentifiers?: { [key: string]: string }
pcmap?: any
runtimeBytecode?: BytecodeObject
sourceId?: string
sourcemap?: string
userdoc?: { [key: string]: string }
}
manifest?: string
sources?: {
[fileName: string]: {
content: string
urls?: string[]
references?: string[]
imports?: string[]
checksum?: { [key: string]: string }
}
}
}
export type Devdoc = {
methods: any
}
export type ETHPM3Format = {
manifest: 'ethpm/3'
name: string
version: string
meta: Record<string, any>
buildDependencies: Record<string, any>
sources: {
[fileName: string]: {
content: string
checksum?: {
keccak256: string
hash: string
}
type?: any
license?: string
}
}
compilers: CompilerInformationObject[]
contractTypes: {
contractName: string
sourceId?: string
depolymentBytecode: {
bytecode: string
linkReferences: {
offset: any
length: number
name?: string
}
linkDependencies?: { offsets: number[]}
}
runtimeBytecode: {
bytecode: string
linkReferences: {
offset: any
length: number
name?: string
}
linkDependencies?: LinkValueObject
}
abi: ABI[]
ast: AST
userDoc?: {
methods: any
notice: string
}
devDoc?: {
methods: any,
author: string
details: string
title: string
license: string
}
}
deployments: {
[contractName: string]: ContractInstanceObject
}
}
export type CompilerInformationObject = {
name: string
version: string
settings?: {
optimizer: {
enabled: boolean
runs: number
}
outputSelection: {
[fileName: string]: {
[contractName: string]: string[]
}
}
},
contractTypes?: string[]
}
export type LinkValueObject = {
offsets: number[]
type: string
value: string
}
export type PackageMetaDataObject = {
authors?: string[]
description?: string
keywords?: string[]
license?: string
links?: {
[key: string]: string
}
}
export type ContractInstanceObject = {
contractType: string
address: string
transaction?: string
block?: string
runtimeBytecode?: BytecodeObject
compiler?: string
linkDependencies?: LinkValueObject
}
export type ASTSrc = {
jumpCode: string;
length: number;
}
export type Child = {
astType: string;
children: Child[];
classification: number;
colOffset: number;
endColOffset: number;
endLineno: number;
lineno: number;
name?: string;
src: ChildSrc;
docStr?: Child;
}
export type ChildSrc = {
jumpCode: string;
length: number;
start: number;
}
export type AST = {
astType: string;
children: Child[];
classification: number;
colOffset: number;
endColOffset: number;
endLineno: number;
lineno: number;
name: string;
src: ASTSrc;
}
export type ABI = {
anonymous?: boolean;
inputs: any[];
name?: string;
type: any
stateMutability?: any;
outputs?: any[];
}

Loading…
Cancel
Save