diff options
author | F. Eugene Aumson <gene@aumson.org> | 2018-08-16 02:13:09 +0800 |
---|---|---|
committer | F. Eugene Aumson <gene@aumson.org> | 2018-08-16 03:53:33 +0800 |
commit | f0f94f199eff982ffa03c6a760235ed22a8ad68a (patch) | |
tree | 881cd08a551e4d1fb88ff31ab93b44393c36cfad | |
parent | d744468479bf88c89412115860e0b8c4cf2a48c1 (diff) | |
download | dexon-sol-tools-f0f94f199eff982ffa03c6a760235ed22a8ad68a.tar dexon-sol-tools-f0f94f199eff982ffa03c6a760235ed22a8ad68a.tar.gz dexon-sol-tools-f0f94f199eff982ffa03c6a760235ed22a8ad68a.tar.bz2 dexon-sol-tools-f0f94f199eff982ffa03c6a760235ed22a8ad68a.tar.lz dexon-sol-tools-f0f94f199eff982ffa03c6a760235ed22a8ad68a.tar.xz dexon-sol-tools-f0f94f199eff982ffa03c6a760235ed22a8ad68a.tar.zst dexon-sol-tools-f0f94f199eff982ffa03c6a760235ed22a8ad68a.zip |
move getSolcAsync to static private method
-rw-r--r-- | packages/sol-compiler/src/compiler.ts | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/packages/sol-compiler/src/compiler.ts b/packages/sol-compiler/src/compiler.ts index 0de8b8cad..c162d65f4 100644 --- a/packages/sol-compiler/src/compiler.ts +++ b/packages/sol-compiler/src/compiler.ts @@ -65,6 +65,29 @@ export class Compiler { private readonly _artifactsDir: string; private readonly _solcVersionIfExists: string | undefined; private readonly _specifiedContracts: string[] | TYPE_ALL_FILES_IDENTIFIER; + private static async _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 }; + } /** * Instantiates a new instance of the Compiler class. * @return An instance of the Compiler class. @@ -200,29 +223,6 @@ export class Compiler { } } } - private static async _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 }; - } private async _verifyAndPersistCompiledContractAsync( contractPath: string, contractMetadata: { |