move getSolcAsync to static private method
This commit is contained in:
@@ -53,30 +53,6 @@ const DEFAULT_COMPILER_SETTINGS: solc.CompilerSettings = {
|
|||||||
};
|
};
|
||||||
const CONFIG_FILE = 'compiler.json';
|
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
|
* The Compiler facilitates compiling Solidity smart contracts and saves the results
|
||||||
* to artifact files.
|
* to artifact files.
|
||||||
@@ -210,7 +186,7 @@ export class Compiler {
|
|||||||
}) with Solidity v${solcVersion}...`,
|
}) with Solidity v${solcVersion}...`,
|
||||||
);
|
);
|
||||||
|
|
||||||
const { solcInstance, fullSolcVersion } = await getSolcAsync(solcVersion);
|
const { solcInstance, fullSolcVersion } = await Compiler._getSolcAsync(solcVersion);
|
||||||
|
|
||||||
const compiled = this._compile(solcInstance, input.standardInput);
|
const compiled = this._compile(solcInstance, input.standardInput);
|
||||||
|
|
||||||
@@ -224,6 +200,29 @@ 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(
|
private async _verifyAndPersistCompiledContractAsync(
|
||||||
contractPath: string,
|
contractPath: string,
|
||||||
contractMetadata: {
|
contractMetadata: {
|
||||||
|
|||||||
Reference in New Issue
Block a user