diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-10-04 16:51:36 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-10-04 16:51:36 +0800 |
commit | f65bfc1ab1425e4866b5b7b7ecf2a30e0eb018a7 (patch) | |
tree | a23df51dcfe0f5273a54d8e5e1f8e3b0a56d8645 | |
parent | f26d49f077a9a8b606159f22c05aaf2601dc8f57 (diff) | |
download | dexon-sol-tools-f65bfc1ab1425e4866b5b7b7ecf2a30e0eb018a7.tar dexon-sol-tools-f65bfc1ab1425e4866b5b7b7ecf2a30e0eb018a7.tar.gz dexon-sol-tools-f65bfc1ab1425e4866b5b7b7ecf2a30e0eb018a7.tar.bz2 dexon-sol-tools-f65bfc1ab1425e4866b5b7b7ecf2a30e0eb018a7.tar.lz dexon-sol-tools-f65bfc1ab1425e4866b5b7b7ecf2a30e0eb018a7.tar.xz dexon-sol-tools-f65bfc1ab1425e4866b5b7b7ecf2a30e0eb018a7.tar.zst dexon-sol-tools-f65bfc1ab1425e4866b5b7b7ecf2a30e0eb018a7.zip |
Extract topics to its variable
-rw-r--r-- | src/contract_wrappers/contract_wrapper.ts | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/src/contract_wrappers/contract_wrapper.ts b/src/contract_wrappers/contract_wrapper.ts index d6c7d915a..921b5a6c2 100644 --- a/src/contract_wrappers/contract_wrapper.ts +++ b/src/contract_wrappers/contract_wrapper.ts @@ -24,22 +24,25 @@ export class ContractWrapper { indexFilterValues: IndexedFilterValues, abi: Web3.ContractAbi): Promise<LogWithDecodedArgs[]> { // TODO include indexFilterValues in topics - const eventSignature = this._getEventSignatureFromAbiByName(abi, eventName); + const eventAbi = _.filter(abi, {name: eventName})[0] as Web3.EventAbi; + const eventSignature = this._getEventSignatureFromAbiByName(eventAbi, eventName); + const topicForEventSignature = this._web3Wrapper.keccak256(eventSignature); + const topics = [topicForEventSignature]; const filter = { fromBlock: subscriptionOpts.fromBlock, toBlock: subscriptionOpts.toBlock, address, - topics: [this._web3Wrapper.keccak256(eventSignature)], + topics, }; const logs = await this._web3Wrapper.getLogsAsync(filter); - const logsWithDecodedArguments = _.map(logs, this._tryToDecodeLogOrNoOp.bind(this)); + const logsWithDecodedArguments = _.map(logs, this._tryToDecodeLogOrNoop.bind(this)); return logsWithDecodedArguments; } - protected _tryToDecodeLogOrNoOp(log: Web3.LogEntry): LogWithDecodedArgs|RawLog { + protected _tryToDecodeLogOrNoop(log: Web3.LogEntry): LogWithDecodedArgs|RawLog { if (_.isUndefined(this._abiDecoder)) { throw new Error(ZeroExError.NoAbiDecoder); } - const logWithDecodedArgs = this._abiDecoder.tryToDecodeLogOrNoOp(log); + const logWithDecodedArgs = this._abiDecoder.tryToDecodeLogOrNoop(log); return logWithDecodedArgs; } protected async _instantiateContractIfExistsAsync<A extends Web3.ContractInstance>(artifact: Artifact, @@ -49,8 +52,7 @@ 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; + protected _getEventSignatureFromAbiByName(eventAbi: Web3.EventAbi, eventName: ContractEvents): string { const types = _.map(eventAbi.inputs, 'type'); const signature = `${eventAbi.name}(${types.join(',')})`; return signature; |