diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2019-02-07 19:58:46 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2019-02-07 19:58:46 +0800 |
commit | 64d6dae672e71f6c81b472a58cb9c443607262c9 (patch) | |
tree | 18613efe6d28ddc0f2dd95535d93043108902e2f | |
parent | c20285dd3655a9685b52205229e675c797cd4418 (diff) | |
download | dexon-0x-contracts-64d6dae672e71f6c81b472a58cb9c443607262c9.tar.gz dexon-0x-contracts-64d6dae672e71f6c81b472a58cb9c443607262c9.tar.zst dexon-0x-contracts-64d6dae672e71f6c81b472a58cb9c443607262c9.zip |
Remove the bin_paths and fetch the solidity release list from github repo
-rw-r--r-- | packages/sol-compiler/CHANGELOG.json | 4 | ||||
-rw-r--r-- | packages/sol-compiler/src/compiler.ts | 7 | ||||
-rw-r--r-- | packages/sol-compiler/src/solc/bin_paths.ts | 52 | ||||
-rw-r--r-- | packages/sol-compiler/src/utils/compiler.ts | 21 | ||||
-rw-r--r-- | packages/sol-compiler/src/utils/types.ts | 4 |
5 files changed, 29 insertions, 59 deletions
diff --git a/packages/sol-compiler/CHANGELOG.json b/packages/sol-compiler/CHANGELOG.json index a0d2250aa..977699ad6 100644 --- a/packages/sol-compiler/CHANGELOG.json +++ b/packages/sol-compiler/CHANGELOG.json @@ -9,6 +9,10 @@ { "note": "Fix a bug when opts could not be undefined", "pr": "TODO" + }, + { + "note": "Remove `bin_paths` and fetch the list of soliidty compilers from github", + "pr": "TODO" } ] }, diff --git a/packages/sol-compiler/src/compiler.ts b/packages/sol-compiler/src/compiler.ts index 686ba4f82..45608eb55 100644 --- a/packages/sol-compiler/src/compiler.ts +++ b/packages/sol-compiler/src/compiler.ts @@ -21,7 +21,6 @@ import * as semver from 'semver'; import solc = require('solc'); import { compilerOptionsSchema } from './schemas/compiler_options_schema'; -import { binPaths } from './solc/bin_paths'; import { addHexPrefixToContractBytecode, compileDockerAsync, @@ -29,6 +28,7 @@ import { createDirIfDoesNotExistAsync, getContractArtifactIfExistsAsync, getDependencyNameToPackagePath, + getSolcJSReleasesAsync, getSourcesWithDependencies, getSourceTreeHash, makeContractPathsRelative, @@ -211,6 +211,7 @@ export class Compiler { // map contract paths to data about them for later verification and persistence const contractPathToData: ContractPathToData = {}; + const solcJSReleases = await getSolcJSReleasesAsync(); const resolvedContractSources = []; for (const contractName of contractNames) { const spyResolver = new SpyResolver(this._resolver); @@ -226,7 +227,7 @@ export class Compiler { } contractPathToData[contractSource.path] = contractData; const solcVersion = _.isUndefined(this._solcVersionIfExists) - ? semver.maxSatisfying(_.keys(binPaths), parseSolidityVersionRange(contractSource.source)) + ? semver.maxSatisfying(_.keys(solcJSReleases), parseSolidityVersionRange(contractSource.source)) : this._solcVersionIfExists; const isFirstContractWithThisVersion = _.isUndefined(versionToInputs[solcVersion]); if (isFirstContractWithThisVersion) { @@ -272,7 +273,7 @@ export class Compiler { fullSolcVersion = versionCommandOutputParts[versionCommandOutputParts.length - 1].trim(); compilerOutput = await compileDockerAsync(solcVersion, input.standardInput); } else { - fullSolcVersion = binPaths[solcVersion]; + fullSolcVersion = solcJSReleases[solcVersion]; compilerOutput = await compileSolcJSAsync(solcVersion, input.standardInput); } if (!_.isUndefined(compilerOutput.errors)) { diff --git a/packages/sol-compiler/src/solc/bin_paths.ts b/packages/sol-compiler/src/solc/bin_paths.ts deleted file mode 100644 index b653c0926..000000000 --- a/packages/sol-compiler/src/solc/bin_paths.ts +++ /dev/null @@ -1,52 +0,0 @@ -export interface BinaryPaths { - [key: string]: string; -} - -export const binPaths: BinaryPaths = { - '0.5.2': 'soljson-v0.5.2+commit.1df8f40c.js', - '0.5.1': 'soljson-v0.5.1+commit.c8a2cb62.js', - '0.5.0': 'soljson-v0.5.0+commit.1d4f565a.js', - '0.4.25': 'soljson-v0.4.25+commit.59dbf8f1.js', - '0.4.24': 'soljson-v0.4.24+commit.e67f0147.js', - '0.4.23': 'soljson-v0.4.23+commit.124ca40d.js', - '0.4.22': 'soljson-v0.4.22+commit.4cb486ee.js', - '0.4.21': 'soljson-v0.4.21+commit.dfe3193c.js', - '0.4.20': 'soljson-v0.4.20+commit.3155dd80.js', - '0.4.19': 'soljson-v0.4.19+commit.c4cbbb05.js', - '0.4.18': 'soljson-v0.4.18+commit.9cf6e910.js', - '0.4.17': 'soljson-v0.4.17+commit.bdeb9e52.js', - '0.4.16': 'soljson-v0.4.16+commit.d7661dd9.js', - '0.4.15': 'soljson-v0.4.15+commit.bbb8e64f.js', - '0.4.14': 'soljson-v0.4.14+commit.c2215d46.js', - '0.4.13': 'soljson-v0.4.13+commit.fb4cb1a.js', - '0.4.12': 'soljson-v0.4.12+commit.194ff033.js', - '0.4.11': 'soljson-v0.4.11+commit.68ef5810.js', - '0.4.10': 'soljson-v0.4.10+commit.f0d539ae.js', - '0.4.9': 'soljson-v0.4.9+commit.364da425.js', - '0.4.8': 'soljson-v0.4.8+commit.60cc1668.js', - '0.4.7': 'soljson-v0.4.7+commit.822622cf.js', - '0.4.6': 'soljson-v0.4.6+commit.2dabbdf0.js', - '0.4.5': 'soljson-v0.4.5+commit.b318366e.js', - '0.4.4': 'soljson-v0.4.4+commit.4633f3de.js', - '0.4.3': 'soljson-v0.4.3+commit.2353da71.js', - '0.4.2': 'soljson-v0.4.2+commit.af6afb04.js', - '0.4.1': 'soljson-v0.4.1+commit.4fc6fc2c.js', - '0.4.0': 'soljson-v0.4.0+commit.acd334c9.js', - '0.3.6': 'soljson-v0.3.6+commit.3fc68da.js', - '0.3.5': 'soljson-v0.3.5+commit.5f97274.js', - '0.3.4': 'soljson-v0.3.4+commit.7dab890.js', - '0.3.3': 'soljson-v0.3.3+commit.4dc1cb1.js', - '0.3.2': 'soljson-v0.3.2+commit.81ae2a7.js', - '0.3.1': 'soljson-v0.3.1+commit.c492d9b.js', - '0.3.0': 'soljson-v0.3.0+commit.11d6736.js', - '0.2.2': 'soljson-v0.2.2+commit.ef92f56.js', - '0.2.1': 'soljson-v0.2.1+commit.91a6b35.js', - '0.2.0': 'soljson-v0.2.0+commit.4dc2445.js', - '0.1.7': 'soljson-v0.1.7+commit.b4e666c.js', - '0.1.6': 'soljson-v0.1.6+commit.d41f8b7.js', - '0.1.5': 'soljson-v0.1.5+commit.23865e3.js', - '0.1.4': 'soljson-v0.1.4+commit.5f6c3cd.js', - '0.1.3': 'soljson-v0.1.3+commit.28f561.js', - '0.1.2': 'soljson-v0.1.2+commit.d0d36e3.js', - '0.1.1': 'soljson-v0.1.1+commit.6ff4cd6.js', -}; diff --git a/packages/sol-compiler/src/utils/compiler.ts b/packages/sol-compiler/src/utils/compiler.ts index dffd07b1d..34aa1a3b8 100644 --- a/packages/sol-compiler/src/utils/compiler.ts +++ b/packages/sol-compiler/src/utils/compiler.ts @@ -9,11 +9,9 @@ import * as path from 'path'; import * as requireFromString from 'require-from-string'; import * as solc from 'solc'; -import { binPaths } from '../solc/bin_paths'; - import { constants } from './constants'; import { fsWrapper } from './fs_wrapper'; -import { CompilationError } from './types'; +import { BinaryPaths, CompilationError } from './types'; /** * Gets contract data on network or returns if an artifact does not exist. @@ -119,6 +117,20 @@ export function parseDependencies(contractSource: ContractSource): string[] { return dependencies; } +let solcJSReleasesCache: BinaryPaths | undefined; + +/** + * Fetches the list of available solidity compilers + */ +export async function getSolcJSReleasesAsync(): Promise<BinaryPaths> { + if (_.isUndefined(solcJSReleasesCache)) { + const versionList = await fetch('https://ethereum.github.io/solc-bin/bin/list.json'); + const versionListJSON = await versionList.json(); + solcJSReleasesCache = versionListJSON.releases; + } + return solcJSReleasesCache as BinaryPaths; +} + /** * Compiles the contracts and prints errors/warnings * @param solcVersion Version of a solc compiler @@ -319,7 +331,8 @@ function recursivelyGatherDependencySources( * @param solcVersion The compiler version. e.g. 0.5.0 */ export async function getSolcJSAsync(solcVersion: string): Promise<solc.SolcInstance> { - const fullSolcVersion = binPaths[solcVersion]; + const solcJSReleases = await getSolcJSReleasesAsync(); + const fullSolcVersion = solcJSReleases[solcVersion]; if (_.isUndefined(fullSolcVersion)) { throw new Error(`${solcVersion} is not a known compiler version`); } diff --git a/packages/sol-compiler/src/utils/types.ts b/packages/sol-compiler/src/utils/types.ts index 64328899d..f756c51bb 100644 --- a/packages/sol-compiler/src/utils/types.ts +++ b/packages/sol-compiler/src/utils/types.ts @@ -13,6 +13,10 @@ export interface ContractSourceData { [contractName: string]: ContractSpecificSourceData; } +export interface BinaryPaths { + [key: string]: string; +} + export interface ContractSpecificSourceData { solcVersionRange: string; sourceHash: Buffer; |