diff options
author | Alex Browne <stephenalexbrowne@gmail.com> | 2018-09-20 03:09:36 +0800 |
---|---|---|
committer | Alex Browne <stephenalexbrowne@gmail.com> | 2018-12-05 06:23:32 +0800 |
commit | d71fa6535987a0f13900f8e31dbb51772c12fc4f (patch) | |
tree | e2354e5c5b75dc4a48b737d646f5a89821fce48f /packages/pipeline/src/data-sources/etherscan/events.ts | |
parent | 75d3f24835fc68a758cfb44c6bc05095c3e87ad3 (diff) | |
download | dexon-0x-contracts-d71fa6535987a0f13900f8e31dbb51772c12fc4f.tar.gz dexon-0x-contracts-d71fa6535987a0f13900f8e31dbb51772c12fc4f.tar.zst dexon-0x-contracts-d71fa6535987a0f13900f8e31dbb51772c12fc4f.zip |
Make contractAbi a parameter of getContractEventsAsync
Diffstat (limited to 'packages/pipeline/src/data-sources/etherscan/events.ts')
-rw-r--r-- | packages/pipeline/src/data-sources/etherscan/events.ts | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/packages/pipeline/src/data-sources/etherscan/events.ts b/packages/pipeline/src/data-sources/etherscan/events.ts index 3083af267..89b3ffac1 100644 --- a/packages/pipeline/src/data-sources/etherscan/events.ts +++ b/packages/pipeline/src/data-sources/etherscan/events.ts @@ -1,9 +1,7 @@ import { AbiDecoder } from '@0xproject/utils'; -import { DecodedLogArgs, LogEntry, LogWithDecodedArgs } from 'ethereum-types'; +import { AbiDefinition, DecodedLogArgs, LogEntry, LogWithDecodedArgs } from 'ethereum-types'; import * as R from 'ramda'; -import { artifacts } from '../../artifacts'; - // Raw events response from etherescan.io export interface EventsResponse { status: string; @@ -48,16 +46,26 @@ export function _convertResponseToLogEntry(result: EventsResponseResult): LogEnt // Decodes a LogEntry into a LogWithDecodedArgs // tslint:disable-next-line:completed-docs -export function _decodeLogEntry(log: LogEntry): LogWithDecodedArgs<DecodedLogArgs> { - const abiDecoder = new AbiDecoder([artifacts.Exchange.compilerOutput.abi]); +export const _decodeLogEntry = R.curry((contractAbi: AbiDefinition[], log: LogEntry): LogWithDecodedArgs< + DecodedLogArgs +> => { + const abiDecoder = new AbiDecoder([contractAbi]); const logWithDecodedArgs = abiDecoder.tryToDecodeLogOrNoop(log); // tslint:disable-next-line:no-unnecessary-type-assertion return logWithDecodedArgs as LogWithDecodedArgs<DecodedLogArgs>; -} +}); /** * Parses and abi-decodes the raw events response from etherscan.io. + * @param contractAbi The ABI for the contract that the events where emited from. * @param rawEventsResponse The raw events response from etherescan.io. * @returns Parsed and decoded events. */ -export const parseRawEventsResponse = R.pipe(R.map(_convertResponseToLogEntry), R.map(_decodeLogEntry)); +export function parseRawEventsResponse( + contractAbi: AbiDefinition[], + rawEventsResponse: EventsResponse, +): Array<LogWithDecodedArgs<DecodedLogArgs>> { + return R.pipe(R.map(_convertResponseToLogEntry), R.map(_decodeLogEntry(contractAbi)))(rawEventsResponse.result); +} + +// export const parseRawEventsResponse = R.pipe(R.map(_convertResponseToLogEntry), R.map(_decodeLogEntry)); |