diff options
author | Alex Browne <stephenalexbrowne@gmail.com> | 2018-09-26 03:54:10 +0800 |
---|---|---|
committer | Fred Carlsen <fred@sjelfull.no> | 2018-12-13 01:12:06 +0800 |
commit | 8e0dcb204f9fdb1802ecf16ae9e02579425298a0 (patch) | |
tree | e06e7094bbe094f1a6254a5b02d15888b602f58c /packages/pipeline/src/data_sources | |
parent | 0dc000183aabab129d6b642eae468ed2996a75c4 (diff) | |
download | dexon-0x-contracts-8e0dcb204f9fdb1802ecf16ae9e02579425298a0.tar dexon-0x-contracts-8e0dcb204f9fdb1802ecf16ae9e02579425298a0.tar.gz dexon-0x-contracts-8e0dcb204f9fdb1802ecf16ae9e02579425298a0.tar.bz2 dexon-0x-contracts-8e0dcb204f9fdb1802ecf16ae9e02579425298a0.tar.lz dexon-0x-contracts-8e0dcb204f9fdb1802ecf16ae9e02579425298a0.tar.xz dexon-0x-contracts-8e0dcb204f9fdb1802ecf16ae9e02579425298a0.tar.zst dexon-0x-contracts-8e0dcb204f9fdb1802ecf16ae9e02579425298a0.zip |
Re-organize event parsing and decoding
Diffstat (limited to 'packages/pipeline/src/data_sources')
-rw-r--r-- | packages/pipeline/src/data_sources/etherscan/index.ts | 52 |
1 files changed, 52 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..044fff02e --- /dev/null +++ b/packages/pipeline/src/data_sources/etherscan/index.ts @@ -0,0 +1,52 @@ +import { default as axios } from 'axios'; +import { BlockParam, BlockParamLiteral } from 'ethereum-types'; + +const ETHERSCAN_URL = 'https://api.etherscan.io/api'; + +export class Etherscan { + private readonly _apiKey: string; + constructor(apiKey: string) { + this._apiKey = apiKey; + } + + /** + * Gets the raw 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<EventsResponse> { + 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. + return resp.data; + } +} + +// 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; +} |