@@ -48,6 +48,7 @@ export function normalizeContractPath(contractPath: string): string[] {
48
48
function parseErrorString ( errorString ) {
49
49
// Split the string into lines
50
50
console . log ( errorString )
51
+ return
51
52
let lines = errorString . trim ( ) . split ( '\n' )
52
53
// Extract the line number and message
53
54
let message = errorString . trim ( )
@@ -141,27 +142,32 @@ const compileReturnType = (output, contract) => {
141
142
return result
142
143
}
143
144
144
- const fixContractContent = ( content : string ) => {
145
- const pragmaRegex = / # \s * p r a g m a \s + [ @ ] * v e r s i o n \s + ( [ \^ ~ < > ! = ^ ] + ) \s * ( \d + \. \d + \. \d + ) /
146
- if ( content . length === 0 ) return
145
+ const updatePragmaDeclaration = ( content : string ) => {
146
+ const pragmaRegex = / # \s * p r a g m a \s + [ @ ] * v e r s i o n \s + ( [ ~ < > ! = ^ ] + ) \s * ( \d + \. \d + \. \d + ) /
147
+ const oldPragmaRegex = / # \s * p r a g m a \s + [ @ ] * v e r s i o n \s + ( [ \^ ^ ] + ) \s * ( \d + \. \d + \. \d + ) /
148
+ const oldPragmaDeclaration = [ '# pragma version ^0.2.16' , '# pragma version ^0.3.10' , '#pragma version ^0.2.16' , '#pragma version ^0.3.10' ]
147
149
const pragmaFound = content . match ( pragmaRegex )
148
- const wrongpragmaFound = content . includes ( '# pragma version ^0.3.10' )
149
- const evmVerFound = content . includes ( '#pragma evm-version cancun' )
150
+ const oldPragmaFound = content . match ( oldPragmaRegex )
151
+
150
152
const pragma = '# pragma version ~=0.4.0'
151
- const evmVer = '# pragma evm-version cancun'
152
153
153
- // if (evmVerFound === false ) {
154
- // content = `${evmVer}\n${content}`
155
- // }
156
- if ( wrongpragmaFound === true ) {
157
- content = content . replace ( '# pragma version ^0.3.10' , '' )
154
+ if ( oldPragmaFound ) {
155
+ console . log ( 'found old pragma' )
156
+ // oldPragmaDeclaration.forEach(declaration => {
157
+ // content = content.replace(declaration, '# pragma version ~=0.4.0')
158
+ // } )
158
159
}
159
160
if ( ! pragmaFound ) {
160
- content = `${ pragma } \n${ content } `
161
+ content = `${ pragma } \n\n ${ content } `
161
162
}
162
163
return content
163
164
}
164
165
166
+ const fixContractContent = ( content : string ) => {
167
+ if ( content . length === 0 ) return
168
+ return updatePragmaDeclaration ( content )
169
+ }
170
+
165
171
/**
166
172
* Compile the a contract
167
173
* @param url The url of the compiler
@@ -177,7 +183,7 @@ export async function compile(url: string, contract: Contract): Promise<any> {
177
183
}
178
184
179
185
const cleanedUpContent = fixContractContent ( contract . content )
180
- console . log ( 'cleanedUp' , cleanedUpContent )
186
+ // console.log('cleanedUp', cleanedUpContent)
181
187
182
188
let contractName = contract [ 'name' ]
183
189
const compilePackage = {
@@ -187,6 +193,7 @@ export async function compile(url: string, contract: Contract): Promise<any> {
187
193
}
188
194
}
189
195
console . log ( compilePackage )
196
+
190
197
let response = await axios . post ( `${ url } compile` , compilePackage )
191
198
192
199
if ( response . status === 404 ) {
@@ -197,9 +204,11 @@ export async function compile(url: string, contract: Contract): Promise<any> {
197
204
}
198
205
199
206
const compileCode = response . data
207
+ console . log ( 'compileCode' , compileCode )
200
208
contractName = null
201
209
response = null
202
210
let result : any
211
+ let intermediateError
203
212
204
213
const status = await ( await axios . get ( url + 'status/' + compileCode , {
205
214
method : 'Get'
@@ -210,12 +219,13 @@ export async function compile(url: string, contract: Contract): Promise<any> {
210
219
} ) ) . data
211
220
212
221
return result
213
- } else if ( status !== 'SUCCESS ') {
222
+ } else if ( status === 'FAILED ') {
214
223
const intermediate = await ( await axios . get ( url + 'exceptions/' + compileCode , {
215
224
method : 'Get'
216
225
} ) ) . data
217
- result = parseErrorString ( intermediate )
218
226
console . log ( 'Errors found' , intermediate )
227
+ result = parseErrorString ( intermediate )
228
+ intermediateError = intermediate
219
229
return result
220
230
}
221
231
await new Promise ( ( resolve ) => setTimeout ( ( ) => resolve ( { } ) , 3000 ) )
0 commit comments