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:56:41 +0800
committerAlex Browne <stephenalexbrowne@gmail.com>2018-12-05 06:23:32 +0800
commit75d3f24835fc68a758cfb44c6bc05095c3e87ad3 (patch)
treef4ce2dc221050b40fa0d78108cd78f97a43cb15a /packages/pipeline/src/data-sources/etherscan/events.ts
parent2b7f94c00f7fd38cfaa50540c6bef8237306c064 (diff)
downloaddexon-0x-contracts-75d3f24835fc68a758cfb44c6bc05095c3e87ad3.tar
dexon-0x-contracts-75d3f24835fc68a758cfb44c6bc05095c3e87ad3.tar.gz
dexon-0x-contracts-75d3f24835fc68a758cfb44c6bc05095c3e87ad3.tar.bz2
dexon-0x-contracts-75d3f24835fc68a758cfb44c6bc05095c3e87ad3.tar.lz
dexon-0x-contracts-75d3f24835fc68a758cfb44c6bc05095c3e87ad3.tar.xz
dexon-0x-contracts-75d3f24835fc68a758cfb44c6bc05095c3e87ad3.tar.zst
dexon-0x-contracts-75d3f24835fc68a758cfb44c6bc05095c3e87ad3.zip
Add tests for etherscan events
Diffstat (limited to 'packages/pipeline/src/data-sources/etherscan/events.ts')
-rw-r--r--packages/pipeline/src/data-sources/etherscan/events.ts23
1 files changed, 16 insertions, 7 deletions
diff --git a/packages/pipeline/src/data-sources/etherscan/events.ts b/packages/pipeline/src/data-sources/etherscan/events.ts
index 50962a266..3083af267 100644
--- a/packages/pipeline/src/data-sources/etherscan/events.ts
+++ b/packages/pipeline/src/data-sources/etherscan/events.ts
@@ -25,21 +25,30 @@ export interface EventsResponseResult {
transactionIndex: string;
}
-function convertResponseToLogEntry(result: EventsResponseResult): LogEntry {
- const radix = 10;
+const hexRadix = 16;
+
+function hexToInt(hex: string): number {
+ return parseInt(hex.replace('0x', ''), hexRadix);
+}
+
+// Converts a raw event response to a LogEntry
+// tslint:disable-next-line:completed-docs
+export function _convertResponseToLogEntry(result: EventsResponseResult): LogEntry {
return {
- logIndex: parseInt(result.logIndex, radix),
- transactionIndex: parseInt(result.logIndex, radix),
+ logIndex: hexToInt(result.logIndex),
+ transactionIndex: hexToInt(result.transactionIndex),
transactionHash: result.transactionHash,
blockHash: '',
- blockNumber: parseInt(result.blockNumber, radix),
+ blockNumber: hexToInt(result.blockNumber),
address: result.address,
data: result.data,
topics: result.topics,
};
}
-function tryToDecodeLogOrNoop(log: LogEntry): LogWithDecodedArgs<DecodedLogArgs> {
+// 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]);
const logWithDecodedArgs = abiDecoder.tryToDecodeLogOrNoop(log);
// tslint:disable-next-line:no-unnecessary-type-assertion
@@ -51,4 +60,4 @@ function tryToDecodeLogOrNoop(log: LogEntry): LogWithDecodedArgs<DecodedLogArgs>
* @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));
+export const parseRawEventsResponse = R.pipe(R.map(_convertResponseToLogEntry), R.map(_decodeLogEntry));