diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-10-03 20:51:52 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-10-04 16:14:19 +0800 |
commit | efa85f844bcf59aa63d940a89d5899462239878a (patch) | |
tree | 7a06b85d2fcd1a2f149f7c24364eb2e1c8372d0d /src | |
parent | db08896274699aaf967751927dcacd0c21e3aaaf (diff) | |
download | dexon-0x-contracts-efa85f844bcf59aa63d940a89d5899462239878a.tar.gz dexon-0x-contracts-efa85f844bcf59aa63d940a89d5899462239878a.tar.zst dexon-0x-contracts-efa85f844bcf59aa63d940a89d5899462239878a.zip |
Add tryToDecodeLogOrNoOp and _getEventSignatureFromAbiByName on contract_wrapper
Diffstat (limited to 'src')
-rw-r--r-- | src/contract_wrappers/contract_wrapper.ts | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/src/contract_wrappers/contract_wrapper.ts b/src/contract_wrappers/contract_wrapper.ts index 2a55b53d9..bc65f692d 100644 --- a/src/contract_wrappers/contract_wrapper.ts +++ b/src/contract_wrappers/contract_wrapper.ts @@ -1,13 +1,23 @@ import * as _ from 'lodash'; import * as Web3 from 'web3'; import {Web3Wrapper} from '../web3_wrapper'; -import {ZeroExError, Artifact} from '../types'; +import {AbiDecoder} from '../utils/abi_decoder'; +import {ZeroExError, Artifact, LogWithDecodedArgs, RawLog, ContractEvents} from '../types'; import {utils} from '../utils/utils'; export class ContractWrapper { protected _web3Wrapper: Web3Wrapper; - constructor(web3Wrapper: Web3Wrapper) { + private _abiDecoder?: AbiDecoder; + constructor(web3Wrapper: Web3Wrapper, abiDecoder?: AbiDecoder) { this._web3Wrapper = web3Wrapper; + this._abiDecoder = abiDecoder; + } + protected tryToDecodeLogOrNoOp(log: Web3.LogEntry): LogWithDecodedArgs|RawLog { + if (_.isUndefined(this._abiDecoder)) { + throw new Error(ZeroExError.NoAbiDecoder); + } + const logWithDecodedArgs = this._abiDecoder.tryToDecodeLogOrNoOp(log); + return logWithDecodedArgs; } protected async _instantiateContractIfExistsAsync<A extends Web3.ContractInstance>(artifact: Artifact, addressIfExists?: string, @@ -16,4 +26,10 @@ export class ContractWrapper { await this._web3Wrapper.getContractInstanceFromArtifactAsync<A>(artifact, addressIfExists); return contractInstance; } + protected _getEventSignatureFromAbiByName(abi: Web3.ContractAbi, eventName: ContractEvents): string { + const eventAbi = _.filter(abi, {name: eventName})[0] as Web3.EventAbi; + const types = _.map(eventAbi.inputs, 'type'); + const signature = `${eventAbi.name}(${types.join(',')})`; + return signature; + } } |