aboutsummaryrefslogtreecommitdiffstats
path: root/packages/base-contract/src/index.ts
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-05-11 18:32:57 +0800
committerFabio Berger <me@fabioberger.com>2018-05-11 18:32:57 +0800
commitd370296e82c11d67bbb16a1dc73432c3625682aa (patch)
treec8e5d440bc2b78feae89644c11ba3ed778da6015 /packages/base-contract/src/index.ts
parentf78b5741c3ba3495c066dc800ce62d8a1f3fb75f (diff)
parentf42f608f3f97a5244f09f17ae5ee184c0f775de3 (diff)
downloaddexon-sol-tools-d370296e82c11d67bbb16a1dc73432c3625682aa.tar
dexon-sol-tools-d370296e82c11d67bbb16a1dc73432c3625682aa.tar.gz
dexon-sol-tools-d370296e82c11d67bbb16a1dc73432c3625682aa.tar.bz2
dexon-sol-tools-d370296e82c11d67bbb16a1dc73432c3625682aa.tar.lz
dexon-sol-tools-d370296e82c11d67bbb16a1dc73432c3625682aa.tar.xz
dexon-sol-tools-d370296e82c11d67bbb16a1dc73432c3625682aa.tar.zst
dexon-sol-tools-d370296e82c11d67bbb16a1dc73432c3625682aa.zip
Merge branch 'development' into breakUp0xjs
* development: Fix ganache subprovider config Fix a bug in compiler config precedence Fix linter errors Fix templates Remove unused deployer docs configs Add a legacy endpoint for the deployer Add a check for compiler output Add a comment Put ARTIFACTS_VERSION in a config Improve a comment Remove _applyDefaultsToDeployTxDataAsync Add a HACK comment Fix linter issues Rename deployer to sol-compiler Remove deployer Remove deployer from 0x.js and migrations Configure migrations with a compiler.json Remove deployer from metacoin and contract tests Update wallet footer and add remove token functionality # Conflicts: # .gitignore # packages/0x.js/package.json # packages/0x.js/src/0x.ts # packages/contracts/package.json # packages/contracts/test/multi_sig_with_time_lock.ts # packages/contracts/test/multi_sig_with_time_lock_except_remove_auth_addr.ts # packages/contracts/util/artifacts.ts # packages/deployer/test/deployer_test.ts # packages/migrations/package.json
Diffstat (limited to 'packages/base-contract/src/index.ts')
-rw-r--r--packages/base-contract/src/index.ts43
1 files changed, 36 insertions, 7 deletions
diff --git a/packages/base-contract/src/index.ts b/packages/base-contract/src/index.ts
index e95b18db6..f9298f413 100644
--- a/packages/base-contract/src/index.ts
+++ b/packages/base-contract/src/index.ts
@@ -1,6 +1,7 @@
import {
AbiDefinition,
AbiType,
+ ConstructorAbi,
ContractAbi,
DataItem,
MethodAbi,
@@ -24,6 +25,8 @@ export class BaseContract {
protected _web3Wrapper: Web3Wrapper;
public abi: ContractAbi;
public address: string;
+ public contractName: string;
+ public constructorArgs: any[] = [];
protected static _formatABIDataItemList(
abis: DataItem[],
values: any[],
@@ -37,11 +40,31 @@ export class BaseContract {
protected static _bigNumberToString(type: string, value: any): any {
return _.isObject(value) && value.isBigNumber ? value.toString() : value;
}
+ protected static _lookupConstructorAbi(abi: ContractAbi): ConstructorAbi {
+ const constructorAbiIfExists = _.find(
+ abi,
+ (abiDefinition: AbiDefinition) => abiDefinition.type === AbiType.Constructor,
+ ) as ConstructorAbi | undefined;
+ if (!_.isUndefined(constructorAbiIfExists)) {
+ return constructorAbiIfExists;
+ } else {
+ // If the constructor is not explicitly defined, it won't be included in the ABI. It is
+ // still callable however, so we construct what the ABI would look like were it to exist.
+ const defaultConstructorAbi: ConstructorAbi = {
+ type: AbiType.Constructor,
+ stateMutability: 'nonpayable',
+ payable: false,
+ inputs: [],
+ };
+ return defaultConstructorAbi;
+ }
+ }
protected static _bnToBigNumber(type: string, value: any): any {
return _.isObject(value) && value._bn ? new BigNumber(value.toString()) : value;
}
- protected async _applyDefaultsToTxDataAsync<T extends Partial<TxData | TxDataPayable>>(
+ protected static async _applyDefaultsToTxDataAsync<T extends Partial<TxData | TxDataPayable>>(
txData: T,
+ txDefaults: Partial<TxData>,
estimateGasAsync?: (txData: T) => Promise<number>,
): Promise<TxData> {
// Gas amount sourced with the following priorities:
@@ -49,13 +72,12 @@ export class BaseContract {
// 2. Global config passed in at library instantiation
// 3. Gas estimate calculation + safety margin
const removeUndefinedProperties = _.pickBy;
- const txDataWithDefaults = ({
- to: this.address,
- ...removeUndefinedProperties(this._web3Wrapper.getContractDefaults()),
+ const txDataWithDefaults: TxData = {
+ ...removeUndefinedProperties(txDefaults),
...removeUndefinedProperties(txData as any),
// HACK: TS can't prove that T is spreadable.
// Awaiting https://github.com/Microsoft/TypeScript/pull/13288 to be merged
- } as any) as TxData;
+ } as any;
if (_.isUndefined(txDataWithDefaults.gas) && !_.isUndefined(estimateGasAsync)) {
const estimatedGas = await estimateGasAsync(txData);
txDataWithDefaults.gas = estimatedGas;
@@ -82,8 +104,15 @@ export class BaseContract {
}) as MethodAbi;
return methodAbi;
}
- constructor(abi: ContractAbi, address: string, provider: Provider, defaults?: Partial<TxData>) {
- this._web3Wrapper = new Web3Wrapper(provider, defaults);
+ constructor(
+ contractName: string,
+ abi: ContractAbi,
+ address: string,
+ provider: Provider,
+ txDefaults?: Partial<TxData>,
+ ) {
+ this.contractName = contractName;
+ this._web3Wrapper = new Web3Wrapper(provider, txDefaults);
this.abi = abi;
this.address = address;
const methodAbis = this.abi.filter(