From 18dde6ec1bc7caa0e6fe2735e2f33388949ae37e Mon Sep 17 00:00:00 2001 From: LianaHus Date: Tue, 19 May 2020 23:00:32 +0200 Subject: [PATCH] adding pathToURL --- src/app/compiler/compiler-helpers.js | 4 +- ...compiler-sourceVerifier-fetchAndCompile.js | 2 - src/app/compiler/compiler-utils.js | 19 +++++-- src/app/tabs/compileTab/compilerContainer.js | 51 ++++++++++++++++--- src/app/tabs/test-tab.js | 6 +-- src/lib/helper.js | 1 - 6 files changed, 63 insertions(+), 20 deletions(-) diff --git a/src/app/compiler/compiler-helpers.js b/src/app/compiler/compiler-helpers.js index a20ffa13b1..820e5c298f 100644 --- a/src/app/compiler/compiler-helpers.js +++ b/src/app/compiler/compiler-helpers.js @@ -1,5 +1,5 @@ 'use strict' -import { canUseWorker } from './compiler-utils' +import { canUseWorker, urlFromVersion } from './compiler-utils' import { Compiler } from 'remix-solidity' import CompilerAbstract from './compiler-abstract' @@ -9,7 +9,7 @@ export const compile = async (compilationTargets, settings) => { const compiler = new Compiler(() => {}) compiler.set('evmVersion', settings.evmVersion) compiler.set('optimize', settings.optimize) - compiler.loadVersion(canUseWorker(settings.version), settings.compilerUrl) + compiler.loadVersion(canUseWorker(settings.version), urlFromVersion(settings.version)) compiler.event.register('compilationFinished', (success, compilationData, source) => { if (!success) return reject(compilationData) resolve(new CompilerAbstract(settings.version, compilationData, source)) diff --git a/src/app/compiler/compiler-sourceVerifier-fetchAndCompile.js b/src/app/compiler/compiler-sourceVerifier-fetchAndCompile.js index 04956b5ac7..8da3dd9bb1 100644 --- a/src/app/compiler/compiler-sourceVerifier-fetchAndCompile.js +++ b/src/app/compiler/compiler-sourceVerifier-fetchAndCompile.js @@ -1,7 +1,6 @@ const ethutil = require('ethereumjs-util') import * as packageJson from '../../../package.json' import { Plugin } from '@remixproject/engine' -import { urlFromVersion } from './compiler-utils' import { compile } from './compiler-helpers' import globalRegistry from '../../global/registry' @@ -109,7 +108,6 @@ export default class FetchAndCompile extends Plugin { languageName: data.metadata.language, evmVersion: data.metadata.settings.evmVersion, optimize: data.metadata.settings.optimizer.enabled, - compilerUrl: urlFromVersion(data.metadata.compiler.version) } try { setTimeout(_ => this.emit('compiling', settings), 0) diff --git a/src/app/compiler/compiler-utils.js b/src/app/compiler/compiler-utils.js index 25e6425f10..a36e25a83c 100644 --- a/src/app/compiler/compiler-utils.js +++ b/src/app/compiler/compiler-utils.js @@ -1,11 +1,15 @@ -// const semver = require('semver') + const semver = require('semver') /* global Worker */ -export const baseUrl = 'https://solc-bin.ethereum.org/wasm' +export const baseURLBin = 'https://solc-bin.ethereum.org/bin' +export const baseURLWasm = 'https://solc-bin.ethereum.org/wasm' + +export const pathToURL = [] export function urlFromVersion (version) { - return `${baseUrl}/soljson-v${version}.js` + return `${pathToURL[version]}/${version}` } + /** * Checks if the worker can be used to load a compiler. * checks a compiler whitelist, browser support and OS. @@ -30,7 +34,14 @@ export function canUseWorker (selectedVersion) { default : isFromWhiteList = true } */ - return browserSupportWorker()// && (!isChrome || (isChrome && isFromWhiteList)) + const version = semver.coerce(selectedVersion) + const isNightly = selectedVersion.includes('nightly') + return browserSupportWorker() && + ( + semver.gt(version, '0.6.3') || + semver.gt(version, '0.3.5') && !isNightly + ) + // && (!isChrome || (isChrome && isFromWhiteList)) } function browserSupportWorker () { diff --git a/src/app/tabs/compileTab/compilerContainer.js b/src/app/tabs/compileTab/compilerContainer.js index 960f5c8d16..e7ef28696d 100644 --- a/src/app/tabs/compileTab/compilerContainer.js +++ b/src/app/tabs/compileTab/compilerContainer.js @@ -6,7 +6,7 @@ const addTooltip = require('../../ui/tooltip') const semver = require('semver') const modalDialogCustom = require('../../ui/modal-dialog-custom') const css = require('../styles/compile-tab-styles') -import { canUseWorker, baseUrl } from '../../compiler/compiler-utils' +import { canUseWorker, baseURLBin, baseURLWasm, urlFromVersion, pathToURL } from '../../compiler/compiler-utils' class CompilerContainer { @@ -25,7 +25,8 @@ class CompilerContainer { allversions: null, selectedVersion: null, defaultVersion: 'soljson-v0.6.6+commit.6c089d02.js', // this default version is defined: in makeMockCompiler (for browser test) and in package.json (downloadsolc_root) for the builtin compiler - baseurl: baseUrl + baseURLWasm: baseURLWasm, + baseURLBin: baseURLBin } } @@ -383,7 +384,7 @@ class CompilerContainer { if (this.data.selectedVersion.indexOf('soljson') !== 0 || helper.checkSpecialChars(this.data.selectedVersion)) { return console.log('loading ' + this.data.selectedVersion + ' not allowed') } - url = `${this.data.baseurl}/${this.data.selectedVersion}` + url = `${urlFromVersion(this.data.selectedVersion)}` } // Workers cannot load js on "file:"-URLs and we get a @@ -413,25 +414,59 @@ class CompilerContainer { if (this._view.version) this._view.version.innerText = text } + // fetching both normal and wasm builds and creating an array [version, baseUrl] fetchAllVersion (callback) { - minixhr(`${this.data.baseurl}/list.json`, (json, event) => { + let allVersions, selectedVersion, allVersionsWasm, urls + // fetch normal builds + minixhr(`${this.data.baseURLBin}/list.json`, (json, event) => { // @TODO: optimise and cache results to improve app loading times #2461 - var allversions, selectedVersion if (event.type !== 'error') { try { const data = JSON.parse(json) - allversions = data.builds.slice().reverse() + allVersions = data.builds.slice().reverse() selectedVersion = this.data.defaultVersion if (this.queryParams.get().version) selectedVersion = this.queryParams.get().version + // no fetching wasm builds + minixhr(`${this.data.baseURLWasm}/list.json`, (json, event) => { + // @TODO: optimise and cache results to improve app loading times #2461 + if (event.type !== 'error') { + try { + const data = JSON.parse(json) + allVersionsWasm = data.builds.slice().reverse() + //selectedVersion = this.data.defaultVersion + if (this.queryParams.get().version) selectedVersion = this.queryParams.get().version + // rewriting all versions in allVersions which exist in allVersionsWasm + if (allVersionsWasm && allVersions) + allVersions.forEach((compiler, index) => { + const rewritten = allVersionsWasm.findIndex(oldCompiler => { return oldCompiler.longVersion === compiler.longVersion }) + if (-1 !== rewritten) { + allVersions[index] = allVersionsWasm[rewritten] + pathToURL[compiler.path] = baseURLWasm + } else { + pathToURL[compiler.path] = baseURLBin + } + }) + callback(allVersions, selectedVersion) + } catch (e) { + addTooltip('Cannot load compiler version list. It might have been blocked by an advertisement blocker. Please try deactivating any of them from this page and reload.') + } + } else { + allVersionsWasm = [{ path: 'builtin', longVersion: 'latest local version' }] + selectedVersion = 'builtin' + } + //callback(allVersions, selectedVersion) + }) } catch (e) { addTooltip('Cannot load compiler version list. It might have been blocked by an advertisement blocker. Please try deactivating any of them from this page and reload.') } } else { - allversions = [{ path: 'builtin', longVersion: 'latest local version' }] + allVersions = [{ path: 'builtin', longVersion: 'latest local version' }] selectedVersion = 'builtin' } - callback(allversions, selectedVersion) + //callback(allVersions, selectedVersion) }) + + } scheduleCompilation () { diff --git a/src/app/tabs/test-tab.js b/src/app/tabs/test-tab.js index 2dfb270a9f..abc9986a1d 100644 --- a/src/app/tabs/test-tab.js +++ b/src/app/tabs/test-tab.js @@ -4,7 +4,7 @@ var tooltip = require('../ui/tooltip') var css = require('./styles/test-tab-styles') var remixTests = require('remix-tests') import { ViewPlugin } from '@remixproject/engine' -import { canUseWorker, baseUrl } from '../compiler/compiler-utils' +import { canUseWorker, urlFromVersion } from '../compiler/compiler-utils' const TestTabLogic = require('./testTab/testTab') @@ -301,7 +301,7 @@ module.exports = class TestTab extends ViewPlugin { let runningTest = {} runningTest[path] = { content } const {currentVersion, evmVersion, optimize} = this.compileTab.getCurrentCompilerConfig() - const currentCompilerUrl = baseUrl + '/' + currentVersion + const currentCompilerUrl = urlFromVersion(currentVersion) const compilerConfig = { currentCompilerUrl, evmVersion, @@ -327,7 +327,7 @@ module.exports = class TestTab extends ViewPlugin { const runningTest = {} runningTest[testFilePath] = { content } const {currentVersion, evmVersion, optimize} = this.compileTab.getCurrentCompilerConfig() - const currentCompilerUrl = baseUrl + '/' + currentVersion + const currentCompilerUrl = urlFromVersion(currentVersion) const compilerConfig = { currentCompilerUrl, evmVersion, diff --git a/src/lib/helper.js b/src/lib/helper.js index cda3bfe519..15f692fcc1 100644 --- a/src/lib/helper.js +++ b/src/lib/helper.js @@ -84,4 +84,3 @@ function find (args, query) { }) return isMatch } -