aboutsummaryrefslogtreecommitdiffstats
path: root/packages/deployer/src/deployer.ts
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2018-04-19 04:22:39 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2018-05-07 16:23:08 +0800
commit72b2a1c66fa9fb85ea8515645b97332eee204550 (patch)
tree8a4504ea2fdbc554f5b62f2b46088bea3e5b6324 /packages/deployer/src/deployer.ts
parent69a6166b6a1d39afc24b8dd950ec5d8539a03420 (diff)
downloaddexon-sol-tools-72b2a1c66fa9fb85ea8515645b97332eee204550.tar
dexon-sol-tools-72b2a1c66fa9fb85ea8515645b97332eee204550.tar.gz
dexon-sol-tools-72b2a1c66fa9fb85ea8515645b97332eee204550.tar.bz2
dexon-sol-tools-72b2a1c66fa9fb85ea8515645b97332eee204550.tar.lz
dexon-sol-tools-72b2a1c66fa9fb85ea8515645b97332eee204550.tar.xz
dexon-sol-tools-72b2a1c66fa9fb85ea8515645b97332eee204550.tar.zst
dexon-sol-tools-72b2a1c66fa9fb85ea8515645b97332eee204550.zip
Implement new artifacts format
Diffstat (limited to 'packages/deployer/src/deployer.ts')
-rw-r--r--packages/deployer/src/deployer.ts48
1 files changed, 23 insertions, 25 deletions
diff --git a/packages/deployer/src/deployer.ts b/packages/deployer/src/deployer.ts
index ad05417b1..fe959e405 100644
--- a/packages/deployer/src/deployer.ts
+++ b/packages/deployer/src/deployer.ts
@@ -2,6 +2,7 @@ import { AbiType, ConstructorAbi, ContractAbi, Provider, TxData } from '@0xproje
import { logUtils } from '@0xproject/utils';
import { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as _ from 'lodash';
+import * as solc from 'solc';
import * as Web3 from 'web3';
import { Contract } from './utils/contract';
@@ -28,7 +29,20 @@ export class Deployer {
private _artifactsDir: string;
private _networkId: number;
private _defaults: Partial<TxData>;
-
+ /**
+ * Gets data for current version stored in artifact.
+ * @param contractArtifact The contract artifact.
+ * @return Version specific contract data.
+ */
+ private static _getContractCompilerOutputFromArtifactIfExists(
+ contractArtifact: ContractArtifact,
+ ): solc.StandardContractOutput {
+ const compilerOutputIfExists = contractArtifact.compilerOutput;
+ if (_.isUndefined(compilerOutputIfExists)) {
+ throw new Error(`Compiler output not found in artifact for contract: ${contractArtifact.contractName}`);
+ }
+ return compilerOutputIfExists;
+ }
/**
* Instantiate a new instance of the Deployer class.
* @param opts Deployer options, including either an RPC url or Provider instance.
@@ -58,10 +72,8 @@ export class Deployer {
*/
public async deployAsync(contractName: string, args: any[] = []): Promise<Web3.ContractInstance> {
const contractArtifactIfExists: ContractArtifact = this._loadContractArtifactIfExists(contractName);
- const contractNetworkDataIfExists: ContractNetworkData = this._getContractNetworkDataFromArtifactIfExists(
- contractArtifactIfExists,
- );
- const data = contractNetworkDataIfExists.bytecode;
+ const compilerOutput = Deployer._getContractCompilerOutputFromArtifactIfExists(contractArtifactIfExists);
+ const data = compilerOutput.evm.bytecode.object;
const from = await this._getFromAddressAsync();
const gas = await this._getAllowableGasEstimateAsync(data);
const txData = {
@@ -70,7 +82,7 @@ export class Deployer {
data,
gas,
};
- const abi = contractNetworkDataIfExists.abi;
+ const abi = compilerOutput.abi;
const constructorAbi = _.find(abi, { type: AbiType.Constructor }) as ConstructorAbi;
const constructorArgs = _.isUndefined(constructorAbi) ? [] : constructorAbi.inputs;
if (constructorArgs.length !== args.length) {
@@ -138,15 +150,13 @@ export class Deployer {
args: any[],
): Promise<void> {
const contractArtifactIfExists: ContractArtifact = this._loadContractArtifactIfExists(contractName);
- const contractNetworkDataIfExists: ContractNetworkData = this._getContractNetworkDataFromArtifactIfExists(
- contractArtifactIfExists,
- );
- const abi = contractNetworkDataIfExists.abi;
+ const compilerOutput = Deployer._getContractCompilerOutputFromArtifactIfExists(contractArtifactIfExists);
+ const abi = compilerOutput.abi;
const encodedConstructorArgs = encoder.encodeConstructorArgsFromAbi(args, abi);
- const newContractData = {
- ...contractNetworkDataIfExists,
+ const newContractData: ContractNetworkData = {
address: contractAddress,
- constructor_args: encodedConstructorArgs,
+ links: {},
+ constructorArgs: encodedConstructorArgs,
};
const newArtifact = {
...contractArtifactIfExists,
@@ -174,18 +184,6 @@ export class Deployer {
}
}
/**
- * Gets data for current networkId stored in artifact.
- * @param contractArtifact The contract artifact.
- * @return Network specific contract data.
- */
- private _getContractNetworkDataFromArtifactIfExists(contractArtifact: ContractArtifact): ContractNetworkData {
- const contractNetworkDataIfExists = contractArtifact.networks[this._networkId];
- if (_.isUndefined(contractNetworkDataIfExists)) {
- throw new Error(`Data not found in artifact for contract: ${contractArtifact.contract_name}`);
- }
- return contractNetworkDataIfExists;
- }
- /**
* Gets the address to use for sending a transaction.
* @return The default from address. If not specified, returns the first address accessible by web3.
*/