Skip to content

Commit

Permalink
updates for v0.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
joeizang committed Sep 12, 2024
1 parent 6b9a7c5 commit cbb5dfe
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 18 deletions.
40 changes: 25 additions & 15 deletions apps/vyper/src/app/utils/compiler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export function normalizeContractPath(contractPath: string): string[] {
function parseErrorString(errorString) {
// Split the string into lines
console.log(errorString)
return
let lines = errorString.trim().split('\n')
// Extract the line number and message
let message = errorString.trim()
Expand Down Expand Up @@ -141,27 +142,32 @@ const compileReturnType = (output, contract) => {
return result
}

const fixContractContent = (content: string) => {
const pragmaRegex = /#\s*pragma\s+[@]*version\s+([\^~<>!=^]+)\s*(\d+\.\d+\.\d+)/
if (content.length === 0) return
const updatePragmaDeclaration = (content: string) => {
const pragmaRegex = /#\s*pragma\s+[@]*version\s+([~<>!=^]+)\s*(\d+\.\d+\.\d+)/
const oldPragmaRegex = /#\s*pragma\s+[@]*version\s+([\^^]+)\s*(\d+\.\d+\.\d+)/
const oldPragmaDeclaration = ['# pragma version ^0.2.16', '# pragma version ^0.3.10', '#pragma version ^0.2.16', '#pragma version ^0.3.10']
const pragmaFound = content.match(pragmaRegex)
const wrongpragmaFound = content.includes('# pragma version ^0.3.10')
const evmVerFound = content.includes('#pragma evm-version cancun')
const oldPragmaFound = content.match(oldPragmaRegex)

const pragma = '# pragma version ~=0.4.0'
const evmVer = '# pragma evm-version cancun'

// if (evmVerFound === false) {
// content = `${evmVer}\n${content}`
// }
if (wrongpragmaFound === true) {
content = content.replace('# pragma version ^0.3.10', '')
if (oldPragmaFound) {
console.log('found old pragma')
// oldPragmaDeclaration.forEach(declaration => {
// content = content.replace(declaration, '# pragma version ~=0.4.0')
// })
}
if (!pragmaFound) {
content = `${pragma}\n${content}`
content = `${pragma}\n\n${content}`
}
return content
}

const fixContractContent = (content: string) => {
if (content.length === 0) return
return updatePragmaDeclaration(content)
}

/**
* Compile the a contract
* @param url The url of the compiler
Expand All @@ -177,7 +183,7 @@ export async function compile(url: string, contract: Contract): Promise<any> {
}

const cleanedUpContent = fixContractContent(contract.content)
console.log('cleanedUp', cleanedUpContent)
// console.log('cleanedUp', cleanedUpContent)

let contractName = contract['name']
const compilePackage = {
Expand All @@ -187,6 +193,7 @@ export async function compile(url: string, contract: Contract): Promise<any> {
}
}
console.log(compilePackage)

let response = await axios.post(`${url}compile`, compilePackage )

if (response.status === 404) {
Expand All @@ -197,9 +204,11 @@ export async function compile(url: string, contract: Contract): Promise<any> {
}

const compileCode = response.data
console.log('compileCode', compileCode)
contractName = null
response = null
let result: any
let intermediateError

const status = await (await axios.get(url + 'status/' + compileCode , {
method: 'Get'
Expand All @@ -210,12 +219,13 @@ export async function compile(url: string, contract: Contract): Promise<any> {
})).data

return result
} else if (status !== 'SUCCESS') {
} else if (status === 'FAILED') {
const intermediate = await(await axios.get(url + 'exceptions/' + compileCode , {
method: 'Get'
})).data
result = parseErrorString(intermediate)
console.log('Errors found', intermediate)
result = parseErrorString(intermediate)
intermediateError = intermediate
return result
}
await new Promise((resolve) => setTimeout(() => resolve({}), 3000))
Expand Down
6 changes: 3 additions & 3 deletions apps/vyper/src/app/utils/remix-client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ export class RemixClient extends PluginClient<any, CustomRemixApi> {

try {
// @ts-ignore
this.call('notification', 'toast', 'cloning Snekmate Vyper repository...')
this.call('notification', 'toast', 'cloning Snekmate Vyper repository...')
await this.call(
'dgitApi',
'clone',
{url: 'https://github.com/pcaversaccio/snekmate', token: null, branch: 'main', singleBranch: false, workspaceName: 'snekmate'},
{ url: 'https://github.com/vyperlang/vyper', token: null, branch: 'master', singleBranch: false, workspaceName: 'vyper' },
)

await this.call(
Expand All @@ -99,7 +99,7 @@ export class RemixClient extends PluginClient<any, CustomRemixApi> {
refresh: true,
}
)

this.call(
// @ts-ignore
'notification',
Expand Down

0 comments on commit cbb5dfe

Please sign in to comment.