diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-10-03 21:37:09 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-10-04 16:14:19 +0800 |
commit | e6c138be5ab56856a454f7f04b6e1e54f1d41f18 (patch) | |
tree | cc8d06745192794fdacfc2430a4d940a560b38c2 /src/contract_wrappers/contract_wrapper.ts | |
parent | 087645e59fb78a1ce20bbbcabe12317f11324e93 (diff) | |
download | dexon-0x-contracts-e6c138be5ab56856a454f7f04b6e1e54f1d41f18.tar.gz dexon-0x-contracts-e6c138be5ab56856a454f7f04b6e1e54f1d41f18.tar.zst dexon-0x-contracts-e6c138be5ab56856a454f7f04b6e1e54f1d41f18.zip |
Add _getLogsAsync on contract_wrapper
Diffstat (limited to 'src/contract_wrappers/contract_wrapper.ts')
-rw-r--r-- | src/contract_wrappers/contract_wrapper.ts | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/src/contract_wrappers/contract_wrapper.ts b/src/contract_wrappers/contract_wrapper.ts index 0c8864ee1..6b2517fc9 100644 --- a/src/contract_wrappers/contract_wrapper.ts +++ b/src/contract_wrappers/contract_wrapper.ts @@ -2,7 +2,15 @@ import * as _ from 'lodash'; import * as Web3 from 'web3'; import {Web3Wrapper} from '../web3_wrapper'; import {AbiDecoder} from '../utils/abi_decoder'; -import {ZeroExError, Artifact, LogWithDecodedArgs, RawLog, ContractEvents} from '../types'; +import { + ZeroExError, + Artifact, + LogWithDecodedArgs, + RawLog, + ContractEvents, + SubscriptionOpts, + IndexedFilterValues, +} from '../types'; import {utils} from '../utils/utils'; export class ContractWrapper { @@ -12,6 +20,21 @@ export class ContractWrapper { this._web3Wrapper = web3Wrapper; this._abiDecoder = abiDecoder; } + protected async _getLogsAsync(address: string, eventName: ContractEvents, subscriptionOpts: SubscriptionOpts, + indexFilterValues: IndexedFilterValues, + abi: Web3.ContractAbi): Promise<Array<LogWithDecodedArgs|RawLog>> { + // TODO include indexFilterValues in topics + const eventSignature = this._getEventSignatureFromAbiByName(abi, eventName); + const filter = { + fromBlock: subscriptionOpts.fromBlock, + toBlock: subscriptionOpts.toBlock, + address, + topics: [this._web3Wrapper.keccak256(eventSignature)], + }; + const logs = await this._web3Wrapper.getLogsAsync(filter); + const logsWithDecodedArguments = _.map(logs, this._tryToDecodeLogOrNoOp.bind(this)); + return logsWithDecodedArguments; + } protected _tryToDecodeLogOrNoOp(log: Web3.LogEntry): LogWithDecodedArgs|RawLog { if (_.isUndefined(this._abiDecoder)) { throw new Error(ZeroExError.NoAbiDecoder); |