diff options
author | Greg Hysen <greg.hysen@gmail.com> | 2018-12-18 10:26:03 +0800 |
---|---|---|
committer | Greg Hysen <greg.hysen@gmail.com> | 2019-01-15 02:49:29 +0800 |
commit | 285fb3deadd0413bf993557575a3f96a840f0e10 (patch) | |
tree | 8970de6db324e3773146f61265e0b44d03976a60 /packages/base-contract | |
parent | 797d7c7878e33ce012259a6a5db5335e9dc838ba (diff) | |
download | dexon-sol-tools-285fb3deadd0413bf993557575a3f96a840f0e10.tar dexon-sol-tools-285fb3deadd0413bf993557575a3f96a840f0e10.tar.gz dexon-sol-tools-285fb3deadd0413bf993557575a3f96a840f0e10.tar.bz2 dexon-sol-tools-285fb3deadd0413bf993557575a3f96a840f0e10.tar.lz dexon-sol-tools-285fb3deadd0413bf993557575a3f96a840f0e10.tar.xz dexon-sol-tools-285fb3deadd0413bf993557575a3f96a840f0e10.tar.zst dexon-sol-tools-285fb3deadd0413bf993557575a3f96a840f0e10.zip |
Progress
Diffstat (limited to 'packages/base-contract')
-rw-r--r-- | packages/base-contract/src/index.ts | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/packages/base-contract/src/index.ts b/packages/base-contract/src/index.ts index fbb8478b7..2fd50b941 100644 --- a/packages/base-contract/src/index.ts +++ b/packages/base-contract/src/index.ts @@ -16,8 +16,10 @@ import * as _ from 'lodash'; import { formatABIDataItem } from './utils'; -export interface EthersInterfaceByFunctionSignature { - [key: string]: ethers.utils.Interface; +import { AbiEncoder } from '@0x/utils'; + +export interface AbiEncoderByFunctionSignature { + [key: string]: AbiEncoder.Method; } const REVERT_ERROR_SELECTOR = '08c379a0'; @@ -26,7 +28,7 @@ const REVERT_ERROR_SELECTOR_BYTES_LENGTH = 4; const REVERT_ERROR_SELECTOR_END = REVERT_ERROR_SELECTOR_OFFSET + REVERT_ERROR_SELECTOR_BYTES_LENGTH * 2; export class BaseContract { - protected _ethersInterfacesByFunctionSignature: EthersInterfaceByFunctionSignature; + protected _abiEncoderByFunctionSignature: AbiEncoderByFunctionSignature; protected _web3Wrapper: Web3Wrapper; public abi: ContractAbi; public address: string; @@ -117,12 +119,12 @@ export class BaseContract { } } } - protected _lookupEthersInterface(functionSignature: string): ethers.utils.Interface { - const ethersInterface = this._ethersInterfacesByFunctionSignature[functionSignature]; - if (_.isUndefined(ethersInterface)) { + protected _lookupAbiEncoder(functionSignature: string): AbiEncoder.Method { + const abiEncoder = this._abiEncoderByFunctionSignature[functionSignature]; + if (_.isUndefined(abiEncoder)) { throw new Error(`Failed to lookup method with function signature '${functionSignature}'`); } - return ethersInterface; + return abiEncoder; } protected _lookupAbi(functionSignature: string): MethodAbi { const methodAbi = _.find(this.abi, (abiDefinition: AbiDefinition) => { @@ -130,7 +132,7 @@ export class BaseContract { return false; } // tslint:disable-next-line:no-unnecessary-type-assertion - const abiFunctionSignature = abiUtils.getFunctionSignature(abiDefinition as MethodAbi); + const abiFunctionSignature = new AbiEncoder.Method(abiDefinition as MethodAbi).getSignature(); if (abiFunctionSignature === functionSignature) { return true; } @@ -152,10 +154,11 @@ export class BaseContract { const methodAbis = this.abi.filter( (abiDefinition: AbiDefinition) => abiDefinition.type === AbiType.Function, ) as MethodAbi[]; - this._ethersInterfacesByFunctionSignature = {}; + this._abiEncoderByFunctionSignature = {}; _.each(methodAbis, methodAbi => { - const functionSignature = abiUtils.getFunctionSignature(methodAbi); - this._ethersInterfacesByFunctionSignature[functionSignature] = new ethers.utils.Interface([methodAbi]); + const abiEncoder = new AbiEncoder.Method(methodAbi); + const functionSignature = abiEncoder.getSignature(); + this._abiEncoderByFunctionSignature[functionSignature] = abiEncoder; }); } } |