|
|
|
@ -4,11 +4,13 @@ import { update } from 'solc/abi' |
|
|
|
|
import * as webworkify from 'webworkify-webpack' |
|
|
|
|
import compilerInput from './compiler-input' |
|
|
|
|
import EventManager from '../lib/eventManager' |
|
|
|
|
import { default as txHelper } from './txHelper'; |
|
|
|
|
import { Source, SourceWithTarget, MessageFromWorker, CompilerState, CompilationResult,
|
|
|
|
|
import txHelper from './txHelper' |
|
|
|
|
import { |
|
|
|
|
Source, SourceWithTarget, MessageFromWorker, CompilerState, CompilationResult, |
|
|
|
|
visitContractsCallbackParam, visitContractsCallbackInterface, CompilationError, |
|
|
|
|
gatherImportsCallbackInterface, |
|
|
|
|
isFunctionDescription } from './types' |
|
|
|
|
isFunctionDescription |
|
|
|
|
} from './types' |
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
trigger compilationFinished, compilerLoaded, compilationStarted, compilationDuration |
|
|
|
@ -53,7 +55,7 @@ export class Compiler { |
|
|
|
|
* @param value value of key in CompilerState |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
set <K extends keyof CompilerState>(key: K, value: CompilerState[K]): void { |
|
|
|
|
set <K extends keyof CompilerState> (key: K, value: CompilerState[K]): void { |
|
|
|
|
this.state[key] = value |
|
|
|
|
if (key === 'runs') this.state['runs'] = parseInt(value) |
|
|
|
|
} |
|
|
|
@ -68,9 +70,8 @@ export class Compiler { |
|
|
|
|
this.gatherImports(files, missingInputs, (error, input) => { |
|
|
|
|
if (error) { |
|
|
|
|
this.state.lastCompilationResult = null |
|
|
|
|
this.event.trigger('compilationFinished', [false, {'error': { formattedMessage: error, severity: 'error' }}, files]) |
|
|
|
|
} else if(this.state.compileJSON && input) |
|
|
|
|
this.state.compileJSON(input) |
|
|
|
|
this.event.trigger('compilationFinished', [false, { error: { formattedMessage: error, severity: 'error' } }, files]) |
|
|
|
|
} else if (this.state.compileJSON && input) { this.state.compileJSON(input) } |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -111,9 +112,9 @@ export class Compiler { |
|
|
|
|
} |
|
|
|
|
let result: CompilationResult = {} |
|
|
|
|
try { |
|
|
|
|
if(source && source.sources) { |
|
|
|
|
const {optimize, runs, evmVersion, language} = this.state |
|
|
|
|
const input = compilerInput(source.sources, {optimize, runs, evmVersion, language}) |
|
|
|
|
if (source && source.sources) { |
|
|
|
|
const { optimize, runs, evmVersion, language } = this.state |
|
|
|
|
const input = compilerInput(source.sources, { optimize, runs, evmVersion, language }) |
|
|
|
|
result = JSON.parse(compiler.compile(input, { import: missingInputsCallback })) |
|
|
|
|
} |
|
|
|
|
} catch (exception) { |
|
|
|
@ -138,7 +139,7 @@ export class Compiler { |
|
|
|
|
const checkIfFatalError = (error: CompilationError) => { |
|
|
|
|
// Ignore warnings and the 'Deferred import' error as those are generated by us as a workaround
|
|
|
|
|
const isValidError = (error.message && error.message.includes('Deferred import')) ? false : error.severity !== 'warning' |
|
|
|
|
if(isValidError) noFatalErrors = false |
|
|
|
|
if (isValidError) noFatalErrors = false |
|
|
|
|
} |
|
|
|
|
if (data.error) checkIfFatalError(data.error) |
|
|
|
|
if (data.errors) data.errors.forEach((err) => checkIfFatalError(err)) |
|
|
|
@ -151,9 +152,8 @@ export class Compiler { |
|
|
|
|
this.internalCompile(source.sources, missingInputs) |
|
|
|
|
} else { |
|
|
|
|
data = this.updateInterface(data) |
|
|
|
|
if(source) |
|
|
|
|
{ |
|
|
|
|
source.target = this.state.target; |
|
|
|
|
if (source) { |
|
|
|
|
source.target = this.state.target |
|
|
|
|
this.state.lastCompilationResult = { |
|
|
|
|
data: data, |
|
|
|
|
source: source |
|
|
|
@ -183,9 +183,9 @@ export class Compiler { |
|
|
|
|
} |
|
|
|
|
let result: CompilationResult = {} |
|
|
|
|
try { |
|
|
|
|
if(source && source.sources) { |
|
|
|
|
const {optimize, runs, evmVersion, language} = this.state |
|
|
|
|
const input = compilerInput(source.sources, {optimize, runs, evmVersion, language}) |
|
|
|
|
if (source && source.sources) { |
|
|
|
|
const { optimize, runs, evmVersion, language } = this.state |
|
|
|
|
const input = compilerInput(source.sources, { optimize, runs, evmVersion, language }) |
|
|
|
|
result = JSON.parse(remoteCompiler.compile(input, { import: missingInputsCallback })) |
|
|
|
|
} |
|
|
|
|
} catch (exception) { |
|
|
|
@ -257,16 +257,16 @@ export class Compiler { |
|
|
|
|
const data: MessageFromWorker = msg.data |
|
|
|
|
switch (data.cmd) { |
|
|
|
|
case 'versionLoaded': |
|
|
|
|
if(data.data) this.onCompilerLoaded(data.data) |
|
|
|
|
if (data.data) this.onCompilerLoaded(data.data) |
|
|
|
|
break |
|
|
|
|
case 'compiled': |
|
|
|
|
{ |
|
|
|
|
let result: CompilationResult |
|
|
|
|
if(data.data && data.job !== undefined && data.job >= 0) { |
|
|
|
|
if (data.data && data.job !== undefined && data.job >= 0) { |
|
|
|
|
try { |
|
|
|
|
result = JSON.parse(data.data) |
|
|
|
|
} catch (exception) { |
|
|
|
|
result = { error : { formattedMessage: 'Invalid JSON output from the compiler: ' + exception }} |
|
|
|
|
result = { error: { formattedMessage: 'Invalid JSON output from the compiler: ' + exception } } |
|
|
|
|
} |
|
|
|
|
let sources: SourceWithTarget = {} |
|
|
|
|
if (data.job in jobs !== undefined) { |
|
|
|
@ -281,17 +281,17 @@ export class Compiler { |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
this.state.worker.addEventListener('error', (msg: Record <'data', MessageFromWorker>) => { |
|
|
|
|
this.onCompilationFinished({ error: { formattedMessage: 'Worker error: ' + msg.data }}) |
|
|
|
|
this.onCompilationFinished({ error: { formattedMessage: 'Worker error: ' + msg.data } }) |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
this.state.compileJSON = (source: SourceWithTarget) => { |
|
|
|
|
if(source && source.sources) { |
|
|
|
|
const {optimize, runs, evmVersion, language} = this.state |
|
|
|
|
jobs.push({sources: source}) |
|
|
|
|
if (source && source.sources) { |
|
|
|
|
const { optimize, runs, evmVersion, language } = this.state |
|
|
|
|
jobs.push({ sources: source }) |
|
|
|
|
this.state.worker.postMessage({ |
|
|
|
|
cmd: 'compile', |
|
|
|
|
job: jobs.length - 1, |
|
|
|
|
input: compilerInput(source.sources, {optimize, runs, evmVersion, language}) |
|
|
|
|
input: compilerInput(source.sources, { optimize, runs, evmVersion, language }) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -340,8 +340,7 @@ export class Compiler { |
|
|
|
|
} |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
if(cb) |
|
|
|
|
cb(null, { 'sources': files }) |
|
|
|
|
if (cb) { cb(null, { sources: files }) } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -366,12 +365,12 @@ export class Compiler { |
|
|
|
|
// yul compiler does not return any abi,
|
|
|
|
|
// we default to accept the fallback function (which expect raw data as argument).
|
|
|
|
|
contract.object.abi.push({ |
|
|
|
|
'payable': true, |
|
|
|
|
'stateMutability': 'payable', |
|
|
|
|
'type': 'fallback' |
|
|
|
|
payable: true, |
|
|
|
|
stateMutability: 'payable', |
|
|
|
|
type: 'fallback' |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
if(data && data.contracts && this.state.currentVersion) { |
|
|
|
|
if (data && data.contracts && this.state.currentVersion) { |
|
|
|
|
const version = this.truncateVersion(this.state.currentVersion) |
|
|
|
|
data.contracts[contract.file][contract.name].abi = update(version, contract.object.abi) |
|
|
|
|
// if "constant" , payable must not be true and stateMutability must be view.
|
|
|
|
@ -379,7 +378,7 @@ export class Compiler { |
|
|
|
|
for (const item of data.contracts[contract.file][contract.name].abi) { |
|
|
|
|
if (isFunctionDescription(item) && item.constant) { |
|
|
|
|
item.payable = false |
|
|
|
|
item.stateMutability = 'view'; |
|
|
|
|
item.stateMutability = 'view' |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -457,4 +456,3 @@ export class Compiler { |
|
|
|
|
return null |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|