aboutsummaryrefslogtreecommitdiffstats
path: root/packages/base-contract
diff options
context:
space:
mode:
authorGreg Hysen <greg.hysen@gmail.com>2018-04-04 08:39:55 +0800
committerGreg Hysen <greg.hysen@gmail.com>2018-04-10 08:22:58 +0800
commit61fc3346c2fe2adc33dfe84aa50780d61e10efdf (patch)
tree1f5ab2cddf7093db8f8fb419ef70da66a9997c7b /packages/base-contract
parent073bf738ddb271b6b4158798baf4cac3cb0608e9 (diff)
downloaddexon-sol-tools-61fc3346c2fe2adc33dfe84aa50780d61e10efdf.tar
dexon-sol-tools-61fc3346c2fe2adc33dfe84aa50780d61e10efdf.tar.gz
dexon-sol-tools-61fc3346c2fe2adc33dfe84aa50780d61e10efdf.tar.bz2
dexon-sol-tools-61fc3346c2fe2adc33dfe84aa50780d61e10efdf.tar.lz
dexon-sol-tools-61fc3346c2fe2adc33dfe84aa50780d61e10efdf.tar.xz
dexon-sol-tools-61fc3346c2fe2adc33dfe84aa50780d61e10efdf.tar.zst
dexon-sol-tools-61fc3346c2fe2adc33dfe84aa50780d61e10efdf.zip
Updated deployer to accept a list of contract directories as input. Contract directories are namespaced to a void clashes. Also in this commit is a fix for overloading contract functions.
Diffstat (limited to 'packages/base-contract')
-rw-r--r--packages/base-contract/src/index.ts51
1 files changed, 47 insertions, 4 deletions
diff --git a/packages/base-contract/src/index.ts b/packages/base-contract/src/index.ts
index bba686f8b..f6cea53fa 100644
--- a/packages/base-contract/src/index.ts
+++ b/packages/base-contract/src/index.ts
@@ -1,13 +1,26 @@
-import { ContractAbi, DataItem, Provider, TxData, TxDataPayable } from '@0xproject/types';
-import { BigNumber } from '@0xproject/utils';
+import {
+ AbiDefinition,
+ AbiType,
+ ContractAbi,
+ DataItem,
+ MethodAbi,
+ Provider,
+ TxData,
+ TxDataPayable,
+} from '@0xproject/types';
+import { abiUtils, BigNumber } from '@0xproject/utils';
import { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as ethersContracts from 'ethers-contracts';
import * as _ from 'lodash';
import { formatABIDataItem } from './utils';
+export interface EthersInterfaceByFunctionSignature {
+ [key: string]: ethersContracts.Interface;
+}
+
export class BaseContract {
- protected _ethersInterface: ethersContracts.Interface;
+ protected _ethersInterfacesByFunctionSignature: EthersInterfaceByFunctionSignature;
protected _web3Wrapper: Web3Wrapper;
public abi: ContractAbi;
public address: string;
@@ -49,10 +62,40 @@ export class BaseContract {
}
return txDataWithDefaults;
}
+ protected _lookupEthersInterface(functionSignature: string): ethersContracts.Interface {
+ const ethersInterface = this._ethersInterfacesByFunctionSignature[functionSignature];
+ if (_.isUndefined(ethersInterface)) {
+ throw new Error(`Failed to lookup method with function signature '${functionSignature}'`);
+ }
+ return ethersInterface;
+ }
+ protected _lookupAbi(functionSignature: string): MethodAbi {
+ const methodAbi = _.find(this.abi, (abiDefinition: AbiDefinition) => {
+ if (abiDefinition.type !== AbiType.Function) {
+ return false;
+ }
+ const abiFunctionSignature = abiUtils.getFunctionSignature(abiDefinition);
+ if (abiFunctionSignature === functionSignature) {
+ return true;
+ }
+ return false;
+ }) as MethodAbi;
+ return methodAbi;
+ }
constructor(abi: ContractAbi, address: string, provider: Provider, defaults?: Partial<TxData>) {
this._web3Wrapper = new Web3Wrapper(provider, defaults);
this.abi = abi;
this.address = address;
- this._ethersInterface = new ethersContracts.Interface(abi);
+ const methodAbis = this.abi.filter(
+ (abiDefinition: AbiDefinition) => abiDefinition.type === AbiType.Function,
+ ) as MethodAbi[];
+ this._ethersInterfacesByFunctionSignature = _.transform(
+ methodAbis,
+ (result: EthersInterfaceByFunctionSignature, methodAbi) => {
+ const functionSignature = abiUtils.getFunctionSignature(methodAbi);
+ result[functionSignature] = new ethersContracts.Interface([methodAbi]);
+ },
+ {},
+ );
}
}