aboutsummaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
authorF. Eugene Aumson <gene@aumson.org>2018-08-16 02:46:23 +0800
committerF. Eugene Aumson <gene@aumson.org>2018-08-16 03:53:41 +0800
commit558286467bc7c05ea1a97a1fdfde0ad1ba7e279f (patch)
treed7af3f1cf08f5b44f1590b3bf5c6a1a4b6caebdd /packages
parentf0f94f199eff982ffa03c6a760235ed22a8ad68a (diff)
downloaddexon-sol-tools-558286467bc7c05ea1a97a1fdfde0ad1ba7e279f.tar
dexon-sol-tools-558286467bc7c05ea1a97a1fdfde0ad1ba7e279f.tar.gz
dexon-sol-tools-558286467bc7c05ea1a97a1fdfde0ad1ba7e279f.tar.bz2
dexon-sol-tools-558286467bc7c05ea1a97a1fdfde0ad1ba7e279f.tar.lz
dexon-sol-tools-558286467bc7c05ea1a97a1fdfde0ad1ba7e279f.tar.xz
dexon-sol-tools-558286467bc7c05ea1a97a1fdfde0ad1ba7e279f.tar.zst
dexon-sol-tools-558286467bc7c05ea1a97a1fdfde0ad1ba7e279f.zip
extract interfaces for re-used complex data types
Diffstat (limited to 'packages')
-rw-r--r--packages/sol-compiler/src/compiler.ts51
1 files changed, 28 insertions, 23 deletions
diff --git a/packages/sol-compiler/src/compiler.ts b/packages/sol-compiler/src/compiler.ts
index c162d65f4..286f15073 100644
--- a/packages/sol-compiler/src/compiler.ts
+++ b/packages/sol-compiler/src/compiler.ts
@@ -53,6 +53,23 @@ const DEFAULT_COMPILER_SETTINGS: solc.CompilerSettings = {
};
const CONFIG_FILE = 'compiler.json';
+interface VersionToInputs {
+ [solcVersion: string]: {
+ standardInput: solc.StandardInput;
+ contractsToCompile: string[];
+ };
+}
+
+interface ContractPathToData {
+ [contractPath: string]: ContractData;
+}
+
+interface ContractData {
+ currentArtifactIfExists: ContractArtifact | void;
+ sourceTreeHashHex: string;
+ contractName: string;
+}
+
/**
* The Compiler facilitates compiling Solidity smart contracts and saves the results
* to artifact files.
@@ -137,24 +154,15 @@ export class Compiler {
* @param fileName Name of contract with '.sol' extension.
*/
private async _compileContractsAsync(contractNames: string[]): Promise<void> {
- const versionToInputs: {
- [solcVersion: string]: {
- standardInput: solc.StandardInput;
- contractsToCompile: string[];
- };
- } = {};
+ // batch input contracts together based on the version of the compiler that they require.
+ const versionToInputs: VersionToInputs = {};
- const contractData: {
- [contractPath: string]: {
- currentArtifactIfExists: ContractArtifact | void;
- sourceTreeHashHex: string;
- contractName: string;
- };
- } = {};
+ // map contract paths to data about them for later verification and persistence
+ const contractPathToData: ContractPathToData = {};
for (const contractName of contractNames) {
const contractSource = this._resolver.resolve(contractName);
- contractData[contractSource.path] = {
+ contractPathToData[contractSource.path] = {
contractName,
currentArtifactIfExists: await getContractArtifactIfExistsAsync(this._artifactsDir, contractName),
sourceTreeHashHex: `0x${this._getSourceTreeHash(
@@ -162,14 +170,15 @@ export class Compiler {
).toString('hex')}`,
};
let shouldCompile = false;
- if (_.isUndefined(contractData[contractSource.path].currentArtifactIfExists)) {
+ if (_.isUndefined(contractPathToData[contractSource.path].currentArtifactIfExists)) {
shouldCompile = true;
} else {
- const currentArtifact = contractData[contractSource.path].currentArtifactIfExists as ContractArtifact;
+ const currentArtifact = contractPathToData[contractSource.path]
+ .currentArtifactIfExists as ContractArtifact;
const isUserOnLatestVersion = currentArtifact.schemaVersion === constants.LATEST_ARTIFACT_VERSION;
const didCompilerSettingsChange = !_.isEqual(currentArtifact.compiler.settings, this._compilerSettings);
const didSourceChange =
- currentArtifact.sourceTreeHashHex !== contractData[contractSource.path].sourceTreeHashHex;
+ currentArtifact.sourceTreeHashHex !== contractPathToData[contractSource.path].sourceTreeHashHex;
shouldCompile = !isUserOnLatestVersion || didCompilerSettingsChange || didSourceChange;
}
if (!shouldCompile) {
@@ -216,7 +225,7 @@ export class Compiler {
for (const contractPath of input.contractsToCompile) {
await this._verifyAndPersistCompiledContractAsync(
contractPath,
- contractData[contractPath],
+ contractPathToData[contractPath],
fullSolcVersion,
compiled,
);
@@ -225,11 +234,7 @@ export class Compiler {
}
private async _verifyAndPersistCompiledContractAsync(
contractPath: string,
- contractMetadata: {
- currentArtifactIfExists: ContractArtifact | void;
- sourceTreeHashHex: string;
- contractName: string;
- },
+ contractMetadata: ContractData,
fullSolcVersion: string,
compiled: solc.StandardOutput,
): Promise<void> {