From f62762bd0e5d3be443e412df1829c2d89ef4640e Mon Sep 17 00:00:00 2001 From: Amir Bandeali Date: Wed, 14 Feb 2018 14:03:12 -0800 Subject: Add contracts to compiler options --- packages/deployer/src/cli.ts | 21 +++++++++++++++++++++ packages/deployer/src/compiler.ts | 8 ++++++-- packages/deployer/src/utils/types.ts | 1 + 3 files changed, 28 insertions(+), 2 deletions(-) (limited to 'packages/deployer/src') diff --git a/packages/deployer/src/cli.ts b/packages/deployer/src/cli.ts index 0fe412bdf..5e0f2145b 100644 --- a/packages/deployer/src/cli.ts +++ b/packages/deployer/src/cli.ts @@ -14,6 +14,7 @@ const DEFAULT_ARTIFACTS_DIR = path.resolve('artifacts'); const DEFAULT_NETWORK_ID = 50; const DEFAULT_JSONRPC_PORT = 8545; const DEFAULT_GAS_PRICE = (10 ** 9 * 2).toString(); +const DEFAULT_COMPILE_CONTRACTS = '*'; /** * Compiles all contracts with options passed in through CLI. @@ -25,6 +26,7 @@ async function onCompileCommand(argv: CliOptions): Promise { networkId: argv.networkId, optimizerEnabled: argv.shouldOptimize ? 1 : 0, artifactsDir: argv.artifactsDir, + contractsToCompile: generateContractsToCompileSet(argv.contracts), }; await commands.compileAsync(opts); } @@ -43,6 +45,7 @@ async function onMigrateCommand(argv: CliOptions): Promise { networkId, optimizerEnabled: argv.shouldOptimize ? 1 : 0, artifactsDir: argv.artifactsDir, + contractsToCompile: generateContractsToCompileSet(argv.contracts), }; await commands.compileAsync(compilerOpts); @@ -72,6 +75,7 @@ async function onDeployCommand(argv: CliOptions): Promise { networkId, optimizerEnabled: argv.shouldOptimize ? 1 : 0, artifactsDir: argv.artifactsDir, + contractsToCompile: generateContractsToCompileSet(argv.contracts), }; await commands.compileAsync(compilerOpts); @@ -89,6 +93,18 @@ async function onDeployCommand(argv: CliOptions): Promise { const deployerArgs = deployerArgsString.split(','); await commands.deployAsync(argv.contract, deployerArgs, deployerOpts); } +/** + * Creates a set of contracts to compile. + * @param contracts Comma separated list of contracts to compile + */ +function generateContractsToCompileSet(contracts: string): Set { + const contractsToCompile = new Set(); + const contractsArray = contracts.split(','); + _.forEach(contracts, contractName => { + contractsToCompile.add(contractName); + }); + return contractsToCompile; +} /** * Provides extra required options for deploy command. * @param yargsInstance yargs instance provided in builder function callback. @@ -144,6 +160,11 @@ function deployCommandBuilder(yargsInstance: any) { type: 'string', description: 'account to use for deploying contracts', }) + .option('contracts', { + type: 'string', + default: DEFAULT_COMPILE_CONTRACTS, + description: 'comma separated list of contracts to compile', + }) .command('compile', 'compile contracts', identityCommandBuilder, onCompileCommand) .command( 'migrate', diff --git a/packages/deployer/src/compiler.ts b/packages/deployer/src/compiler.ts index 63db6c865..4e5518d0e 100644 --- a/packages/deployer/src/compiler.ts +++ b/packages/deployer/src/compiler.ts @@ -17,6 +17,7 @@ import { import { utils } from './utils/utils'; const SOLIDITY_FILE_EXTENSION = '.sol'; +const ALL_CONTRACTS_IDENTIFIER = '*'; export class Compiler { private _contractsDir: string; @@ -25,6 +26,7 @@ export class Compiler { private _artifactsDir: string; private _contractSourcesIfExists?: ContractSources; private _solcErrors: Set; + private _contractsToCompile: Set; /** * Recursively retrieves Solidity source code from directory. * @param dirPath Directory to search. @@ -106,6 +108,7 @@ export class Compiler { this._optimizerEnabled = opts.optimizerEnabled; this._artifactsDir = opts.artifactsDir; this._solcErrors = new Set(); + this._contractsToCompile = opts.contractsToCompile; } /** * Compiles all Solidity files found in contractsDir and writes JSON artifacts to artifactsDir. @@ -150,9 +153,10 @@ export class Compiler { oldNetworks = currentArtifact.networks; const oldNetwork: ContractData = oldNetworks[this._networkId]; shouldCompile = - _.isUndefined(oldNetwork) || + (_.isUndefined(oldNetwork) || oldNetwork.keccak256 !== sourceHash || - oldNetwork.optimizer_enabled !== this._optimizerEnabled; + oldNetwork.optimizer_enabled !== this._optimizerEnabled) && + (this._contractsToCompile.has(ALL_CONTRACTS_IDENTIFIER) || this._contractsToCompile.has(contractName)); } catch (err) { shouldCompile = true; } diff --git a/packages/deployer/src/utils/types.ts b/packages/deployer/src/utils/types.ts index e054b9cc2..c8bb1b9ca 100644 --- a/packages/deployer/src/utils/types.ts +++ b/packages/deployer/src/utils/types.ts @@ -50,6 +50,7 @@ export interface CompilerOptions { networkId: number; optimizerEnabled: number; artifactsDir: string; + contractsToCompile: Set; } export interface DeployerOptions { -- cgit v1.2.3 From af333b1838628fa0f8d393b19818224c15427106 Mon Sep 17 00:00:00 2001 From: Amir Bandeali Date: Wed, 14 Feb 2018 13:54:04 -0800 Subject: Fix checks, add contract list to compile script in package.json --- packages/deployer/src/cli.ts | 2 +- packages/deployer/src/compiler.ts | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'packages/deployer/src') diff --git a/packages/deployer/src/cli.ts b/packages/deployer/src/cli.ts index 5e0f2145b..bc1ec8421 100644 --- a/packages/deployer/src/cli.ts +++ b/packages/deployer/src/cli.ts @@ -100,7 +100,7 @@ async function onDeployCommand(argv: CliOptions): Promise { function generateContractsToCompileSet(contracts: string): Set { const contractsToCompile = new Set(); const contractsArray = contracts.split(','); - _.forEach(contracts, contractName => { + _.forEach(contractsArray, contractName => { contractsToCompile.add(contractName); }); return contractsToCompile; diff --git a/packages/deployer/src/compiler.ts b/packages/deployer/src/compiler.ts index 4e5518d0e..beeda1260 100644 --- a/packages/deployer/src/compiler.ts +++ b/packages/deployer/src/compiler.ts @@ -139,6 +139,7 @@ export class Compiler { const contractName = path.basename(contractBaseName, SOLIDITY_FILE_EXTENSION); const currentArtifactPath = `${this._artifactsDir}/${contractName}.json`; const sourceHash = `0x${ethUtil.sha3(source).toString('hex')}`; + const isContractSpecified = this._contractsToCompile.has(ALL_CONTRACTS_IDENTIFIER) || this._contractsToCompile.has(contractName); let currentArtifactString: string; let currentArtifact: ContractArtifact; @@ -156,9 +157,9 @@ export class Compiler { (_.isUndefined(oldNetwork) || oldNetwork.keccak256 !== sourceHash || oldNetwork.optimizer_enabled !== this._optimizerEnabled) && - (this._contractsToCompile.has(ALL_CONTRACTS_IDENTIFIER) || this._contractsToCompile.has(contractName)); + isContractSpecified; } catch (err) { - shouldCompile = true; + shouldCompile = isContractSpecified; } if (!shouldCompile) { -- cgit v1.2.3 From db52ed994111dabe13593280c46afc3bd5f7574e Mon Sep 17 00:00:00 2001 From: Amir Bandeali Date: Wed, 14 Feb 2018 14:06:00 -0800 Subject: Run prettier --- packages/deployer/src/compiler.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'packages/deployer/src') diff --git a/packages/deployer/src/compiler.ts b/packages/deployer/src/compiler.ts index beeda1260..3ff41139e 100644 --- a/packages/deployer/src/compiler.ts +++ b/packages/deployer/src/compiler.ts @@ -139,7 +139,8 @@ export class Compiler { const contractName = path.basename(contractBaseName, SOLIDITY_FILE_EXTENSION); const currentArtifactPath = `${this._artifactsDir}/${contractName}.json`; const sourceHash = `0x${ethUtil.sha3(source).toString('hex')}`; - const isContractSpecified = this._contractsToCompile.has(ALL_CONTRACTS_IDENTIFIER) || this._contractsToCompile.has(contractName); + const isContractSpecified = + this._contractsToCompile.has(ALL_CONTRACTS_IDENTIFIER) || this._contractsToCompile.has(contractName); let currentArtifactString: string; let currentArtifact: ContractArtifact; @@ -155,8 +156,8 @@ export class Compiler { const oldNetwork: ContractData = oldNetworks[this._networkId]; shouldCompile = (_.isUndefined(oldNetwork) || - oldNetwork.keccak256 !== sourceHash || - oldNetwork.optimizer_enabled !== this._optimizerEnabled) && + oldNetwork.keccak256 !== sourceHash || + oldNetwork.optimizer_enabled !== this._optimizerEnabled) && isContractSpecified; } catch (err) { shouldCompile = isContractSpecified; -- cgit v1.2.3 From 060b02eaed2c7e2946286897b79ccfe828efc95d Mon Sep 17 00:00:00 2001 From: Amir Bandeali Date: Thu, 15 Feb 2018 10:20:03 -0800 Subject: Rename variables --- packages/deployer/src/cli.ts | 18 +++++++++--------- packages/deployer/src/compiler.ts | 6 +++--- packages/deployer/src/utils/types.ts | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) (limited to 'packages/deployer/src') diff --git a/packages/deployer/src/cli.ts b/packages/deployer/src/cli.ts index bc1ec8421..3c6d042c0 100644 --- a/packages/deployer/src/cli.ts +++ b/packages/deployer/src/cli.ts @@ -14,7 +14,7 @@ const DEFAULT_ARTIFACTS_DIR = path.resolve('artifacts'); const DEFAULT_NETWORK_ID = 50; const DEFAULT_JSONRPC_PORT = 8545; const DEFAULT_GAS_PRICE = (10 ** 9 * 2).toString(); -const DEFAULT_COMPILE_CONTRACTS = '*'; +const DEFAULT_CONTRACTS_LIST = '*'; /** * Compiles all contracts with options passed in through CLI. @@ -26,7 +26,7 @@ async function onCompileCommand(argv: CliOptions): Promise { networkId: argv.networkId, optimizerEnabled: argv.shouldOptimize ? 1 : 0, artifactsDir: argv.artifactsDir, - contractsToCompile: generateContractsToCompileSet(argv.contracts), + specifiedContracts: getContractsSetFromList(argv.contracts), }; await commands.compileAsync(opts); } @@ -45,7 +45,7 @@ async function onMigrateCommand(argv: CliOptions): Promise { networkId, optimizerEnabled: argv.shouldOptimize ? 1 : 0, artifactsDir: argv.artifactsDir, - contractsToCompile: generateContractsToCompileSet(argv.contracts), + specifiedContracts: getContractsSetFromList(argv.contracts), }; await commands.compileAsync(compilerOpts); @@ -75,7 +75,7 @@ async function onDeployCommand(argv: CliOptions): Promise { networkId, optimizerEnabled: argv.shouldOptimize ? 1 : 0, artifactsDir: argv.artifactsDir, - contractsToCompile: generateContractsToCompileSet(argv.contracts), + specifiedContracts: getContractsSetFromList(argv.contracts), }; await commands.compileAsync(compilerOpts); @@ -97,13 +97,13 @@ async function onDeployCommand(argv: CliOptions): Promise { * Creates a set of contracts to compile. * @param contracts Comma separated list of contracts to compile */ -function generateContractsToCompileSet(contracts: string): Set { - const contractsToCompile = new Set(); +function getContractsSetFromList(contracts: string): Set { + const specifiedContracts = new Set(); const contractsArray = contracts.split(','); _.forEach(contractsArray, contractName => { - contractsToCompile.add(contractName); + specifiedContracts.add(contractName); }); - return contractsToCompile; + return specifiedContracts; } /** * Provides extra required options for deploy command. @@ -162,7 +162,7 @@ function deployCommandBuilder(yargsInstance: any) { }) .option('contracts', { type: 'string', - default: DEFAULT_COMPILE_CONTRACTS, + default: DEFAULT_CONTRACTS_LIST, description: 'comma separated list of contracts to compile', }) .command('compile', 'compile contracts', identityCommandBuilder, onCompileCommand) diff --git a/packages/deployer/src/compiler.ts b/packages/deployer/src/compiler.ts index 3ff41139e..2b0b81c44 100644 --- a/packages/deployer/src/compiler.ts +++ b/packages/deployer/src/compiler.ts @@ -26,7 +26,7 @@ export class Compiler { private _artifactsDir: string; private _contractSourcesIfExists?: ContractSources; private _solcErrors: Set; - private _contractsToCompile: Set; + private _specifiedContracts: Set; /** * Recursively retrieves Solidity source code from directory. * @param dirPath Directory to search. @@ -108,7 +108,7 @@ export class Compiler { this._optimizerEnabled = opts.optimizerEnabled; this._artifactsDir = opts.artifactsDir; this._solcErrors = new Set(); - this._contractsToCompile = opts.contractsToCompile; + this._specifiedContracts = opts.specifiedContracts; } /** * Compiles all Solidity files found in contractsDir and writes JSON artifacts to artifactsDir. @@ -140,7 +140,7 @@ export class Compiler { const currentArtifactPath = `${this._artifactsDir}/${contractName}.json`; const sourceHash = `0x${ethUtil.sha3(source).toString('hex')}`; const isContractSpecified = - this._contractsToCompile.has(ALL_CONTRACTS_IDENTIFIER) || this._contractsToCompile.has(contractName); + this._specifiedContracts.has(ALL_CONTRACTS_IDENTIFIER) || this._specifiedContracts.has(contractName); let currentArtifactString: string; let currentArtifact: ContractArtifact; diff --git a/packages/deployer/src/utils/types.ts b/packages/deployer/src/utils/types.ts index c8bb1b9ca..46481828e 100644 --- a/packages/deployer/src/utils/types.ts +++ b/packages/deployer/src/utils/types.ts @@ -50,7 +50,7 @@ export interface CompilerOptions { networkId: number; optimizerEnabled: number; artifactsDir: string; - contractsToCompile: Set; + specifiedContracts: Set; } export interface DeployerOptions { -- cgit v1.2.3