diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-10-03 20:53:23 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-10-04 16:14:19 +0800 |
commit | 0a12fa7f4e83562d48e143c30cb59645aa6b9b7a (patch) | |
tree | 748af069300d6840e14ba8e67912de2aa1f86ddb | |
parent | 87374d7f46b6365078d20e8e0660520080facebe (diff) | |
download | dexon-sol-tools-0a12fa7f4e83562d48e143c30cb59645aa6b9b7a.tar dexon-sol-tools-0a12fa7f4e83562d48e143c30cb59645aa6b9b7a.tar.gz dexon-sol-tools-0a12fa7f4e83562d48e143c30cb59645aa6b9b7a.tar.bz2 dexon-sol-tools-0a12fa7f4e83562d48e143c30cb59645aa6b9b7a.tar.lz dexon-sol-tools-0a12fa7f4e83562d48e143c30cb59645aa6b9b7a.tar.xz dexon-sol-tools-0a12fa7f4e83562d48e143c30cb59645aa6b9b7a.tar.zst dexon-sol-tools-0a12fa7f4e83562d48e143c30cb59645aa6b9b7a.zip |
Implement getLogsAsync on token contract
-rw-r--r-- | src/contract_wrappers/contract_wrapper.ts | 2 | ||||
-rw-r--r-- | src/contract_wrappers/token_wrapper.ts | 23 |
2 files changed, 22 insertions, 3 deletions
diff --git a/src/contract_wrappers/contract_wrapper.ts b/src/contract_wrappers/contract_wrapper.ts index bc65f692d..0c8864ee1 100644 --- a/src/contract_wrappers/contract_wrapper.ts +++ b/src/contract_wrappers/contract_wrapper.ts @@ -12,7 +12,7 @@ export class ContractWrapper { this._web3Wrapper = web3Wrapper; this._abiDecoder = abiDecoder; } - protected tryToDecodeLogOrNoOp(log: Web3.LogEntry): LogWithDecodedArgs|RawLog { + protected _tryToDecodeLogOrNoOp(log: Web3.LogEntry): LogWithDecodedArgs|RawLog { if (_.isUndefined(this._abiDecoder)) { throw new Error(ZeroExError.NoAbiDecoder); } 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<string>; - constructor(web3Wrapper: Web3Wrapper, tokenTransferProxyContractAddressFetcher: () => Promise<string>) { - super(web3Wrapper); + constructor(web3Wrapper: Web3Wrapper, abiDecoder: AbiDecoder, + tokenTransferProxyContractAddressFetcher: () => Promise<string>) { + 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<Array<LogWithDecodedArgs|RawLog>> { + // 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 */ |