diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2018-04-10 04:23:25 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2018-04-12 18:52:48 +0800 |
commit | eb89926cee2c50ef657b3c033b5637f527d73c6a (patch) | |
tree | 6a4ece7902c860bfa48ac53033baf86ba25683d0 /packages/deployer/src/utils | |
parent | 7923ff4ac6d03adf3787a2a3e6f7deb6aa38fc73 (diff) | |
download | dexon-sol-tools-eb89926cee2c50ef657b3c033b5637f527d73c6a.tar dexon-sol-tools-eb89926cee2c50ef657b3c033b5637f527d73c6a.tar.gz dexon-sol-tools-eb89926cee2c50ef657b3c033b5637f527d73c6a.tar.bz2 dexon-sol-tools-eb89926cee2c50ef657b3c033b5637f527d73c6a.tar.lz dexon-sol-tools-eb89926cee2c50ef657b3c033b5637f527d73c6a.tar.xz dexon-sol-tools-eb89926cee2c50ef657b3c033b5637f527d73c6a.tar.zst dexon-sol-tools-eb89926cee2c50ef657b3c033b5637f527d73c6a.zip |
Implement the resolver
Diffstat (limited to 'packages/deployer/src/utils')
-rw-r--r-- | packages/deployer/src/utils/compiler.ts | 32 | ||||
-rw-r--r-- | packages/deployer/src/utils/types.ts | 9 |
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; |