aboutsummaryrefslogtreecommitdiffstats
path: root/packages/pipeline/src/data-sources/etherscan/index.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/index.ts
parentcd73a047efbc1b7afa884ef27a1cc4991e20efd8 (diff)
downloaddexon-0x-contracts-2b7f94c00f7fd38cfaa50540c6bef8237306c064.tar
dexon-0x-contracts-2b7f94c00f7fd38cfaa50540c6bef8237306c064.tar.gz
dexon-0x-contracts-2b7f94c00f7fd38cfaa50540c6bef8237306c064.tar.bz2
dexon-0x-contracts-2b7f94c00f7fd38cfaa50540c6bef8237306c064.tar.lz
dexon-0x-contracts-2b7f94c00f7fd38cfaa50540c6bef8237306c064.tar.xz
dexon-0x-contracts-2b7f94c00f7fd38cfaa50540c6bef8237306c064.tar.zst
dexon-0x-contracts-2b7f94c00f7fd38cfaa50540c6bef8237306c064.zip
Restructure pipeline package. Create data-sources dir
Diffstat (limited to 'packages/pipeline/src/data-sources/etherscan/index.ts')
-rw-r--r--packages/pipeline/src/data-sources/etherscan/index.ts34
1 files changed, 34 insertions, 0 deletions
diff --git a/packages/pipeline/src/data-sources/etherscan/index.ts b/packages/pipeline/src/data-sources/etherscan/index.ts
new file mode 100644
index 000000000..0891d351a
--- /dev/null
+++ b/packages/pipeline/src/data-sources/etherscan/index.ts
@@ -0,0 +1,34 @@
+import { default as axios } from 'axios';
+import { BlockParam, BlockParamLiteral, DecodedLogArgs, LogWithDecodedArgs } from 'ethereum-types';
+
+import { EventsResponse, parseRawEventsResponse } from './events';
+
+const ETHERSCAN_URL = 'https://api.etherscan.io/api';
+
+export class Etherscan {
+ private readonly _apiKey: string;
+ constructor(apiKey: string) {
+ this._apiKey = apiKey;
+ }
+
+ /**
+ * Gets the decoded events for a specific contract and block range.
+ * @param contractAddress The address of the contract to get the events for.
+ * @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,
+ fromBlock: BlockParam = BlockParamLiteral.Earliest,
+ toBlock: BlockParam = BlockParamLiteral.Latest,
+ ): Promise<Array<LogWithDecodedArgs<DecodedLogArgs>>> {
+ const fullURL = `${ETHERSCAN_URL}?module=logs&action=getLogs&address=${contractAddress}&fromBlock=${fromBlock}&toBlock=${toBlock}&apikey=${
+ this._apiKey
+ }`;
+ const resp = await axios.get<EventsResponse>(fullURL);
+ // TODO(albrow): Check response code.
+ const decodedEvents = parseRawEventsResponse(resp.data.result);
+ return decodedEvents;
+ }
+}