-
Notifications
You must be signed in to change notification settings - Fork 5
/
types.ts
40 lines (33 loc) · 1.41 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
export type JSObject = {
[key: string]: JSType;
};
export type JSType = string | number | boolean | bigint | JSType[] | JSObject;
import {
AbiEvent,
AbiParameterToPrimitiveType,
AbiParametersToPrimitiveTypes,
ExtractAbiEventNames,
Abi,
LogEvent,
ExtractAbiEvent,
} from 'ethereum-indexer';
export type InputNames<T extends AbiEvent> = Extract<T['inputs'][number], {name: string}>['name'];
export type InputValues<T extends AbiEvent> = {
[Property in InputNames<T>]: AbiParameterToPrimitiveType<Extract<T['inputs'][number], {name: Property}>>;
};
export type InputValueArray<T extends AbiEvent> = AbiParametersToPrimitiveTypes<T['inputs']>;
export type EventFunctions<ABI extends Abi, ProcessResultType extends JSObject, ProcessorConfig = undefined> = {
[Property in ExtractAbiEventNames<ABI> as `on${Property}`]?: ProcessorConfig extends undefined
? (json: ProcessResultType, event: LogEvent<ABI> & {args: InputValues<ExtractAbiEvent<ABI, Property>>}) => void
: (
json: ProcessResultType,
event: LogEvent<ABI> & {args: InputValues<ExtractAbiEvent<ABI, Property>>},
config: ProcessorConfig
) => void;
};
export type MergedEventFunctions<
T extends {[name: string]: {abi: Abi}},
ProcessResultType extends JSObject,
ProcessorConfig = undefined
> = EventFunctions<MergedAbis<T>, ProcessResultType, ProcessorConfig>;
export type MergedAbis<T extends {[name: string]: {abi: Abi}}> = [...T[keyof T]['abi']];