From cbb5dfe01db53c0b417f745e1e9afd9d0c887b41 Mon Sep 17 00:00:00 2001 From: Joseph Izang Date: Thu, 12 Sep 2024 02:12:22 +0100 Subject: [PATCH] updates for v0.4.0 --- apps/vyper/src/app/utils/compiler.tsx | 40 ++++++++++++++--------- apps/vyper/src/app/utils/remix-client.tsx | 6 ++-- 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/apps/vyper/src/app/utils/compiler.tsx b/apps/vyper/src/app/utils/compiler.tsx index a1d4916f0e..1b196050c8 100644 --- a/apps/vyper/src/app/utils/compiler.tsx +++ b/apps/vyper/src/app/utils/compiler.tsx @@ -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() @@ -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 @@ -177,7 +183,7 @@ export async function compile(url: string, contract: Contract): Promise { } const cleanedUpContent = fixContractContent(contract.content) - console.log('cleanedUp', cleanedUpContent) + // console.log('cleanedUp', cleanedUpContent) let contractName = contract['name'] const compilePackage = { @@ -187,6 +193,7 @@ export async function compile(url: string, contract: Contract): Promise { } } console.log(compilePackage) + let response = await axios.post(`${url}compile`, compilePackage ) if (response.status === 404) { @@ -197,9 +204,11 @@ export async function compile(url: string, contract: Contract): Promise { } 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' @@ -210,12 +219,13 @@ export async function compile(url: string, contract: Contract): Promise { })).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)) diff --git a/apps/vyper/src/app/utils/remix-client.tsx b/apps/vyper/src/app/utils/remix-client.tsx index c2d57f64f6..2c534a8cc7 100644 --- a/apps/vyper/src/app/utils/remix-client.tsx +++ b/apps/vyper/src/app/utils/remix-client.tsx @@ -83,11 +83,11 @@ export class RemixClient extends PluginClient { 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( @@ -99,7 +99,7 @@ export class RemixClient extends PluginClient { refresh: true, } ) - + this.call( // @ts-ignore 'notification',