aboutsummaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
authorF. Eugene Aumson <gene@aumson.org>2018-08-23 05:32:01 +0800
committerF. Eugene Aumson <gene@aumson.org>2018-08-29 02:24:26 +0800
commit4779ebfd20d9c4b197d525453ac1ec47cc15e2bc (patch)
tree89343b29d36ca8fdeb9b5d39c2b887359f41a935 /packages
parent2eab0e30b753fb33729db53d141c8e22017cadec (diff)
downloaddexon-sol-tools-4779ebfd20d9c4b197d525453ac1ec47cc15e2bc.tar
dexon-sol-tools-4779ebfd20d9c4b197d525453ac1ec47cc15e2bc.tar.gz
dexon-sol-tools-4779ebfd20d9c4b197d525453ac1ec47cc15e2bc.tar.bz2
dexon-sol-tools-4779ebfd20d9c4b197d525453ac1ec47cc15e2bc.tar.lz
dexon-sol-tools-4779ebfd20d9c4b197d525453ac1ec47cc15e2bc.tar.xz
dexon-sol-tools-4779ebfd20d9c4b197d525453ac1ec47cc15e2bc.tar.zst
dexon-sol-tools-4779ebfd20d9c4b197d525453ac1ec47cc15e2bc.zip
split method
Diffstat (limited to 'packages')
-rw-r--r--packages/sol-compiler/src/compiler.ts51
1 files changed, 29 insertions, 22 deletions
diff --git a/packages/sol-compiler/src/compiler.ts b/packages/sol-compiler/src/compiler.ts
index 7c76f3e52..c44585a36 100644
--- a/packages/sol-compiler/src/compiler.ts
+++ b/packages/sol-compiler/src/compiler.ts
@@ -110,6 +110,21 @@ export class Compiler {
const solcInstance = solc.setupMethods(requireFromString(solcjs, compilerBinFilename));
return { solcInstance, fullSolcVersion };
}
+ private static _addHexPrefixes(compiledData: solc.StandardContractOutput): void {
+ if (!_.isUndefined(compiledData.evm)) {
+ if (!_.isUndefined(compiledData.evm.bytecode) && !_.isUndefined(compiledData.evm.bytecode.object)) {
+ compiledData.evm.bytecode.object = ethUtil.addHexPrefix(compiledData.evm.bytecode.object);
+ }
+ if (
+ !_.isUndefined(compiledData.evm.deployedBytecode) &&
+ !_.isUndefined(compiledData.evm.deployedBytecode.object)
+ ) {
+ compiledData.evm.deployedBytecode.object = ethUtil.addHexPrefix(
+ compiledData.evm.deployedBytecode.object,
+ );
+ }
+ }
+ }
/**
* Instantiates a new instance of the Compiler class.
* @param opts Optional compiler options
@@ -214,11 +229,22 @@ export class Compiler {
const compilerOutput = this._compile(solcInstance, input.standardInput);
for (const contractPath of input.contractsToCompile) {
- await this._verifyAndPersistCompiledContractAsync(
+ const contractName = contractPathToData[contractPath].contractName;
+
+ const compiledData = compilerOutput.contracts[contractPath][contractName];
+ if (_.isUndefined(compiledData)) {
+ throw new Error(
+ `Contract ${contractName} not found in ${contractPath}. Please make sure your contract has the same name as it's file name`,
+ );
+ }
+
+ Compiler._addHexPrefixes(compiledData);
+
+ await this._persistCompiledContractAsync(
contractPath,
contractPathToData[contractPath].currentArtifactIfExists,
contractPathToData[contractPath].sourceTreeHashHex,
- contractPathToData[contractPath].contractName,
+ contractName,
fullSolcVersion,
compilerOutput,
);
@@ -236,7 +262,7 @@ export class Compiler {
return !isUserOnLatestVersion || didCompilerSettingsChange || didSourceChange;
}
}
- private async _verifyAndPersistCompiledContractAsync(
+ private async _persistCompiledContractAsync(
contractPath: string,
currentArtifactIfExists: ContractArtifact | void,
sourceTreeHashHex: string,
@@ -245,25 +271,6 @@ export class Compiler {
compilerOutput: solc.StandardOutput,
): Promise<void> {
const compiledData = compilerOutput.contracts[contractPath][contractName];
- if (_.isUndefined(compiledData)) {
- throw new Error(
- `Contract ${contractName} not found in ${contractPath}. Please make sure your contract has the same name as it's file name`,
- );
- }
- if (!_.isUndefined(compiledData.evm)) {
- if (!_.isUndefined(compiledData.evm.bytecode) && !_.isUndefined(compiledData.evm.bytecode.object)) {
- compiledData.evm.bytecode.object = ethUtil.addHexPrefix(compiledData.evm.bytecode.object);
- }
- if (
- !_.isUndefined(compiledData.evm.deployedBytecode) &&
- !_.isUndefined(compiledData.evm.deployedBytecode.object)
- ) {
- compiledData.evm.deployedBytecode.object = ethUtil.addHexPrefix(
- compiledData.evm.deployedBytecode.object,
- );
- }
- }
-
const sourceCodes = _.mapValues(
compilerOutput.sources,
(_1, sourceFilePath) => this._resolver.resolve(sourceFilePath).source,