aboutsummaryrefslogtreecommitdiffstats
path: root/packages/pipeline/src/data-sources/etherscan/events.ts
diff options
context:
space:
mode:
authorAlex Browne <stephenalexbrowne@gmail.com>2018-09-20 02:25:46 +0800
committerAlex Browne <stephenalexbrowne@gmail.com>2018-12-05 06:23:32 +0800
commit2b7f94c00f7fd38cfaa50540c6bef8237306c064 (patch)
treebb759b1161d3bc8a12382dce6814b3d2cf26dd0a /packages/pipeline/src/data-sources/etherscan/events.ts
parentcd73a047efbc1b7afa884ef27a1cc4991e20efd8 (diff)
downloaddexon-sol-tools-2b7f94c00f7fd38cfaa50540c6bef8237306c064.tar
dexon-sol-tools-2b7f94c00f7fd38cfaa50540c6bef8237306c064.tar.gz
dexon-sol-tools-2b7f94c00f7fd38cfaa50540c6bef8237306c064.tar.bz2
dexon-sol-tools-2b7f94c00f7fd38cfaa50540c6bef8237306c064.tar.lz
dexon-sol-tools-2b7f94c00f7fd38cfaa50540c6bef8237306c064.tar.xz
dexon-sol-tools-2b7f94c00f7fd38cfaa50540c6bef8237306c064.tar.zst
dexon-sol-tools-2b7f94c00f7fd38cfaa50540c6bef8237306c064.zip
Restructure pipeline package. Create data-sources dir
Diffstat (limited to 'packages/pipeline/src/data-sources/etherscan/events.ts')
-rw-r--r--packages/pipeline/src/data-sources/etherscan/events.ts54
1 files changed, 54 insertions, 0 deletions
diff --git a/packages/pipeline/src/data-sources/etherscan/events.ts b/packages/pipeline/src/data-sources/etherscan/events.ts
new file mode 100644
index 000000000..50962a266
--- /dev/null
+++ b/packages/pipeline/src/data-sources/etherscan/events.ts
@@ -0,0 +1,54 @@
+import { AbiDecoder } from '@0xproject/utils';
+import { 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;
+ message: string;
+ result: EventsResponseResult[];
+}
+
+// Events as represented in the response from etherscan.io
+export interface EventsResponseResult {
+ address: string;
+ topics: string[];
+ data: string;
+ blockNumber: string;
+ timeStamp: string;
+ gasPrice: string;
+ gasUsed: string;
+ logIndex: string;
+ transactionHash: string;
+ transactionIndex: string;
+}
+
+function convertResponseToLogEntry(result: EventsResponseResult): LogEntry {
+ const radix = 10;
+ return {
+ logIndex: parseInt(result.logIndex, radix),
+ transactionIndex: parseInt(result.logIndex, radix),
+ transactionHash: result.transactionHash,
+ blockHash: '',
+ blockNumber: parseInt(result.blockNumber, radix),
+ address: result.address,
+ data: result.data,
+ topics: result.topics,
+ };
+}
+
+function tryToDecodeLogOrNoop(log: LogEntry): LogWithDecodedArgs<DecodedLogArgs> {
+ const abiDecoder = new AbiDecoder([artifacts.Exchange.compilerOutput.abi]);
+ 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 rawEventsResponse The raw events response from etherescan.io.
+ * @returns Parsed and decoded events.
+ */
+export const parseRawEventsResponse = R.pipe(R.map(convertResponseToLogEntry), R.map(tryToDecodeLogOrNoop));