aboutsummaryrefslogtreecommitdiffstats
path: root/packages/deployer/src/utils
diff options
context:
space:
mode:
Diffstat (limited to 'packages/deployer/src/utils')
-rw-r--r--packages/deployer/src/utils/compiler.ts32
-rw-r--r--packages/deployer/src/utils/types.ts9
2 files changed, 9 insertions, 32 deletions
diff --git a/packages/deployer/src/utils/compiler.ts b/packages/deployer/src/utils/compiler.ts
index b83be221a..79dce5d73 100644
--- a/packages/deployer/src/utils/compiler.ts
+++ b/packages/deployer/src/utils/compiler.ts
@@ -1,3 +1,4 @@
+import { ContractSource, ContractSources } from '@0xproject/resolver';
import { logUtils } from '@0xproject/utils';
import * as _ from 'lodash';
import * as path from 'path';
@@ -5,7 +6,7 @@ import * as solc from 'solc';
import { constants } from './constants';
import { fsWrapper } from './fs_wrapper';
-import { ContractArtifact, ContractSources } from './types';
+import { ContractArtifact } from './types';
/**
* Gets contract data on network or returns if an artifact does not exist.
@@ -83,8 +84,9 @@ export function getNormalizedErrMsg(errMsg: string): string {
* @param source Contract source code
* @return List of dependendencies
*/
-export function parseDependencies(source: string): string[] {
+export function parseDependencies(contractSource: ContractSource): string[] {
// TODO: Use a proper parser
+ const source = contractSource.source;
const IMPORT_REGEX = /(import\s)/;
const DEPENDENCY_PATH_REGEX = /"([^"]+)"/; // Source: https://github.com/BlockChainCompany/soljitsu/blob/master/lib/shared.js
const dependencies: string[] = [];
@@ -93,29 +95,13 @@ export function parseDependencies(source: string): string[] {
if (!_.isNull(line.match(IMPORT_REGEX))) {
const dependencyMatch = line.match(DEPENDENCY_PATH_REGEX);
if (!_.isNull(dependencyMatch)) {
- const dependencyPath = dependencyMatch[1];
- const contractName = path.basename(dependencyPath, constants.SOLIDITY_FILE_EXTENSION);
- dependencies.push(contractName);
+ let dependencyPath = dependencyMatch[1];
+ if (dependencyPath.startsWith('.')) {
+ dependencyPath = path.join(path.dirname(contractSource.path), dependencyPath);
+ }
+ dependencies.push(dependencyPath);
}
}
});
return dependencies;
}
-
-/**
- * Callback to resolve dependencies with `solc.compile`.
- * @param contractSources Source codes of contracts.
- * @param importPath Path to an imported dependency.
- * @return Import contents object containing source code of dependency.
- */
-export function findImportIfExist(contractSources: ContractSources, importPath: string): solc.ImportContents {
- const contractName = path.basename(importPath, constants.SOLIDITY_FILE_EXTENSION);
- const source = contractSources[contractName].source;
- if (_.isUndefined(source)) {
- throw new Error(`Contract source not found for ${contractName}`);
- }
- const importContents: solc.ImportContents = {
- contents: source,
- };
- return importContents;
-}
diff --git a/packages/deployer/src/utils/types.ts b/packages/deployer/src/utils/types.ts
index 54579c200..a20d0f627 100644
--- a/packages/deployer/src/utils/types.ts
+++ b/packages/deployer/src/utils/types.ts
@@ -21,7 +21,6 @@ export interface ContractNetworks {
export interface ContractNetworkData {
solc_version: string;
optimizer_enabled: boolean;
- keccak256: string;
source_tree_hash: string;
abi: ContractAbi;
bytecode: string;
@@ -74,19 +73,11 @@ export interface UrlDeployerOptions extends BaseDeployerOptions {
export type DeployerOptions = UrlDeployerOptions | ProviderDeployerOptions;
-export interface ContractSources {
- [key: string]: {
- source: string;
- absoluteFilePath: string;
- };
-}
-
export interface ContractSourceData {
[contractName: string]: ContractSpecificSourceData;
}
export interface ContractSpecificSourceData {
- dependencies: string[];
solcVersionRange: string;
sourceHash: Buffer;
sourceTreeHash: Buffer;