From a850ec26dfcae7083da57c15479daddc4132c290 Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Fri, 12 Aug 2022 13:52:09 +0530 Subject: [PATCH 1/7] return license on compiler loading --- apps/solidity-compiler/src/app/compiler-api.ts | 4 ++-- .../remix-solidity/src/compiler/compiler-worker.ts | 3 ++- libs/remix-solidity/src/compiler/compiler.ts | 14 +++++++++----- libs/remix-solidity/src/compiler/types.ts | 2 ++ libs/remix-tests/src/compiler.ts | 4 ++-- .../solidity-compiler/src/lib/actions/compiler.ts | 4 ++-- .../src/lib/compiler-container.tsx | 5 +++-- .../src/lib/solidity-unit-testing.tsx | 2 +- .../src/lib/remix-ui-static-analyser.tsx | 2 +- 9 files changed, 24 insertions(+), 16 deletions(-) diff --git a/apps/solidity-compiler/src/app/compiler-api.ts b/apps/solidity-compiler/src/app/compiler-api.ts index 74eec1d57f..f7eb97442c 100644 --- a/apps/solidity-compiler/src/app/compiler-api.ts +++ b/apps/solidity-compiler/src/app/compiler-api.ts @@ -222,10 +222,10 @@ export const CompilerApiMixin = (Base) => class extends Base { } this.compiler.event.register('loadingCompiler', this.data.eventHandlers.onLoadingCompiler) - this.data.eventHandlers.onCompilerLoaded = (version) => { + this.data.eventHandlers.onCompilerLoaded = (version, license) => { this.data.loading = false this.statusChanged({ key: 'none' }) - this.emit('compilerLoaded', version) + this.emit('compilerLoaded', version, license) } this.compiler.event.register('compilerLoaded', this.data.eventHandlers.onCompilerLoaded) diff --git a/libs/remix-solidity/src/compiler/compiler-worker.ts b/libs/remix-solidity/src/compiler/compiler-worker.ts index 662a03ec06..313d1b0119 100644 --- a/libs/remix-solidity/src/compiler/compiler-worker.ts +++ b/libs/remix-solidity/src/compiler/compiler-worker.ts @@ -33,7 +33,8 @@ export default function (self) { // eslint-disable-line @typescript-eslint/expli } self.postMessage({ cmd: 'versionLoaded', - data: compiler.version() + data: compiler.version(), + license: compiler.license() }) break } diff --git a/libs/remix-solidity/src/compiler/compiler.ts b/libs/remix-solidity/src/compiler/compiler.ts index f728748a9e..20aa8880a2 100644 --- a/libs/remix-solidity/src/compiler/compiler.ts +++ b/libs/remix-solidity/src/compiler/compiler.ts @@ -25,6 +25,7 @@ export class Compiler { compileJSON: null, worker: null, currentVersion: null, + compilerLicense: null, optimize: false, runs: 200, evmVersion: null, @@ -94,9 +95,10 @@ export class Compiler { * @param version compiler version */ - onCompilerLoaded (version: string): void { + onCompilerLoaded (version: string, license: string): void { this.state.currentVersion = version - this.event.trigger('compilerLoaded', [version]) + this.state.compilerLicense = license + this.event.trigger('compilerLoaded', [version, license]) } /** @@ -131,7 +133,7 @@ export class Compiler { } this.onCompilationFinished(result, missingInputs, source, input, this.state.currentVersion) } - this.onCompilerLoaded(compiler.version()) + this.onCompilerLoaded(compiler.version(), compiler.license()) } } @@ -184,6 +186,7 @@ export class Compiler { if (err) { console.error('Error in loading remote solc compiler: ', err) } else { + let license this.state.compileJSON = (source: SourceWithTarget) => { const missingInputs: string[] = [] const missingInputsCallback = (path: string) => { @@ -203,13 +206,14 @@ export class Compiler { } result = JSON.parse(remoteCompiler.compile(input, { import: missingInputsCallback })) + license = remoteCompiler.license() } } catch (exception) { result = { error: { formattedMessage: 'Uncaught JavaScript exception:\n' + exception, severity: 'error', mode: 'panic' } } } this.onCompilationFinished(result, missingInputs, source, input, version) } - this.onCompilerLoaded(version) + this.onCompilerLoaded(version, license) } }) } @@ -273,7 +277,7 @@ export class Compiler { const data: MessageFromWorker = msg.data switch (data.cmd) { case 'versionLoaded': - if (data.data) this.onCompilerLoaded(data.data) + if (data.data && data.license) this.onCompilerLoaded(data.data, data.license) break case 'compiled': { diff --git a/libs/remix-solidity/src/compiler/types.ts b/libs/remix-solidity/src/compiler/types.ts index c4e48dd2ff..9f3cfb4b54 100644 --- a/libs/remix-solidity/src/compiler/types.ts +++ b/libs/remix-solidity/src/compiler/types.ts @@ -158,6 +158,7 @@ export interface CompilerState { compileJSON: ((input: SourceWithTarget) => void) | null, worker: any, currentVersion: string| null| undefined, + compilerLicense: string| null optimize: boolean, runs: number evmVersion: EVMVersion| null, @@ -186,6 +187,7 @@ export interface MessageToWorker { export interface MessageFromWorker { cmd: string, + license?: string, job?: number, missingInputs?: string[], input?: any, diff --git a/libs/remix-tests/src/compiler.ts b/libs/remix-tests/src/compiler.ts index b399f7376e..7fedf9c830 100644 --- a/libs/remix-tests/src/compiler.ts +++ b/libs/remix-tests/src/compiler.ts @@ -134,7 +134,7 @@ export function compileFileOrFiles (filename: string, isDirectory: boolean, opts if (runs) compiler.set('runs', runs) if (currentCompilerUrl) { compiler.loadRemoteVersion(currentCompilerUrl) - compiler.event.register('compilerLoaded', this, function (version) { + compiler.event.register('compilerLoaded', this, function (version, license) { next() }) } else { @@ -198,7 +198,7 @@ export function compileContractSources (sources: SrcIfc, newCompConfig: any, imp compiler.set('runs', runs) compiler.loadVersion(usingWorker, currentCompilerUrl) // @ts-ignore - compiler.event.register('compilerLoaded', this, (version) => { + compiler.event.register('compilerLoaded', this, (version, license) => { next() }) } else { diff --git a/libs/remix-ui/solidity-compiler/src/lib/actions/compiler.ts b/libs/remix-ui/solidity-compiler/src/lib/actions/compiler.ts index c67aee6ddb..b1c0b686de 100644 --- a/libs/remix-ui/solidity-compiler/src/lib/actions/compiler.ts +++ b/libs/remix-ui/solidity-compiler/src/lib/actions/compiler.ts @@ -46,8 +46,8 @@ export const listenToEvents = (compileTabLogic: CompileTabLogic, api) => (dispat dispatch(setCompilerMode('loadingCompiler')) }) - compileTabLogic.compiler.event.register('compilerLoaded', () => { - dispatch(setCompilerMode('compilerLoaded')) + compileTabLogic.compiler.event.register('compilerLoaded', (version, license) => { + dispatch(setCompilerMode('compilerLoaded', version, license)) }) compileTabLogic.compiler.event.register('compilationFinished', (success, data, source, input, version) => { diff --git a/libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx b/libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx index 069377d045..001e446f54 100644 --- a/libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx +++ b/libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx @@ -185,7 +185,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => { loadingCompiler() break case 'compilerLoaded': - compilerLoaded() + compilerLoaded(compilerContainer.compiler.args[1]) break case 'compilationFinished': compilationFinished() @@ -436,7 +436,8 @@ export const CompilerContainer = (props: CompilerContainerProps) => { setDisableCompileButton(true) } - const compilerLoaded = () => { + const compilerLoaded = (license) => { + console.log('inside compilerLoaded----->', license) if (!compileIcon.current) return compileIcon.current.setAttribute('title', '') compileIcon.current.classList.remove('remixui_spinningIcon') diff --git a/libs/remix-ui/solidity-unit-testing/src/lib/solidity-unit-testing.tsx b/libs/remix-ui/solidity-unit-testing/src/lib/solidity-unit-testing.tsx index e580a9448b..947eae4dac 100644 --- a/libs/remix-ui/solidity-unit-testing/src/lib/solidity-unit-testing.tsx +++ b/libs/remix-ui/solidity-unit-testing/src/lib/solidity-unit-testing.tsx @@ -164,7 +164,7 @@ export const SolidityUnitTesting = (props: Record) => { // eslint-d testTab.fileManager.events.on('currentFileChanged', async (file: string) => { await updateForNewCurrent(file) }) - testTab.on('solidity', 'compilerLoaded', async (version: string) => { + testTab.on('solidity', 'compilerLoaded', async (version: string, license: string) => { const { currentVersion } = testTab.compileTab.getCurrentCompilerConfig() if (!semver.gt(truncateVersion(currentVersion), '0.4.12')) { diff --git a/libs/remix-ui/static-analyser/src/lib/remix-ui-static-analyser.tsx b/libs/remix-ui/static-analyser/src/lib/remix-ui-static-analyser.tsx index 5e143dec1f..2afc377d15 100644 --- a/libs/remix-ui/static-analyser/src/lib/remix-ui-static-analyser.tsx +++ b/libs/remix-ui/static-analyser/src/lib/remix-ui-static-analyser.tsx @@ -141,7 +141,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { } }) - props.analysisModule.on('solidity', 'compilerLoaded', async (version: string) => { + props.analysisModule.on('solidity', 'compilerLoaded', async (version: string, license: string) => { setDisableForRun(version) }) return () => { } From 69915abd915e44fe8ca5a9ae4cf98efa3cc89d83 Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Fri, 12 Aug 2022 14:16:58 +0530 Subject: [PATCH 2/7] linting fix --- .../static-analyser/src/lib/remix-ui-static-analyser.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/remix-ui/static-analyser/src/lib/remix-ui-static-analyser.tsx b/libs/remix-ui/static-analyser/src/lib/remix-ui-static-analyser.tsx index 2afc377d15..84aab5e5d0 100644 --- a/libs/remix-ui/static-analyser/src/lib/remix-ui-static-analyser.tsx +++ b/libs/remix-ui/static-analyser/src/lib/remix-ui-static-analyser.tsx @@ -140,7 +140,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { setSlitherEnabled(false) } }) - + // eslint-disable-next-line @typescript-eslint/no-unused-vars props.analysisModule.on('solidity', 'compilerLoaded', async (version: string, license: string) => { setDisableForRun(version) }) From 007b1f590d625572ab6af698c45057e05429c833 Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Fri, 12 Aug 2022 14:38:39 +0530 Subject: [PATCH 3/7] show license --- .../solidity-compiler/src/lib/compiler-container.tsx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx b/libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx index 001e446f54..89e3223c68 100644 --- a/libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx +++ b/libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx @@ -48,6 +48,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => { timeout: 300, allversions: [], customVersions: [], + compilerLicense: null, selectedVersion: null, defaultVersion: 'soljson-v0.8.7+commit.e28d00a7.js', // this default version is defined: in makeMockCompiler (for browser test) runs: '', @@ -437,10 +438,12 @@ export const CompilerContainer = (props: CompilerContainerProps) => { } const compilerLoaded = (license) => { - console.log('inside compilerLoaded----->', license) if (!compileIcon.current) return compileIcon.current.setAttribute('title', '') compileIcon.current.classList.remove('remixui_spinningIcon') + setState(prevState => { + return { ...prevState, compilerLicense: license ? license : 'could not retreive license' } + }) if (state.autoCompile) compile() const isDisabled = !compiledFileName || (compiledFileName && !isSolFileSelected(compiledFileName)) @@ -555,6 +558,10 @@ export const CompilerContainer = (props: CompilerContainerProps) => { modal('Add a custom compiler', promptMessage('URL'), 'OK', addCustomCompiler, 'Cancel', () => {}) } + const showCompilerLicense = () => { + modal('Compiler License', state.compilerLicense ? state.compilerLicense : 'License can be seen once compiler is loaded', 'OK', () => {}) + } + const promptMessage = (message) => { return ( <> @@ -705,6 +712,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => { handleLoadVersion(e.target.value) } className="custom-select" id="versionSelector" disabled={state.allversions.length <= 0}> { state.allversions.length <= 0 && } { state.allversions.length <= 0 && } From d7f3f926975779c31e10183acc351afec39b02be Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Wed, 17 Aug 2022 14:37:12 +0530 Subject: [PATCH 7/7] do not show license while compiler is loading --- .../src/lib/compiler-container.tsx | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx b/libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx index 8d63721e32..857a86e73c 100644 --- a/libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx +++ b/libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx @@ -49,7 +49,6 @@ export const CompilerContainer = (props: CompilerContainerProps) => { allversions: [], customVersions: [], compilerLicense: null, - loadedVersion: null, selectedVersion: null, defaultVersion: 'soljson-v0.8.7+commit.e28d00a7.js', // this default version is defined: in makeMockCompiler (for browser test) runs: '', @@ -187,7 +186,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => { loadingCompiler() break case 'compilerLoaded': - compilerLoaded(compilerContainer.compiler.args[0], compilerContainer.compiler.args[1]) + compilerLoaded(compilerContainer.compiler.args[1]) break case 'compilationFinished': compilationFinished() @@ -434,16 +433,19 @@ export const CompilerContainer = (props: CompilerContainerProps) => { if (!compileIcon.current) return compileIcon.current.setAttribute('title', 'compiler is loading, please wait a few moments.') compileIcon.current.classList.add('remixui_spinningIcon') + setState(prevState => { + return { ...prevState, compilerLicense: 'Compiler is loading. License will be displayed once compiler is loaded'} + }) _updateLanguageSelector() setDisableCompileButton(true) } - const compilerLoaded = (version, license) => { + const compilerLoaded = (license) => { if (!compileIcon.current) return compileIcon.current.setAttribute('title', '') compileIcon.current.classList.remove('remixui_spinningIcon') setState(prevState => { - return { ...prevState, compilerLicense: license ? license : 'could not retreive license', loadedVersion: version } + return { ...prevState, compilerLicense: license ? license : 'Could not retreive license for selected compiler version' } }) if (state.autoCompile) compile() const isDisabled = !compiledFileName || (compiledFileName && !isSolFileSelected(compiledFileName)) @@ -560,14 +562,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => { } const showCompilerLicense = () => { - let licenseText - if (state.loadedVersion) { - const tmp: RegExpExecArray | null = /(\d+.\d+.\d+)/.exec(state.loadedVersion) - const version = tmp ? tmp[0] : state.loadedVersion - licenseText = `---- Compiler license for loaded version ${version} ---- \n\n` + state.compilerLicense - } else - licenseText = 'License can be seen once compiler is loaded' - modal('Compiler License', licenseText, 'OK', () => {}) + modal('Compiler License', state.compilerLicense ? state.compilerLicense : 'License not available', 'OK', () => {}) } const promptMessage = (message) => {