-
Notifications
You must be signed in to change notification settings - Fork 0
/
factory.ts
96 lines (85 loc) · 3.2 KB
/
factory.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/* eslint-disable prettier/prettier */
import { Utils } from '@aleph-indexer/core'
import {
BaseEntityIndexer,
Blockchain,
BlockchainIndexerI,
createEntityIndexerStateDAL,
createEntityRequestDAL,
createEntityRequestIncomingEntityDAL,
createEntityRequestPendingEntityDAL,
createEntityRequestResponseDAL,
FetcherMsClient,
IndexableEntityType,
IndexerMsClient,
IndexerWorkerDomainI,
ParserMsClient,
} from '@aleph-indexer/framework'
import { EthereumParsedLog, EthereumParsedTransaction } from '../parser/src/types.js'
import { EthereumIndexer } from './main.js'
import { EthereumIndexerLogFetcher } from './src/logFetcher.js'
import { EthereumIndexerTransactionFetcher } from './src/transactionFetcher.js'
export async function ethereumIndexerFactory(
basePath: string,
domain: IndexerWorkerDomainI,
indexerMsClient: IndexerMsClient,
fetcherMsClient: FetcherMsClient,
parserMsClient: ParserMsClient,
): Promise<BlockchainIndexerI> {
await Utils.ensurePath(basePath)
// DALs
const transactionRequestDAL = createEntityRequestDAL(basePath, IndexableEntityType.Transaction)
const transactionRequestIncomingEntityDAL = createEntityRequestIncomingEntityDAL<EthereumParsedTransaction>(basePath, IndexableEntityType.Transaction)
const transactionRequestPendingSignatureDAL = createEntityRequestPendingEntityDAL(basePath, IndexableEntityType.Transaction)
const transactionRequestResponseDAL = createEntityRequestResponseDAL(basePath, IndexableEntityType.Transaction)
const transactionIndexerStateDAL = createEntityIndexerStateDAL(basePath, IndexableEntityType.Transaction)
const logRequestDAL = createEntityRequestDAL(basePath, IndexableEntityType.Log)
const logRequestIncomingEntityDAL = createEntityRequestIncomingEntityDAL<EthereumParsedLog>(basePath, IndexableEntityType.Log)
const logRequestPendingSignatureDAL = createEntityRequestPendingEntityDAL(basePath, IndexableEntityType.Log)
const logRequestResponseDAL = createEntityRequestResponseDAL(basePath, IndexableEntityType.Log)
const logIndexerStateDAL = createEntityIndexerStateDAL(basePath, IndexableEntityType.Log)
// Instances
const transactionFetcher = new EthereumIndexerTransactionFetcher(
fetcherMsClient,
transactionRequestDAL,
transactionRequestIncomingEntityDAL,
transactionRequestPendingSignatureDAL,
transactionRequestResponseDAL,
)
const transactionFetcherMain = new BaseEntityIndexer(
IndexableEntityType.Transaction,
Blockchain.Ethereum,
domain,
indexerMsClient,
fetcherMsClient,
parserMsClient,
transactionIndexerStateDAL,
transactionFetcher,
)
const logFetcher = new EthereumIndexerLogFetcher(
fetcherMsClient,
logRequestDAL,
logRequestIncomingEntityDAL,
logRequestPendingSignatureDAL,
logRequestResponseDAL,
)
const logFetcherMain = new BaseEntityIndexer(
IndexableEntityType.Log,
Blockchain.Ethereum,
domain,
indexerMsClient,
fetcherMsClient,
parserMsClient,
logIndexerStateDAL,
logFetcher,
)
const entityIndexers = {
[IndexableEntityType.Transaction]: transactionFetcherMain,
[IndexableEntityType.Log]: logFetcherMain
}
return new EthereumIndexer(
indexerMsClient,
domain,
entityIndexers,
)
}