aboutsummaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
authorAlex Browne <stephenalexbrowne@gmail.com>2018-09-20 03:09:36 +0800
committerFred Carlsen <fred@sjelfull.no>2018-12-06 19:03:11 +0800
commita6e5d126c37e03c50aa4b9b77eee1cce78dc2d9b (patch)
treee8920bf043423fc94a082f0780c54c0cf7030bc3 /packages
parent8e7ea4695bae8cd8c5e5bce62e7bc8b8130448a1 (diff)
downloaddexon-0x-contracts-a6e5d126c37e03c50aa4b9b77eee1cce78dc2d9b.tar
dexon-0x-contracts-a6e5d126c37e03c50aa4b9b77eee1cce78dc2d9b.tar.gz
dexon-0x-contracts-a6e5d126c37e03c50aa4b9b77eee1cce78dc2d9b.tar.bz2
dexon-0x-contracts-a6e5d126c37e03c50aa4b9b77eee1cce78dc2d9b.tar.lz
dexon-0x-contracts-a6e5d126c37e03c50aa4b9b77eee1cce78dc2d9b.tar.xz
dexon-0x-contracts-a6e5d126c37e03c50aa4b9b77eee1cce78dc2d9b.tar.zst
dexon-0x-contracts-a6e5d126c37e03c50aa4b9b77eee1cce78dc2d9b.zip
Make contractAbi a parameter of getContractEventsAsync
Diffstat (limited to 'packages')
-rw-r--r--packages/pipeline/src/data-sources/etherscan/events.ts22
-rw-r--r--packages/pipeline/src/data-sources/etherscan/index.ts6
-rw-r--r--packages/pipeline/src/index.ts8
-rw-r--r--packages/pipeline/test/data-sources/etherscan/events_test.ts4
4 files changed, 29 insertions, 11 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));
diff --git a/packages/pipeline/src/data-sources/etherscan/index.ts b/packages/pipeline/src/data-sources/etherscan/index.ts
index 0891d351a..66b6b1a8d 100644
--- a/packages/pipeline/src/data-sources/etherscan/index.ts
+++ b/packages/pipeline/src/data-sources/etherscan/index.ts
@@ -1,5 +1,5 @@
import { default as axios } from 'axios';
-import { BlockParam, BlockParamLiteral, DecodedLogArgs, LogWithDecodedArgs } from 'ethereum-types';
+import { AbiDefinition, BlockParam, BlockParamLiteral, DecodedLogArgs, LogWithDecodedArgs } from 'ethereum-types';
import { EventsResponse, parseRawEventsResponse } from './events';
@@ -14,12 +14,14 @@ export class Etherscan {
/**
* Gets the decoded events for a specific contract and block range.
* @param contractAddress The address of the contract to get the events for.
+ * @param constractAbi The ABI of the contract.
* @param fromBlock The start of the block range to get events for (inclusive).
* @param toBlock The end of the block range to get events for (inclusive).
* @returns A list of decoded events.
*/
public async getContractEventsAsync(
contractAddress: string,
+ contractAbi: AbiDefinition[],
fromBlock: BlockParam = BlockParamLiteral.Earliest,
toBlock: BlockParam = BlockParamLiteral.Latest,
): Promise<Array<LogWithDecodedArgs<DecodedLogArgs>>> {
@@ -28,7 +30,7 @@ export class Etherscan {
}`;
const resp = await axios.get<EventsResponse>(fullURL);
// TODO(albrow): Check response code.
- const decodedEvents = parseRawEventsResponse(resp.data.result);
+ const decodedEvents = parseRawEventsResponse(contractAbi, resp.data);
return decodedEvents;
}
}
diff --git a/packages/pipeline/src/index.ts b/packages/pipeline/src/index.ts
index baed6933e..eccb24d18 100644
--- a/packages/pipeline/src/index.ts
+++ b/packages/pipeline/src/index.ts
@@ -1,7 +1,13 @@
import { Etherscan } from './data-sources/etherscan';
+import { artifacts } from './artifacts';
+
const etherscan = new Etherscan(process.env.ETHERSCAN_API_KEY as string);
(async () => {
- await etherscan.getContractEventsAsync('0x4f833a24e1f95d70f028921e27040ca56e09ab0b');
+ const events = await etherscan.getContractEventsAsync(
+ '0x4f833a24e1f95d70f028921e27040ca56e09ab0b',
+ artifacts.Exchange.compilerOutput.abi,
+ );
+ console.log(events);
})();
diff --git a/packages/pipeline/test/data-sources/etherscan/events_test.ts b/packages/pipeline/test/data-sources/etherscan/events_test.ts
index 1151757f2..cb8e9d8e8 100644
--- a/packages/pipeline/test/data-sources/etherscan/events_test.ts
+++ b/packages/pipeline/test/data-sources/etherscan/events_test.ts
@@ -3,6 +3,8 @@ import * as chai from 'chai';
import { DecodedLogArgs, LogEntry, LogWithDecodedArgs } from 'ethereum-types';
import 'mocha';
+import { artifacts } from '../../../src/artifacts';
+
import {
_convertResponseToLogEntry,
_decodeLogEntry,
@@ -81,7 +83,7 @@ describe('etherscan#events', () => {
takerAssetData: '0xf47261b0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
},
};
- const actual = _decodeLogEntry(input);
+ const actual = _decodeLogEntry(artifacts.Exchange.compilerOutput.abi, input);
expect(actual).deep.equal(expected);
});
});