From 0a12fa7f4e83562d48e143c30cb59645aa6b9b7a Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 3 Oct 2017 15:53:23 +0300 Subject: Implement getLogsAsync on token contract --- src/contract_wrappers/token_wrapper.ts | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'src/contract_wrappers/token_wrapper.ts') diff --git a/src/contract_wrappers/token_wrapper.ts b/src/contract_wrappers/token_wrapper.ts index f7f0a0ce3..04c03edbd 100644 --- a/src/contract_wrappers/token_wrapper.ts +++ b/src/contract_wrappers/token_wrapper.ts @@ -7,6 +7,7 @@ import {utils} from '../utils/utils'; import {eventUtils} from '../utils/event_utils'; import {constants} from '../utils/constants'; import {ContractWrapper} from './contract_wrapper'; +import {AbiDecoder} from '../utils/abi_decoder'; import {artifacts} from '../artifacts'; import { TokenContract, @@ -18,6 +19,8 @@ import { ContractEventEmitter, ContractEventObj, MethodOpts, + LogWithDecodedArgs, + RawLog, } from '../types'; const ALLOWANCE_TO_ZERO_GAS_AMOUNT = 47155; @@ -32,8 +35,9 @@ export class TokenWrapper extends ContractWrapper { private _tokenContractsByAddress: {[address: string]: TokenContract}; private _tokenLogEventEmitters: ContractEventEmitter[]; private _tokenTransferProxyContractAddressFetcher: () => Promise; - constructor(web3Wrapper: Web3Wrapper, tokenTransferProxyContractAddressFetcher: () => Promise) { - super(web3Wrapper); + constructor(web3Wrapper: Web3Wrapper, abiDecoder: AbiDecoder, + tokenTransferProxyContractAddressFetcher: () => Promise) { + super(web3Wrapper, abiDecoder); this._tokenContractsByAddress = {}; this._tokenLogEventEmitters = []; this._tokenTransferProxyContractAddressFetcher = tokenTransferProxyContractAddressFetcher; @@ -276,6 +280,21 @@ export class TokenWrapper extends ContractWrapper { this._tokenLogEventEmitters.push(eventEmitter); return eventEmitter; } + public async getLogsAsync(tokenAddress: string, eventName: TokenEvents, + subscriptionOpts: SubscriptionOpts, + indexFilterValues: IndexedFilterValues): Promise> { + // TODO include indexFilterValues in topics + const eventSignature = this._getEventSignatureFromAbiByName(artifacts.TokenArtifact.abi, eventName); + const filter = { + fromBlock: subscriptionOpts.fromBlock, + toBlock: subscriptionOpts.toBlock, + address: tokenAddress, + topics: [this._web3Wrapper.keccak256(eventSignature)], + }; + const logs = await this._web3Wrapper.getLogsAsync(filter); + const logsWithDecodedArguments = _.map(logs, this._tryToDecodeLogOrNoOp.bind(this)); + return logsWithDecodedArguments; + } /** * Stops watching for all token events */ -- cgit v1.2.3 From e6c138be5ab56856a454f7f04b6e1e54f1d41f18 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 3 Oct 2017 16:37:09 +0300 Subject: Add _getLogsAsync on contract_wrapper --- src/contract_wrappers/token_wrapper.ts | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) (limited to 'src/contract_wrappers/token_wrapper.ts') diff --git a/src/contract_wrappers/token_wrapper.ts b/src/contract_wrappers/token_wrapper.ts index 04c03edbd..b932686d4 100644 --- a/src/contract_wrappers/token_wrapper.ts +++ b/src/contract_wrappers/token_wrapper.ts @@ -280,20 +280,12 @@ export class TokenWrapper extends ContractWrapper { this._tokenLogEventEmitters.push(eventEmitter); return eventEmitter; } - public async getLogsAsync(tokenAddress: string, eventName: TokenEvents, - subscriptionOpts: SubscriptionOpts, + public async getLogsAsync(tokenAddress: string, eventName: TokenEvents, subscriptionOpts: SubscriptionOpts, indexFilterValues: IndexedFilterValues): Promise> { - // TODO include indexFilterValues in topics - const eventSignature = this._getEventSignatureFromAbiByName(artifacts.TokenArtifact.abi, eventName); - const filter = { - fromBlock: subscriptionOpts.fromBlock, - toBlock: subscriptionOpts.toBlock, - address: tokenAddress, - topics: [this._web3Wrapper.keccak256(eventSignature)], - }; - const logs = await this._web3Wrapper.getLogsAsync(filter); - const logsWithDecodedArguments = _.map(logs, this._tryToDecodeLogOrNoOp.bind(this)); - return logsWithDecodedArguments; + const logs = await this._getLogsAsync( + tokenAddress, eventName, subscriptionOpts, indexFilterValues, artifacts.TokenArtifact.abi, + ); + return logs; } /** * Stops watching for all token events -- cgit v1.2.3 From 837618c7a016b9b66d70f3c0e9682c97a9d4cf8a Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 3 Oct 2017 16:44:16 +0300 Subject: Implement zeroEx.exchange.getLogsAsync --- src/contract_wrappers/token_wrapper.ts | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/contract_wrappers/token_wrapper.ts') diff --git a/src/contract_wrappers/token_wrapper.ts b/src/contract_wrappers/token_wrapper.ts index b932686d4..175671f74 100644 --- a/src/contract_wrappers/token_wrapper.ts +++ b/src/contract_wrappers/token_wrapper.ts @@ -280,6 +280,15 @@ export class TokenWrapper extends ContractWrapper { this._tokenLogEventEmitters.push(eventEmitter); return eventEmitter; } + /** + * Gets historical logs without creating a subscription + * @param tokenAddress An address of the token that emited the logs. + * @param eventName The token contract event you would like to subscribe to. + * @param subscriptionOpts Subscriptions options that let you configure the subscription. + * @param indexFilterValues An object where the keys are indexed args returned by the event and + * the value is the value you are interested in. E.g `{_from: aUserAddressHex}` + * @return Array of logs that match the parameters + */ public async getLogsAsync(tokenAddress: string, eventName: TokenEvents, subscriptionOpts: SubscriptionOpts, indexFilterValues: IndexedFilterValues): Promise> { const logs = await this._getLogsAsync( -- cgit v1.2.3 From 451ded4963aaaa40ff4d00bcb0d589b06b45ce24 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 3 Oct 2017 19:05:44 +0300 Subject: Add tests for zeroEx.exchange.getLogsAsync --- src/contract_wrappers/token_wrapper.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/contract_wrappers/token_wrapper.ts') diff --git a/src/contract_wrappers/token_wrapper.ts b/src/contract_wrappers/token_wrapper.ts index 175671f74..95f5491c9 100644 --- a/src/contract_wrappers/token_wrapper.ts +++ b/src/contract_wrappers/token_wrapper.ts @@ -290,7 +290,7 @@ export class TokenWrapper extends ContractWrapper { * @return Array of logs that match the parameters */ public async getLogsAsync(tokenAddress: string, eventName: TokenEvents, subscriptionOpts: SubscriptionOpts, - indexFilterValues: IndexedFilterValues): Promise> { + indexFilterValues: IndexedFilterValues): Promise { const logs = await this._getLogsAsync( tokenAddress, eventName, subscriptionOpts, indexFilterValues, artifacts.TokenArtifact.abi, ); -- cgit v1.2.3 From 2b9418b7009a54c5943dd42b34db8f82ddf50e99 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Wed, 4 Oct 2017 11:54:34 +0300 Subject: Fix a typo --- src/contract_wrappers/token_wrapper.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/contract_wrappers/token_wrapper.ts') diff --git a/src/contract_wrappers/token_wrapper.ts b/src/contract_wrappers/token_wrapper.ts index 95f5491c9..91af223e4 100644 --- a/src/contract_wrappers/token_wrapper.ts +++ b/src/contract_wrappers/token_wrapper.ts @@ -282,7 +282,7 @@ export class TokenWrapper extends ContractWrapper { } /** * Gets historical logs without creating a subscription - * @param tokenAddress An address of the token that emited the logs. + * @param tokenAddress An address of the token that emmited the logs. * @param eventName The token contract event you would like to subscribe to. * @param subscriptionOpts Subscriptions options that let you configure the subscription. * @param indexFilterValues An object where the keys are indexed args returned by the event and -- cgit v1.2.3