-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.ts
326 lines (294 loc) · 7.58 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
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
import { StorageValueStream } from '@aleph-indexer/core'
import {
Blockchain,
IndexableEntityType,
ParsedEntity,
} from '../../../types.js'
import { TransportType } from '../../../utils/index.js'
import { BlockchainRequestArgs } from '../../types.js'
import { IndexerMsClient } from '../client.js'
import { EntityRequest, EntityRequestType } from './dal/entityRequest.js'
/**
* Describes a date range associated with an account.
*/
export type IdRange = {
blockchainId: Blockchain
ids: string[]
}
/**
* Describes a date range associated with an account.
*/
export type AccountDateRange = {
blockchainId: Blockchain
account: string
startDate: number
endDate: number
}
/**
* Describes a slot range associated with an account.
*/
export type AccountSlotRange = {
blockchainId: Blockchain
account: string
startSlot: number
endSlot: number
}
/**
* {@link AccountDateRange} bundled with fetched transactions.
*/
export type EntityDateRangeResponse<T extends ParsedEntity<unknown>> =
AccountDateRange & {
type: IndexableEntityType
entities: StorageValueStream<T>
}
export type IndexerAccountPartitionRequestArgs = {
/**
* Account to partition.
*/
account: string
/**
* Key of the partition group to which the account belongs.
*/
partitionKey?: string
}
export type IndexerIndexerPartitionRequestArgs = {
/**
* @todo: what is this helpful for? similar to above?
*/
indexer: string
}
// Account ------------------------------
export type AccountIndexerEntityRequestArgs = BlockchainRequestArgs &
IndexerAccountPartitionRequestArgs & {
/**
* The kind of entity to index
*/
type: IndexableEntityType
/**
* How often to fetch a new chunk of transactions. (@todo: what is this helpful for?)
*/
chunkDelay: number
/**
* How large the timeframe of a chunk is. (@todo: what is this helpful for?)
*/
chunkTimeframe: number
}
export type AccountIndexerTransactionRequestArgs =
AccountIndexerEntityRequestArgs
export type AccountIndexerLogRequestArgs = AccountIndexerEntityRequestArgs
export type AccountIndexerStateRequestArgs = AccountIndexerEntityRequestArgs
export type AccountIndexerRequestArgs = BlockchainRequestArgs &
IndexerAccountPartitionRequestArgs & {
/**
* Indexer options.
*/
index: {
/**
* Whether to index account transactions.
*/
transactions?:
| boolean
| Omit<
AccountIndexerTransactionRequestArgs,
'type' | 'account' | 'blockchainId'
>
/**
* Whether to index account logs.
*/
logs?:
| boolean
| Omit<
AccountIndexerLogRequestArgs,
'type' | 'account' | 'blockchainId'
>
/**
* Whether to index account state.
*/
state?:
| boolean
| Omit<
AccountIndexerStateRequestArgs,
'type' | 'account' | 'blockchainId'
>
}
}
export type DelAccountIndexerRequestArgs = BlockchainRequestArgs &
IndexerAccountPartitionRequestArgs & {
index: {
/**
* Whether to stop indexing account transactions
*/
transactions?: boolean
/**
* Whether to stop indexing account logs
*/
logs?: boolean
/**
* Whether to stop indexing account state
*/
state?: boolean
}
}
// Other --------------------------------------------------
/**
* Indexer configuration with account information.
*/
export type AccountIndexerConfigWithMeta<T> = AccountIndexerRequestArgs & {
/**
* Account parsed information.
*/
meta: T
}
export type GetAccountIndexingEntityStateRequestArgs = BlockchainRequestArgs &
IndexerAccountPartitionRequestArgs & {
type: IndexableEntityType
}
export type InvokeMethodRequestArgs = Partial<BlockchainRequestArgs> &
IndexerAccountPartitionRequestArgs & {
/**
* Method to invoke.
*/
method: string
/**
* Arguments to pass to the method.
*/
args?: unknown[]
/**
* Indexer to execute.
*/
indexer?: string
}
export type GetEntityPendingRequestsRequestArgs = BlockchainRequestArgs &
IndexerIndexerPartitionRequestArgs & {
type: IndexableEntityType
/**
* Whether to filter by slot, date or signature requests.
*/
requestType?: EntityRequestType
/**
* Optional filter by unique nonce.
*/
nonce?: number
/**
* Whether to return only pending requests or only processed requests.
* If undefined, both are returned.
*/
complete?: boolean
/**
* Optional filter by associated account.
*/
account?: string
/**
* Optional filter by associated id.
*/
id?: string
}
export type AccountEventsFilters = AccountDateRange
/**
* Describes an object capable of handling transaction streams.
*/
export type EntityIndexerHandler<T extends ParsedEntity<unknown>> = {
onEntityDateRange(data: EntityDateRangeResponse<T>): Promise<void>
}
export type IndexerCommonDomainContext = {
/**
* Name of the project to which the indexer belongs.
*/
projectId: string
/**
* Supported blockchains
*/
supportedBlockchains: Blockchain[]
/**
* Transport type used to communicate inside the indexer.
*/
transport: TransportType
/**
* Client for calling the indexer service.
*/
apiClient: IndexerMsClient
// apiClient: IndexerMsI & PrivateIndexerMsI
/**
* Path to the directory where data is stored.
*/
dataPath: string
}
export type IndexerDomainContext = IndexerCommonDomainContext & {
instanceName: string
}
/**
* Describes an indexer worker domain,
* capable of indexing transactions and adding new accounts to be indexed.
*/
export type IndexerWorkerDomainI = EntityIndexerHandler<
ParsedEntity<unknown>
> & {
init(): Promise<void>
onNewAccount(args: AccountIndexerRequestArgs): Promise<void>
}
export type IndexerMainDomainContext = IndexerCommonDomainContext
export type IndexerMainDomainI = {
init(): Promise<void>
}
/**
* Stats about an account indexer's state.
*/
export type AccountEntityIndexerState = {
indexer: string
type: IndexableEntityType
blockchain: Blockchain
/**
* Which account is being indexed.
*/
account: string
/**
* If its statistics are accurate.
*/
accurate: boolean
/**
* Percentage of the account's transactions have been indexed.
*/
progress: number
/**
* Which transactions are pending.
*/
pending: string[]
/**
* Which transactions have been indexed.
*/
processed: string[]
}
/**
* Stats about an account indexer's state.
*/
export type AccountIndexerState = AccountEntityIndexerState & {
blockchain: Blockchain
}
export interface BlockchainIndexerI {
start(): Promise<void>
stop(): Promise<void>
/**
* Registers a new indexer for the given account, either for transactions or content or both.
* @param config The indexer configuration.
*/
indexAccount(config: AccountIndexerRequestArgs): Promise<void>
/**
* Remove the indexer for the given account, either for transactions or content or both.
* @param config The indexer configuration.
*/
deleteAccount(config: AccountIndexerRequestArgs): Promise<void>
/**
* Returns the indexing state of the given account.
* @param args The account to get the state of.
*/
getAccountState(
args: GetAccountIndexingEntityStateRequestArgs,
): Promise<AccountIndexerState | undefined>
/**
* Returns all pending and processed transaction requests.
* @param args
*/
getEntityPendingRequests(
args: GetEntityPendingRequestsRequestArgs,
): Promise<EntityRequest[]>
}