aboutsummaryrefslogtreecommitdiffstats
path: root/packages/sol-compiler
diff options
context:
space:
mode:
authorF. Eugene Aumson <gene@aumson.org>2018-08-14 13:31:04 +0800
committerF. Eugene Aumson <gene@aumson.org>2018-08-15 02:42:06 +0800
commitd89934954d22e5175a7d97f407e2cd43a04d0b57 (patch)
treebb58d04172a9d01287a0f5239a4124c13a6b3da8 /packages/sol-compiler
parent56eb444ea4b04768c8ea3192d87074602838f0ea (diff)
downloaddexon-sol-tools-d89934954d22e5175a7d97f407e2cd43a04d0b57.tar
dexon-sol-tools-d89934954d22e5175a7d97f407e2cd43a04d0b57.tar.gz
dexon-sol-tools-d89934954d22e5175a7d97f407e2cd43a04d0b57.tar.bz2
dexon-sol-tools-d89934954d22e5175a7d97f407e2cd43a04d0b57.tar.lz
dexon-sol-tools-d89934954d22e5175a7d97f407e2cd43a04d0b57.tar.xz
dexon-sol-tools-d89934954d22e5175a7d97f407e2cd43a04d0b57.tar.zst
dexon-sol-tools-d89934954d22e5175a7d97f407e2cd43a04d0b57.zip
extract function getSolcAsync()
Diffstat (limited to 'packages/sol-compiler')
-rw-r--r--packages/sol-compiler/src/compiler.ts43
1 files changed, 25 insertions, 18 deletions
diff --git a/packages/sol-compiler/src/compiler.ts b/packages/sol-compiler/src/compiler.ts
index 3620a3ec1..5c99e3dae 100644
--- a/packages/sol-compiler/src/compiler.ts
+++ b/packages/sol-compiler/src/compiler.ts
@@ -53,6 +53,30 @@ const DEFAULT_COMPILER_SETTINGS: solc.CompilerSettings = {
};
const CONFIG_FILE = 'compiler.json';
+async function getSolcAsync(
+ solcVersion: string,
+): Promise<{ solcInstance: solc.SolcInstance; fullSolcVersion: string }> {
+ const fullSolcVersion = binPaths[solcVersion];
+ const compilerBinFilename = path.join(SOLC_BIN_DIR, fullSolcVersion);
+ let solcjs: string;
+ const isCompilerAvailableLocally = fs.existsSync(compilerBinFilename);
+ if (isCompilerAvailableLocally) {
+ solcjs = fs.readFileSync(compilerBinFilename).toString();
+ } else {
+ logUtils.log(`Downloading ${fullSolcVersion}...`);
+ const url = `${constants.BASE_COMPILER_URL}${fullSolcVersion}`;
+ const response = await fetchAsync(url);
+ const SUCCESS_STATUS = 200;
+ if (response.status !== SUCCESS_STATUS) {
+ throw new Error(`Failed to load ${fullSolcVersion}`);
+ }
+ solcjs = await response.text();
+ fs.writeFileSync(compilerBinFilename, solcjs);
+ }
+ const solcInstance = solc.setupMethods(requireFromString(solcjs, compilerBinFilename));
+ return { solcInstance, fullSolcVersion };
+}
+
/**
* The Compiler facilitates compiling Solidity smart contracts and saves the results
* to artifact files.
@@ -139,24 +163,7 @@ export class Compiler {
const availableCompilerVersions = _.keys(binPaths);
solcVersion = semver.maxSatisfying(availableCompilerVersions, solcVersionRange);
}
- const fullSolcVersion = binPaths[solcVersion];
- const compilerBinFilename = path.join(SOLC_BIN_DIR, fullSolcVersion);
- let solcjs: string;
- const isCompilerAvailableLocally = fs.existsSync(compilerBinFilename);
- if (isCompilerAvailableLocally) {
- solcjs = fs.readFileSync(compilerBinFilename).toString();
- } else {
- logUtils.log(`Downloading ${fullSolcVersion}...`);
- const url = `${constants.BASE_COMPILER_URL}${fullSolcVersion}`;
- const response = await fetchAsync(url);
- const SUCCESS_STATUS = 200;
- if (response.status !== SUCCESS_STATUS) {
- throw new Error(`Failed to load ${fullSolcVersion}`);
- }
- solcjs = await response.text();
- fs.writeFileSync(compilerBinFilename, solcjs);
- }
- const solcInstance = solc.setupMethods(requireFromString(solcjs, compilerBinFilename));
+ const { solcInstance, fullSolcVersion } = await getSolcAsync(solcVersion);
logUtils.log(`Compiling ${contractName} with Solidity v${solcVersion}...`);
const standardInput: solc.StandardInput = {