aboutsummaryrefslogtreecommitdiffstats
path: root/packages/pipeline/src/data_types/events/event_handlers/base_event_handler.ts
diff options
context:
space:
mode:
authorAlex Browne <stephenalexbrowne@gmail.com>2018-09-26 03:54:10 +0800
committerAlex Browne <stephenalexbrowne@gmail.com>2018-12-05 06:24:06 +0800
commitfe523e1f3f765077bdaf4dfc345c9dca67693668 (patch)
tree240544ddca2ecc3e96dfd7079b3192bb3827bb97 /packages/pipeline/src/data_types/events/event_handlers/base_event_handler.ts
parent9e9104578c8526ff48ecdda8b87d61ccb3d66a2d (diff)
downloaddexon-sol-tools-fe523e1f3f765077bdaf4dfc345c9dca67693668.tar
dexon-sol-tools-fe523e1f3f765077bdaf4dfc345c9dca67693668.tar.gz
dexon-sol-tools-fe523e1f3f765077bdaf4dfc345c9dca67693668.tar.bz2
dexon-sol-tools-fe523e1f3f765077bdaf4dfc345c9dca67693668.tar.lz
dexon-sol-tools-fe523e1f3f765077bdaf4dfc345c9dca67693668.tar.xz
dexon-sol-tools-fe523e1f3f765077bdaf4dfc345c9dca67693668.tar.zst
dexon-sol-tools-fe523e1f3f765077bdaf4dfc345c9dca67693668.zip
Re-organize event parsing and decoding
Diffstat (limited to 'packages/pipeline/src/data_types/events/event_handlers/base_event_handler.ts')
-rw-r--r--packages/pipeline/src/data_types/events/event_handlers/base_event_handler.ts34
1 files changed, 34 insertions, 0 deletions
diff --git a/packages/pipeline/src/data_types/events/event_handlers/base_event_handler.ts b/packages/pipeline/src/data_types/events/event_handlers/base_event_handler.ts
new file mode 100644
index 000000000..59331fc4f
--- /dev/null
+++ b/packages/pipeline/src/data_types/events/event_handlers/base_event_handler.ts
@@ -0,0 +1,34 @@
+import { AbiDefinition, BlockParam, BlockParamLiteral, LogEntry } from 'ethereum-types';
+import * as R from 'ramda';
+import { BaseEntity } from 'typeorm';
+
+import { Etherscan } from '../../../data_sources/etherscan';
+import { convertResponseToLogEntry } from '../event_utils';
+
+export abstract class BaseEventHandler<EntityType extends BaseEntity> {
+ protected _abi: AbiDefinition[];
+ protected _address: string;
+ protected _etherscan: Etherscan;
+ constructor(abi: AbiDefinition[], address: string, etherscan: Etherscan) {
+ this._abi = abi;
+ this._address = address;
+ this._etherscan = etherscan;
+ }
+ public abstract convertLogEntryToEventEntity(logEntry: LogEntry): EntityType;
+
+ public async getEventsAsync(
+ fromBlock: BlockParam = BlockParamLiteral.Earliest,
+ toBlock: BlockParam = BlockParamLiteral.Latest,
+ ): Promise<EntityType[]> {
+ const rawEventsResponse = await this._etherscan.getContractEventsAsync(this._address, fromBlock, toBlock);
+ const logEntries = R.map(convertResponseToLogEntry, rawEventsResponse.result);
+ // Note(albrow): Imperative for loop is required here because we can't
+ // bind convertLogEntryToEventEntity without having a specific instance
+ // of a sub-class.
+ const result = [];
+ for (const logEntry of logEntries) {
+ result.push(this.convertLogEntryToEventEntity(logEntry));
+ }
+ return result;
+ }
+}