From f2f9bd2e7ac1372073644a4e30a5d99e8c57fbb1 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 10 Apr 2018 13:44:15 +0200 Subject: Revert "Merge pull request #493 from hysz/features/deployer/multipleCodebaseSupport" This reverts commit 70d403e6f8c56bc70e6d3471a770b9bbff5d72e7, reversing changes made to 073bf738ddb271b6b4158798baf4cac3cb0608e9. --- packages/deployer/src/utils/compiler.ts | 65 +++++---------------------------- packages/deployer/src/utils/contract.ts | 4 +- packages/deployer/src/utils/encoder.ts | 4 +- packages/deployer/src/utils/types.ts | 19 ++-------- 4 files changed, 18 insertions(+), 74 deletions(-) (limited to 'packages/deployer/src/utils') diff --git a/packages/deployer/src/utils/compiler.ts b/packages/deployer/src/utils/compiler.ts index 600495693..d5137d394 100644 --- a/packages/deployer/src/utils/compiler.ts +++ b/packages/deployer/src/utils/compiler.ts @@ -1,4 +1,3 @@ -import { AbiType, ContractAbi, MethodAbi } from '@0xproject/types'; import { logUtils } from '@0xproject/utils'; import * as _ from 'lodash'; import * as path from 'path'; @@ -6,48 +5,8 @@ import * as solc from 'solc'; import { constants } from './constants'; import { fsWrapper } from './fs_wrapper'; -import { ContractArtifact, ContractSources, FunctionNameToSeenCount } from './types'; +import { ContractArtifact, ContractSources } from './types'; -/** - * Constructs a system-wide unique identifier for a source file. - * @param directoryNamespace Namespace of the source file's root contract directory. - * @param sourceFilePath Path to a source file, relative to contractBaseDir. - * @return sourceFileId A system-wide unique identifier for the source file. - */ -export function constructUniqueSourceFileId(directoryNamespace: string, sourceFilePath: string): string { - const namespacePrefix = !_.isEmpty(directoryNamespace) ? `/${directoryNamespace}` : ''; - const sourceFilePathNoLeadingSlash = sourceFilePath.replace(/^\/+/g, ''); - const sourceFileId = `${namespacePrefix}/${sourceFilePathNoLeadingSlash}`; - return sourceFileId; -} -/** - * Constructs a system-wide unique identifier for a dependency file. - * @param dependencyFilePath Path from a sourceFile to a dependency. - * @param contractBaseDir Base contracts directory of search tree. - * @return sourceFileId A system-wide unique identifier for the source file. - */ -export function constructDependencyFileId(dependencyFilePath: string, sourceFilePath: string): string { - if (_.startsWith(dependencyFilePath, '/')) { - // Path of the form /namespace/path/to/dependency.sol - return dependencyFilePath; - } else { - // Dependency is relative to the source file: ./dependency.sol, ../../some/path/dependency.sol, etc. - // Join the two paths to construct a valid source file id: /namespace/path/to/dependency.sol - return path.join(path.dirname(sourceFilePath), dependencyFilePath); - } -} -/** - * Constructs a system-wide unique identifier for a contract. - * @param directoryNamespace Namespace of the source file's root contract directory. - * @param sourceFilePath Path to a source file, relative to contractBaseDir. - * @return sourceFileId A system-wide unique identifier for contract. - */ -export function constructContractId(directoryNamespace: string, sourceFilePath: string): string { - const namespacePrefix = !_.isEmpty(directoryNamespace) ? `${directoryNamespace}:` : ''; - const sourceFileName = path.basename(sourceFilePath, constants.SOLIDITY_FILE_EXTENSION); - const contractId = `${namespacePrefix}${sourceFileName}`; - return contractId; -} /** * Gets contract data on network or returns if an artifact does not exist. * @param artifactsDir Path to the artifacts directory. @@ -123,10 +82,9 @@ export function getNormalizedErrMsg(errMsg: string): string { /** * Parses the contract source code and extracts the dendencies * @param source Contract source code - * @param sourceFilePath File path of the source code. * @return List of dependendencies */ -export function parseDependencies(source: string, sourceFileId: string): string[] { +export function parseDependencies(source: string): string[] { // TODO: Use a proper parser const IMPORT_REGEX = /(import\s)/; const DEPENDENCY_PATH_REGEX = /"([^"]+)"/; // Source: https://github.com/BlockChainCompany/soljitsu/blob/master/lib/shared.js @@ -137,8 +95,8 @@ export function parseDependencies(source: string, sourceFileId: string): string[ const dependencyMatch = line.match(DEPENDENCY_PATH_REGEX); if (!_.isNull(dependencyMatch)) { const dependencyPath = dependencyMatch[1]; - const dependencyId = constructDependencyFileId(dependencyPath, sourceFileId); - dependencies.push(dependencyId); + const basenName = path.basename(dependencyPath); + dependencies.push(basenName); } } }); @@ -149,19 +107,14 @@ export function parseDependencies(source: string, sourceFileId: string): string[ * Callback to resolve dependencies with `solc.compile`. * Throws error if contractSources not yet initialized. * @param contractSources Source codes of contracts. - * @param sourceFileId ID of the source file. - * @param importPath Path of dependency source file. + * @param importPath Path to an imported dependency. * @return Import contents object containing source code of dependency. */ -export function findImportIfExist( - contractSources: ContractSources, - sourceFileId: string, - importPath: string, -): solc.ImportContents { - const dependencyFileId = constructDependencyFileId(importPath, sourceFileId); - const source = contractSources[dependencyFileId]; +export function findImportIfExist(contractSources: ContractSources, importPath: string): solc.ImportContents { + const fileName = path.basename(importPath); + const source = contractSources[fileName]; if (_.isUndefined(source)) { - throw new Error(`Contract source not found for ${dependencyFileId}`); + throw new Error(`Contract source not found for ${fileName}`); } const importContents: solc.ImportContents = { contents: source, diff --git a/packages/deployer/src/utils/contract.ts b/packages/deployer/src/utils/contract.ts index e8dd5218a..9b7baac11 100644 --- a/packages/deployer/src/utils/contract.ts +++ b/packages/deployer/src/utils/contract.ts @@ -1,9 +1,11 @@ import { schemas, SchemaValidator } from '@0xproject/json-schemas'; -import { AbiType, ContractAbi, EventAbi, FunctionAbi, MethodAbi, TxData } from '@0xproject/types'; +import { ContractAbi, EventAbi, FunctionAbi, MethodAbi, TxData } from '@0xproject/types'; import { promisify } from '@0xproject/utils'; import * as _ from 'lodash'; import * as Web3 from 'web3'; +import { AbiType } from './types'; + export class Contract implements Web3.ContractInstance { public address: string; public abi: ContractAbi; diff --git a/packages/deployer/src/utils/encoder.ts b/packages/deployer/src/utils/encoder.ts index 806efbbca..4f62662e1 100644 --- a/packages/deployer/src/utils/encoder.ts +++ b/packages/deployer/src/utils/encoder.ts @@ -1,7 +1,9 @@ -import { AbiDefinition, AbiType, ContractAbi, DataItem } from '@0xproject/types'; +import { AbiDefinition, ContractAbi, DataItem } from '@0xproject/types'; import * as _ from 'lodash'; import * as web3Abi from 'web3-eth-abi'; +import { AbiType } from './types'; + export const encoder = { encodeConstructorArgsFromAbi(args: any[], abi: ContractAbi): string { const constructorTypes: string[] = []; diff --git a/packages/deployer/src/utils/types.ts b/packages/deployer/src/utils/types.ts index 1a866b873..7d131f5ce 100644 --- a/packages/deployer/src/utils/types.ts +++ b/packages/deployer/src/utils/types.ts @@ -18,11 +18,6 @@ export interface ContractNetworks { [key: number]: ContractNetworkData; } -export interface ContractDirectory { - path: string; - namespace: string; -} - export interface ContractNetworkData { solc_version: string; optimizer_enabled: boolean; @@ -45,7 +40,7 @@ export interface SolcErrors { export interface CliOptions extends yargs.Arguments { artifactsDir: string; - contractDirs: string; + contractsDir: string; jsonrpcUrl: string; networkId: number; shouldOptimize: boolean; @@ -56,7 +51,7 @@ export interface CliOptions extends yargs.Arguments { } export interface CompilerOptions { - contractDirs: Set; + contractsDir: string; networkId: number; optimizerEnabled: boolean; artifactsDir: string; @@ -83,11 +78,7 @@ export interface ContractSources { [key: string]: string; } -export interface ContractIdToSourceFileId { - [key: string]: string; -} - -export interface ContractSourceDataByFileId { +export interface ContractSourceData { [key: string]: ContractSpecificSourceData; } @@ -107,8 +98,4 @@ export interface Token { swarmHash: string; } -export interface FunctionNameToSeenCount { - [key: string]: number; -} - export type DoneCallback = (err?: Error) => void; -- cgit v1.2.3 From 4dd9f29769bea90a4b687be26b086164aaff685a Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 10 Apr 2018 14:06:43 +0200 Subject: Add ony abi-gen changes from Greg's PR --- packages/deployer/src/utils/contract.ts | 4 +--- packages/deployer/src/utils/encoder.ts | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) (limited to 'packages/deployer/src/utils') diff --git a/packages/deployer/src/utils/contract.ts b/packages/deployer/src/utils/contract.ts index 9b7baac11..e8dd5218a 100644 --- a/packages/deployer/src/utils/contract.ts +++ b/packages/deployer/src/utils/contract.ts @@ -1,11 +1,9 @@ import { schemas, SchemaValidator } from '@0xproject/json-schemas'; -import { ContractAbi, EventAbi, FunctionAbi, MethodAbi, TxData } from '@0xproject/types'; +import { AbiType, ContractAbi, EventAbi, FunctionAbi, MethodAbi, TxData } from '@0xproject/types'; import { promisify } from '@0xproject/utils'; import * as _ from 'lodash'; import * as Web3 from 'web3'; -import { AbiType } from './types'; - export class Contract implements Web3.ContractInstance { public address: string; public abi: ContractAbi; diff --git a/packages/deployer/src/utils/encoder.ts b/packages/deployer/src/utils/encoder.ts index 4f62662e1..806efbbca 100644 --- a/packages/deployer/src/utils/encoder.ts +++ b/packages/deployer/src/utils/encoder.ts @@ -1,9 +1,7 @@ -import { AbiDefinition, ContractAbi, DataItem } from '@0xproject/types'; +import { AbiDefinition, AbiType, ContractAbi, DataItem } from '@0xproject/types'; import * as _ from 'lodash'; import * as web3Abi from 'web3-eth-abi'; -import { AbiType } from './types'; - export const encoder = { encodeConstructorArgsFromAbi(args: any[], abi: ContractAbi): string { const constructorTypes: string[] = []; -- cgit v1.2.3 From 442017f93ad1fa5af7b751da7cfdda3deb0861ab Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Fri, 6 Apr 2018 18:37:48 +0200 Subject: Use solc.compileStandardWrapper --- packages/deployer/src/utils/compiler.ts | 18 ++++++++---------- packages/deployer/src/utils/types.ts | 7 +++++-- 2 files changed, 13 insertions(+), 12 deletions(-) (limited to 'packages/deployer/src/utils') diff --git a/packages/deployer/src/utils/compiler.ts b/packages/deployer/src/utils/compiler.ts index d5137d394..b83be221a 100644 --- a/packages/deployer/src/utils/compiler.ts +++ b/packages/deployer/src/utils/compiler.ts @@ -10,15 +10,14 @@ import { ContractArtifact, ContractSources } from './types'; /** * Gets contract data on network or returns if an artifact does not exist. * @param artifactsDir Path to the artifacts directory. - * @param fileName Name of contract file. + * @param contractName Name of contract. * @return Contract data on network or undefined. */ export async function getContractArtifactIfExistsAsync( artifactsDir: string, - fileName: string, + contractName: string, ): Promise { let contractArtifact; - const contractName = path.basename(fileName, constants.SOLIDITY_FILE_EXTENSION); const currentArtifactPath = `${artifactsDir}/${contractName}.json`; try { const opts = { @@ -28,7 +27,7 @@ export async function getContractArtifactIfExistsAsync( contractArtifact = JSON.parse(contractArtifactString); return contractArtifact; } catch (err) { - logUtils.log(`Artifact for ${fileName} does not exist`); + logUtils.log(`Artifact for ${contractName} does not exist`); return undefined; } } @@ -95,8 +94,8 @@ export function parseDependencies(source: string): string[] { const dependencyMatch = line.match(DEPENDENCY_PATH_REGEX); if (!_.isNull(dependencyMatch)) { const dependencyPath = dependencyMatch[1]; - const basenName = path.basename(dependencyPath); - dependencies.push(basenName); + const contractName = path.basename(dependencyPath, constants.SOLIDITY_FILE_EXTENSION); + dependencies.push(contractName); } } }); @@ -105,16 +104,15 @@ export function parseDependencies(source: string): string[] { /** * Callback to resolve dependencies with `solc.compile`. - * Throws error if contractSources not yet initialized. * @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 fileName = path.basename(importPath); - const source = contractSources[fileName]; + 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 ${fileName}`); + throw new Error(`Contract source not found for ${contractName}`); } const importContents: solc.ImportContents = { contents: source, diff --git a/packages/deployer/src/utils/types.ts b/packages/deployer/src/utils/types.ts index 7d131f5ce..54579c200 100644 --- a/packages/deployer/src/utils/types.ts +++ b/packages/deployer/src/utils/types.ts @@ -75,11 +75,14 @@ export interface UrlDeployerOptions extends BaseDeployerOptions { export type DeployerOptions = UrlDeployerOptions | ProviderDeployerOptions; export interface ContractSources { - [key: string]: string; + [key: string]: { + source: string; + absoluteFilePath: string; + }; } export interface ContractSourceData { - [key: string]: ContractSpecificSourceData; + [contractName: string]: ContractSpecificSourceData; } export interface ContractSpecificSourceData { -- cgit v1.2.3 From eb89926cee2c50ef657b3c033b5637f527d73c6a Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 9 Apr 2018 22:23:25 +0200 Subject: Implement the resolver --- packages/deployer/src/utils/compiler.ts | 32 +++++++++----------------------- packages/deployer/src/utils/types.ts | 9 --------- 2 files changed, 9 insertions(+), 32 deletions(-) (limited to 'packages/deployer/src/utils') 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; -- cgit v1.2.3 From d8ef76fd5efe63ec8f6205a73494ce388e64391f Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 16 Apr 2018 16:38:55 +0200 Subject: Rename resolver to sol-resolver --- packages/deployer/src/utils/compiler.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages/deployer/src/utils') diff --git a/packages/deployer/src/utils/compiler.ts b/packages/deployer/src/utils/compiler.ts index 79dce5d73..c571b2581 100644 --- a/packages/deployer/src/utils/compiler.ts +++ b/packages/deployer/src/utils/compiler.ts @@ -1,4 +1,4 @@ -import { ContractSource, ContractSources } from '@0xproject/resolver'; +import { ContractSource, ContractSources } from '@0xproject/sol-resolver'; import { logUtils } from '@0xproject/utils'; import * as _ from 'lodash'; import * as path from 'path'; -- cgit v1.2.3