@apibara/indexer 0.2.2 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/config.d.ts +5 -5
- package/dist/sink/console.d.ts +1 -1
- package/dist/sink/mongo.d.ts +1 -1
- package/dist/sink/parquet.d.ts +1 -1
- package/dist/sink/postgres.d.ts +1 -1
- package/dist/sink/webhook.d.ts +1 -1
- package/dist/starknet/block.d.ts +27 -27
- package/dist/starknet/felt.d.ts +1 -1
- package/dist/starknet/filter.d.ts +19 -19
- package/dist/starknet/index.d.ts +2 -1
- package/dist/starknet/index.js +1 -0
- package/dist/starknet/index.js.map +1 -1
- package/dist/starknet/parser.d.ts +12 -0
- package/dist/starknet/parser.js +33 -0
- package/dist/starknet/parser.js.map +1 -0
- package/dist/starknet/parser.test.d.ts +1 -0
- package/dist/starknet/parser.test.js +32 -0
- package/dist/starknet/parser.test.js.map +1 -0
- package/package.json +2 -1
- package/src/starknet/index.ts +1 -0
- package/src/starknet/parser.test.ts +41 -0
- package/src/starknet/parser.ts +50 -0
package/dist/config.d.ts
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
/** Sink-related options. */
|
|
2
|
-
export
|
|
2
|
+
export type SinkOptions = {
|
|
3
3
|
/** Sink type. */
|
|
4
4
|
sinkType: string;
|
|
5
5
|
/** Sink options. */
|
|
6
6
|
sinkOptions: object;
|
|
7
7
|
};
|
|
8
8
|
/** Network-specific options. */
|
|
9
|
-
export
|
|
9
|
+
export type NetworkOptions = {
|
|
10
10
|
/** Network name. */
|
|
11
11
|
network: string;
|
|
12
12
|
/** Data filter. */
|
|
13
13
|
filter: object;
|
|
14
14
|
};
|
|
15
15
|
/** Data finality. */
|
|
16
|
-
export
|
|
16
|
+
export type Finality = "DATA_STATUS_FINALIZED" | "DATA_STATUS_ACCEPTED" | "DATA_STATUS_PENDING";
|
|
17
17
|
/** Stream-related options. */
|
|
18
|
-
export
|
|
18
|
+
export type StreamOptions = {
|
|
19
19
|
/** The Apibara DNA stream url, e.g. `mainnet.starknet.a5a.ch`. */
|
|
20
20
|
streamUrl?: string;
|
|
21
21
|
/** Maximum message size, e.g. `50Mb` */
|
|
@@ -25,7 +25,7 @@ export declare type StreamOptions = {
|
|
|
25
25
|
/** The Apibara DNA stream auth token. */
|
|
26
26
|
authToken?: string;
|
|
27
27
|
};
|
|
28
|
-
export
|
|
28
|
+
export type Config<TNetworkOptions extends NetworkOptions = NetworkOptions, TSink extends SinkOptions = SinkOptions> = TSink & TNetworkOptions & StreamOptions & {
|
|
29
29
|
/** How many historical blocks to process in a single batch. */
|
|
30
30
|
batchSize?: number;
|
|
31
31
|
/** Finality of the data to process. */
|
package/dist/sink/console.d.ts
CHANGED
package/dist/sink/mongo.d.ts
CHANGED
package/dist/sink/parquet.d.ts
CHANGED
package/dist/sink/postgres.d.ts
CHANGED
package/dist/sink/webhook.d.ts
CHANGED
package/dist/starknet/block.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FieldElement } from "./felt";
|
|
2
|
-
export
|
|
2
|
+
export type Block = {
|
|
3
3
|
/** Block header. */
|
|
4
4
|
header?: BlockHeader;
|
|
5
5
|
/** Transactions. */
|
|
@@ -11,7 +11,7 @@ export declare type Block = {
|
|
|
11
11
|
/** State update. */
|
|
12
12
|
stateUpdate?: StateUpdate;
|
|
13
13
|
};
|
|
14
|
-
export
|
|
14
|
+
export type BlockHeader = {
|
|
15
15
|
/** Block hash. */
|
|
16
16
|
blockHash: FieldElement;
|
|
17
17
|
/** Parent block hash. */
|
|
@@ -25,13 +25,13 @@ export declare type BlockHeader = {
|
|
|
25
25
|
/** Block production timestamp. */
|
|
26
26
|
timestamp: string;
|
|
27
27
|
};
|
|
28
|
-
export
|
|
28
|
+
export type TransactionWithReceipt = {
|
|
29
29
|
/** Transaction. */
|
|
30
30
|
transaction: Transaction;
|
|
31
31
|
/** Transaction receipt. */
|
|
32
32
|
receipt: TransactionReceipt;
|
|
33
33
|
};
|
|
34
|
-
export
|
|
34
|
+
export type EventWithTransaction = {
|
|
35
35
|
/** Transaction. */
|
|
36
36
|
transaction: Transaction;
|
|
37
37
|
/** Transaction receipt. */
|
|
@@ -39,17 +39,17 @@ export declare type EventWithTransaction = {
|
|
|
39
39
|
/** Event. */
|
|
40
40
|
event: Event;
|
|
41
41
|
};
|
|
42
|
-
export
|
|
42
|
+
export type L2ToL1MessageWithTransaction = {
|
|
43
43
|
/** Transaction. */
|
|
44
44
|
transaction: Transaction;
|
|
45
45
|
/** Message from L2 to L1. */
|
|
46
46
|
message: L2ToL1Message;
|
|
47
47
|
};
|
|
48
|
-
export
|
|
49
|
-
export
|
|
48
|
+
export type Transaction = TransactionCommon & (InvokeTransactionV0 | InvokeTransactionV1 | DeployTransaction | DeclareTransaction | DeployAccountTransaction | L1HandlerTransaction);
|
|
49
|
+
export type TransactionCommon = {
|
|
50
50
|
meta: TransactionMeta;
|
|
51
51
|
};
|
|
52
|
-
export
|
|
52
|
+
export type TransactionMeta = {
|
|
53
53
|
/** Transaction hash. */
|
|
54
54
|
hash: FieldElement;
|
|
55
55
|
/** Maximum fee. */
|
|
@@ -61,7 +61,7 @@ export declare type TransactionMeta = {
|
|
|
61
61
|
/** Transaction version. */
|
|
62
62
|
version: string;
|
|
63
63
|
};
|
|
64
|
-
export
|
|
64
|
+
export type InvokeTransactionV0 = {
|
|
65
65
|
invokeV0?: {
|
|
66
66
|
/** Target contract address. */
|
|
67
67
|
contractAddress: FieldElement;
|
|
@@ -76,7 +76,7 @@ export declare type InvokeTransactionV0 = {
|
|
|
76
76
|
l1Handler?: never;
|
|
77
77
|
deployAccount?: never;
|
|
78
78
|
};
|
|
79
|
-
export
|
|
79
|
+
export type InvokeTransactionV1 = {
|
|
80
80
|
invokeV1?: {
|
|
81
81
|
/** Address of the account sending the transaction. */
|
|
82
82
|
senderAddress: FieldElement;
|
|
@@ -89,7 +89,7 @@ export declare type InvokeTransactionV1 = {
|
|
|
89
89
|
l1Handler?: never;
|
|
90
90
|
deployAccount?: never;
|
|
91
91
|
};
|
|
92
|
-
export
|
|
92
|
+
export type DeployTransaction = {
|
|
93
93
|
deploy?: {
|
|
94
94
|
/** Constructor calldata. */
|
|
95
95
|
constructorCalldata: FieldElement[];
|
|
@@ -104,7 +104,7 @@ export declare type DeployTransaction = {
|
|
|
104
104
|
l1Handler?: never;
|
|
105
105
|
deployAccount?: never;
|
|
106
106
|
};
|
|
107
|
-
export
|
|
107
|
+
export type DeclareTransaction = {
|
|
108
108
|
declare?: {
|
|
109
109
|
/** Class hash. */
|
|
110
110
|
classHash: FieldElement;
|
|
@@ -119,7 +119,7 @@ export declare type DeclareTransaction = {
|
|
|
119
119
|
l1Handler?: never;
|
|
120
120
|
deployAccount?: never;
|
|
121
121
|
};
|
|
122
|
-
export
|
|
122
|
+
export type DeployAccountTransaction = {
|
|
123
123
|
deployAccount?: {
|
|
124
124
|
/** Constructor calldata. */
|
|
125
125
|
constructorCalldata: FieldElement[];
|
|
@@ -134,7 +134,7 @@ export declare type DeployAccountTransaction = {
|
|
|
134
134
|
declare?: never;
|
|
135
135
|
l1Handler?: never;
|
|
136
136
|
};
|
|
137
|
-
export
|
|
137
|
+
export type L1HandlerTransaction = {
|
|
138
138
|
l1Handler?: {
|
|
139
139
|
/** Target contract address. */
|
|
140
140
|
contractAddress: FieldElement;
|
|
@@ -149,7 +149,7 @@ export declare type L1HandlerTransaction = {
|
|
|
149
149
|
declare?: never;
|
|
150
150
|
deployAccount?: never;
|
|
151
151
|
};
|
|
152
|
-
export
|
|
152
|
+
export type TransactionReceipt = {
|
|
153
153
|
/** Transaction status. */
|
|
154
154
|
executionStatus: ExecutionStatus;
|
|
155
155
|
/** Transaction hash. */
|
|
@@ -167,8 +167,8 @@ export declare type TransactionReceipt = {
|
|
|
167
167
|
/** Revert reason. */
|
|
168
168
|
revertReason?: string;
|
|
169
169
|
};
|
|
170
|
-
export
|
|
171
|
-
export
|
|
170
|
+
export type ExecutionStatus = "EXECUTION_STATUS_UNSPECIFIED" | "EXECUTION_STATUS_SUCCEEDED" | "EXECUTION_STATUS_REVERTED";
|
|
171
|
+
export type Event = {
|
|
172
172
|
/** Event index. */
|
|
173
173
|
index: number;
|
|
174
174
|
/** Contract address. */
|
|
@@ -178,7 +178,7 @@ export declare type Event = {
|
|
|
178
178
|
/** Event data. */
|
|
179
179
|
data: FieldElement[];
|
|
180
180
|
};
|
|
181
|
-
export
|
|
181
|
+
export type L2ToL1Message = {
|
|
182
182
|
/** Message index. */
|
|
183
183
|
index: number;
|
|
184
184
|
/** L2 sender address. */
|
|
@@ -188,7 +188,7 @@ export declare type L2ToL1Message = {
|
|
|
188
188
|
/** Calldata. */
|
|
189
189
|
payload: FieldElement[];
|
|
190
190
|
};
|
|
191
|
-
export
|
|
191
|
+
export type StateUpdate = {
|
|
192
192
|
/** New state root. */
|
|
193
193
|
newRoot: FieldElement;
|
|
194
194
|
/** Old state root. */
|
|
@@ -196,7 +196,7 @@ export declare type StateUpdate = {
|
|
|
196
196
|
/** State diff. */
|
|
197
197
|
stateDiff: StateDiff;
|
|
198
198
|
};
|
|
199
|
-
export
|
|
199
|
+
export type StateDiff = {
|
|
200
200
|
/** Changes in storage. */
|
|
201
201
|
storageDiffs: StorageDiff[];
|
|
202
202
|
/** Declared contracts. */
|
|
@@ -210,41 +210,41 @@ export declare type StateDiff = {
|
|
|
210
210
|
/** Classes replaced. */
|
|
211
211
|
replacedClasses: ReplacedClass[];
|
|
212
212
|
};
|
|
213
|
-
export
|
|
213
|
+
export type StorageDiff = {
|
|
214
214
|
/** Contract address. */
|
|
215
215
|
contractAddress: FieldElement;
|
|
216
216
|
/** Changes in storage. */
|
|
217
217
|
storageEntries: StorageEntry[];
|
|
218
218
|
};
|
|
219
|
-
export
|
|
219
|
+
export type StorageEntry = {
|
|
220
220
|
/** Storage key. */
|
|
221
221
|
key: FieldElement;
|
|
222
222
|
/** New storage value. */
|
|
223
223
|
value: FieldElement;
|
|
224
224
|
};
|
|
225
|
-
export
|
|
225
|
+
export type DeclaredContract = {
|
|
226
226
|
/** Class hash. */
|
|
227
227
|
classHash: FieldElement;
|
|
228
228
|
};
|
|
229
|
-
export
|
|
229
|
+
export type DeclaredClass = {
|
|
230
230
|
/** Class hash. */
|
|
231
231
|
classHash: FieldElement;
|
|
232
232
|
/** Compiled class hash. */
|
|
233
233
|
compiledClassHash: FieldElement;
|
|
234
234
|
};
|
|
235
|
-
export
|
|
235
|
+
export type ReplacedClass = {
|
|
236
236
|
/** Contract address. */
|
|
237
237
|
contractAddress: FieldElement;
|
|
238
238
|
/** Class hash. */
|
|
239
239
|
classHash: FieldElement;
|
|
240
240
|
};
|
|
241
|
-
export
|
|
241
|
+
export type DeployedContract = {
|
|
242
242
|
/** Contract address. */
|
|
243
243
|
contractAddress: FieldElement;
|
|
244
244
|
/** Class hash. */
|
|
245
245
|
classHash: FieldElement;
|
|
246
246
|
};
|
|
247
|
-
export
|
|
247
|
+
export type NonceUpdate = {
|
|
248
248
|
/** Contract address. */
|
|
249
249
|
contractAddress: FieldElement;
|
|
250
250
|
/** New nonce. */
|
package/dist/starknet/felt.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FieldElement } from "./felt";
|
|
2
|
-
export
|
|
2
|
+
export type Filter = {
|
|
3
3
|
/** Header information. */
|
|
4
4
|
header?: HeaderFilter;
|
|
5
5
|
/** Include transactions. */
|
|
@@ -11,14 +11,14 @@ export declare type Filter = {
|
|
|
11
11
|
/** Include state updates. */
|
|
12
12
|
stateUpdate?: StateUpdateFilter;
|
|
13
13
|
};
|
|
14
|
-
export
|
|
14
|
+
export type HeaderFilter = {
|
|
15
15
|
weak?: boolean;
|
|
16
16
|
};
|
|
17
|
-
export
|
|
17
|
+
export type TransactionFilterCommon = {
|
|
18
18
|
/*** Include reverted transactions. */
|
|
19
19
|
includeReverted?: boolean;
|
|
20
20
|
};
|
|
21
|
-
export
|
|
21
|
+
export type InvokeTransactionV0Filter = {
|
|
22
22
|
invokeV0?: {
|
|
23
23
|
/** Filter by contract address. */
|
|
24
24
|
contractAddress?: FieldElement;
|
|
@@ -33,7 +33,7 @@ export declare type InvokeTransactionV0Filter = {
|
|
|
33
33
|
l1Handler?: never;
|
|
34
34
|
deployAccount?: never;
|
|
35
35
|
};
|
|
36
|
-
export
|
|
36
|
+
export type InvokeTransactionV1Filter = {
|
|
37
37
|
invokeV1?: {
|
|
38
38
|
/** Filter by sender address. */
|
|
39
39
|
senderAddress?: FieldElement;
|
|
@@ -46,7 +46,7 @@ export declare type InvokeTransactionV1Filter = {
|
|
|
46
46
|
l1Handler?: never;
|
|
47
47
|
deployAccount?: never;
|
|
48
48
|
};
|
|
49
|
-
export
|
|
49
|
+
export type DeployTransactionFilter = {
|
|
50
50
|
deploy?: {
|
|
51
51
|
/** Filter by contract address salt. */
|
|
52
52
|
contractAddressSalt?: FieldElement;
|
|
@@ -61,7 +61,7 @@ export declare type DeployTransactionFilter = {
|
|
|
61
61
|
l1Handler?: never;
|
|
62
62
|
deployAccount?: never;
|
|
63
63
|
};
|
|
64
|
-
export
|
|
64
|
+
export type DeclareTransactionFilter = {
|
|
65
65
|
declare?: {
|
|
66
66
|
/** Filter by class hash. */
|
|
67
67
|
classHash?: FieldElement;
|
|
@@ -74,7 +74,7 @@ export declare type DeclareTransactionFilter = {
|
|
|
74
74
|
l1Handler?: never;
|
|
75
75
|
deployAccount?: never;
|
|
76
76
|
};
|
|
77
|
-
export
|
|
77
|
+
export type L1HandlerTransactionFilter = {
|
|
78
78
|
l1Handler?: {
|
|
79
79
|
/** Filter by contract address. */
|
|
80
80
|
contractAddress?: FieldElement;
|
|
@@ -89,7 +89,7 @@ export declare type L1HandlerTransactionFilter = {
|
|
|
89
89
|
declare?: never;
|
|
90
90
|
deployAccount?: never;
|
|
91
91
|
};
|
|
92
|
-
export
|
|
92
|
+
export type DeployAccountTransactionFilter = {
|
|
93
93
|
deployAccount?: {
|
|
94
94
|
/** Filter by contract address salt. */
|
|
95
95
|
contractAddressSalt?: FieldElement;
|
|
@@ -104,8 +104,8 @@ export declare type DeployAccountTransactionFilter = {
|
|
|
104
104
|
declare?: never;
|
|
105
105
|
l1Handler?: never;
|
|
106
106
|
};
|
|
107
|
-
export
|
|
108
|
-
export
|
|
107
|
+
export type TransactionFilter = TransactionFilterCommon & (InvokeTransactionV0Filter | InvokeTransactionV1Filter | DeployTransactionFilter | DeclareTransactionFilter | L1HandlerTransactionFilter | DeployAccountTransactionFilter);
|
|
108
|
+
export type EventFilter = {
|
|
109
109
|
/** Filter by contract address. */
|
|
110
110
|
fromAddress?: FieldElement;
|
|
111
111
|
/** Filter by event keys (selector). */
|
|
@@ -119,7 +119,7 @@ export declare type EventFilter = {
|
|
|
119
119
|
/** Include the receipt of the transaction that emitted the event. Defaults to true. */
|
|
120
120
|
includeReceipt?: boolean;
|
|
121
121
|
};
|
|
122
|
-
export
|
|
122
|
+
export type L2ToL1MessageFilter = {
|
|
123
123
|
/** Filter by destination address. */
|
|
124
124
|
toAddress?: FieldElement;
|
|
125
125
|
/** Filter by payload. */
|
|
@@ -127,7 +127,7 @@ export declare type L2ToL1MessageFilter = {
|
|
|
127
127
|
/** Include messages from reverted transactions. */
|
|
128
128
|
includeReverted?: boolean;
|
|
129
129
|
};
|
|
130
|
-
export
|
|
130
|
+
export type StateUpdateFilter = {
|
|
131
131
|
/** Filter storage diffs. */
|
|
132
132
|
storageDiffs?: StorageDiffFilter[];
|
|
133
133
|
/** Filter declared contracts. */
|
|
@@ -141,33 +141,33 @@ export declare type StateUpdateFilter = {
|
|
|
141
141
|
/** Filter replaced classes. */
|
|
142
142
|
replacedClasses?: ReplacedClassFilter[];
|
|
143
143
|
};
|
|
144
|
-
export
|
|
144
|
+
export type StorageDiffFilter = {
|
|
145
145
|
/** Filter by contract address. */
|
|
146
146
|
contractAddress?: FieldElement;
|
|
147
147
|
};
|
|
148
|
-
export
|
|
148
|
+
export type DeclaredContractFilter = {
|
|
149
149
|
/** Filter by class hash. */
|
|
150
150
|
classHash?: FieldElement;
|
|
151
151
|
};
|
|
152
|
-
export
|
|
152
|
+
export type DeployedContractFilter = {
|
|
153
153
|
/** Filter by contract address. */
|
|
154
154
|
contractAddress?: FieldElement;
|
|
155
155
|
/** Filter by class hash. */
|
|
156
156
|
classHash?: FieldElement;
|
|
157
157
|
};
|
|
158
|
-
export
|
|
158
|
+
export type NonceUpdateFilter = {
|
|
159
159
|
/** Filter by contract address. */
|
|
160
160
|
contractAddress?: FieldElement;
|
|
161
161
|
/** Filter by nonce value. */
|
|
162
162
|
nonce?: FieldElement;
|
|
163
163
|
};
|
|
164
|
-
export
|
|
164
|
+
export type DeclaredClassFilter = {
|
|
165
165
|
/** Filter by class hash. */
|
|
166
166
|
classHash?: FieldElement;
|
|
167
167
|
/** Filter by compiled class hash. */
|
|
168
168
|
compiledClassHash?: FieldElement;
|
|
169
169
|
};
|
|
170
|
-
export
|
|
170
|
+
export type ReplacedClassFilter = {
|
|
171
171
|
/** Filter by contract address. */
|
|
172
172
|
contractAddress?: FieldElement;
|
|
173
173
|
/** Filter by class hash. */
|
package/dist/starknet/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
export * from "./filter";
|
|
2
2
|
export * from "./block";
|
|
3
|
+
export { Contract } from "./parser";
|
|
3
4
|
import { Filter } from "./filter";
|
|
4
5
|
/** Starknet network type and data filter. */
|
|
5
|
-
export
|
|
6
|
+
export type Starknet = {
|
|
6
7
|
network: "starknet";
|
|
7
8
|
filter: Filter;
|
|
8
9
|
};
|
package/dist/starknet/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/starknet/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/starknet/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { FieldElement } from "./felt";
|
|
2
|
+
import { EventFilter } from "./filter";
|
|
3
|
+
import { type Abi } from "starknet";
|
|
4
|
+
/** Build a stream filter from a contract ABI. */
|
|
5
|
+
export declare class Contract {
|
|
6
|
+
readonly contractAddress: FieldElement;
|
|
7
|
+
readonly contractAbi: Abi;
|
|
8
|
+
constructor(contractAddress: FieldElement, contractAbi: Abi);
|
|
9
|
+
private _findEvent;
|
|
10
|
+
/** Filter events based on their name from the contract's ABI. */
|
|
11
|
+
eventFilter(name: string, opts?: Pick<EventFilter, "includeReceipt" | "includeTransaction" | "includeReverted">): EventFilter;
|
|
12
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { hash } from "starknet";
|
|
2
|
+
/** Build a stream filter from a contract ABI. */
|
|
3
|
+
export class Contract {
|
|
4
|
+
// Read-only properties for the contract's address and its ABI.
|
|
5
|
+
contractAddress;
|
|
6
|
+
contractAbi;
|
|
7
|
+
constructor(contractAddress, contractAbi) {
|
|
8
|
+
this.contractAddress = contractAddress;
|
|
9
|
+
this.contractAbi = contractAbi;
|
|
10
|
+
}
|
|
11
|
+
_findEvent(name) {
|
|
12
|
+
// Find the event in the ABI matching the provided name.
|
|
13
|
+
const event = this.contractAbi.find((item) => item.type === "event" && item.name === name);
|
|
14
|
+
return event;
|
|
15
|
+
}
|
|
16
|
+
/** Filter events based on their name from the contract's ABI. */
|
|
17
|
+
eventFilter(name, opts = {}) {
|
|
18
|
+
const event = this._findEvent(name);
|
|
19
|
+
// Throw an error if the event is not found in the ABI
|
|
20
|
+
if (!event) {
|
|
21
|
+
throw new Error(`Event ${name} not found in contract ABI`);
|
|
22
|
+
}
|
|
23
|
+
// Return the found event.
|
|
24
|
+
return {
|
|
25
|
+
fromAddress: this.contractAddress,
|
|
26
|
+
keys: [hash.getSelectorFromName(event.name)],
|
|
27
|
+
includeTransaction: opts.includeTransaction ?? false,
|
|
28
|
+
includeReceipt: opts.includeReceipt ?? false,
|
|
29
|
+
includeReverted: opts.includeReverted ?? false,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=parser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parser.js","sourceRoot":"","sources":["../../src/starknet/parser.ts"],"names":[],"mappings":"AAGA,OAAO,EAAsB,IAAI,EAAE,MAAM,UAAU,CAAC;AAEpD,iDAAiD;AACjD,MAAM,OAAO,QAAQ;IACnB,+DAA+D;IACtD,eAAe,CAAe;IAC9B,WAAW,CAAM;IAE1B,YAAY,eAA6B,EAAE,WAAgB;QACzD,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;QACvC,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;IACjC,CAAC;IAEO,UAAU,CAAC,IAAY;QAC7B,wDAAwD;QACxD,MAAM,KAAK,GAAyB,IAAI,CAAC,WAAW,CAAC,IAAI,CACvD,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,OAAO,IAAI,IAAI,CAAC,IAAI,KAAK,IAAI,CACtD,CAAC;QAEF,OAAO,KAAK,CAAC;IACf,CAAC;IAED,iEAAiE;IACjE,WAAW,CACT,IAAY,EACZ,OAGI,EAAE;QAEN,MAAM,KAAK,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QAEpC,sDAAsD;QACtD,IAAI,CAAC,KAAK,EAAE;YACV,MAAM,IAAI,KAAK,CAAC,SAAS,IAAI,4BAA4B,CAAC,CAAC;SAC5D;QAED,0BAA0B;QAC1B,OAAO;YACL,WAAW,EAAE,IAAI,CAAC,eAAe;YACjC,IAAI,EAAE,CAAC,IAAI,CAAC,mBAAmB,CAAC,KAAK,CAAC,IAAI,CAAkB,CAAC;YAC7D,kBAAkB,EAAE,IAAI,CAAC,kBAAkB,IAAI,KAAK;YACpD,cAAc,EAAE,IAAI,CAAC,cAAc,IAAI,KAAK;YAC5C,eAAe,EAAE,IAAI,CAAC,eAAe,IAAI,KAAK;SAC/C,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Contract } from "./parser";
|
|
2
|
+
import { describe, expect, it } from "vitest";
|
|
3
|
+
describe("Contract class tests", () => {
|
|
4
|
+
const mockContractAddress = "0x0";
|
|
5
|
+
const mockEventAbi = {
|
|
6
|
+
type: "event",
|
|
7
|
+
name: "MockEvent",
|
|
8
|
+
kind: "struct",
|
|
9
|
+
members: [{ name: "param1", type: "felt", kind: "key" }],
|
|
10
|
+
};
|
|
11
|
+
const mockContractAbi = [mockEventAbi];
|
|
12
|
+
it("should create an EventFilter for a valid event name", () => {
|
|
13
|
+
const contract = new Contract(mockContractAddress, mockContractAbi);
|
|
14
|
+
const filter = contract.eventFilter("MockEvent");
|
|
15
|
+
expect(filter).toBeDefined();
|
|
16
|
+
expect(filter.fromAddress).toBe(mockContractAddress);
|
|
17
|
+
expect(filter.includeReceipt).toBeFalsy();
|
|
18
|
+
});
|
|
19
|
+
it("overrides some arguments", () => {
|
|
20
|
+
const contract = new Contract(mockContractAddress, mockContractAbi);
|
|
21
|
+
const filter = contract.eventFilter("MockEvent", { includeReceipt: true });
|
|
22
|
+
expect(filter).toBeDefined();
|
|
23
|
+
expect(filter.includeReceipt).toBeTruthy();
|
|
24
|
+
});
|
|
25
|
+
it("should throw an error for an invalid event name", () => {
|
|
26
|
+
const contract = new Contract(mockContractAddress, mockContractAbi);
|
|
27
|
+
expect(() => {
|
|
28
|
+
contract.eventFilter("InvalidEvent");
|
|
29
|
+
}).toThrow("Event InvalidEvent not found in contract ABI");
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
//# sourceMappingURL=parser.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parser.test.js","sourceRoot":"","sources":["../../src/starknet/parser.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAI9C,QAAQ,CAAC,sBAAsB,EAAE,GAAG,EAAE;IACpC,MAAM,mBAAmB,GAAiB,KAAK,CAAC;IAChD,MAAM,YAAY,GAAa;QAC7B,IAAI,EAAE,OAAO;QACb,IAAI,EAAE,WAAW;QACjB,IAAI,EAAE,QAAQ;QACd,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;KACzD,CAAC;IAEF,MAAM,eAAe,GAAG,CAAC,YAAY,CAAC,CAAC;IAEvC,EAAE,CAAC,qDAAqD,EAAE,GAAG,EAAE;QAC7D,MAAM,QAAQ,GAAG,IAAI,QAAQ,CAAC,mBAAmB,EAAE,eAAe,CAAC,CAAC;QACpE,MAAM,MAAM,GAAG,QAAQ,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC;QAEjD,MAAM,CAAC,MAAM,CAAC,CAAC,WAAW,EAAE,CAAC;QAC7B,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;QACrD,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,SAAS,EAAE,CAAC;IAC5C,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,0BAA0B,EAAE,GAAG,EAAE;QAClC,MAAM,QAAQ,GAAG,IAAI,QAAQ,CAAC,mBAAmB,EAAE,eAAe,CAAC,CAAC;QACpE,MAAM,MAAM,GAAG,QAAQ,CAAC,WAAW,CAAC,WAAW,EAAE,EAAE,cAAc,EAAE,IAAI,EAAE,CAAC,CAAC;QAE3E,MAAM,CAAC,MAAM,CAAC,CAAC,WAAW,EAAE,CAAC;QAC7B,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,UAAU,EAAE,CAAC;IAC7C,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,iDAAiD,EAAE,GAAG,EAAE;QACzD,MAAM,QAAQ,GAAG,IAAI,QAAQ,CAAC,mBAAmB,EAAE,eAAe,CAAC,CAAC;QAEpE,MAAM,CAAC,GAAG,EAAE;YACV,QAAQ,CAAC,WAAW,CAAC,cAAc,CAAC,CAAC;QACvC,CAAC,CAAC,CAAC,OAAO,CAAC,8CAA8C,CAAC,CAAC;IAC7D,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@apibara/indexer",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -48,6 +48,7 @@
|
|
|
48
48
|
"vitest": "^0.34.3"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
+
"starknet": "^5.24.3",
|
|
51
52
|
"zod": "^3.22.2"
|
|
52
53
|
},
|
|
53
54
|
"scripts": {
|
package/src/starknet/index.ts
CHANGED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Contract } from "./parser";
|
|
2
|
+
import { describe, expect, it } from "vitest";
|
|
3
|
+
import { FieldElement } from "./felt";
|
|
4
|
+
import { EventAbi } from "starknet";
|
|
5
|
+
|
|
6
|
+
describe("Contract class tests", () => {
|
|
7
|
+
const mockContractAddress: FieldElement = "0x0";
|
|
8
|
+
const mockEventAbi: EventAbi = {
|
|
9
|
+
type: "event",
|
|
10
|
+
name: "MockEvent",
|
|
11
|
+
kind: "struct",
|
|
12
|
+
members: [{ name: "param1", type: "felt", kind: "key" }],
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const mockContractAbi = [mockEventAbi];
|
|
16
|
+
|
|
17
|
+
it("should create an EventFilter for a valid event name", () => {
|
|
18
|
+
const contract = new Contract(mockContractAddress, mockContractAbi);
|
|
19
|
+
const filter = contract.eventFilter("MockEvent");
|
|
20
|
+
|
|
21
|
+
expect(filter).toBeDefined();
|
|
22
|
+
expect(filter.fromAddress).toBe(mockContractAddress);
|
|
23
|
+
expect(filter.includeReceipt).toBeFalsy();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("overrides some arguments", () => {
|
|
27
|
+
const contract = new Contract(mockContractAddress, mockContractAbi);
|
|
28
|
+
const filter = contract.eventFilter("MockEvent", { includeReceipt: true });
|
|
29
|
+
|
|
30
|
+
expect(filter).toBeDefined();
|
|
31
|
+
expect(filter.includeReceipt).toBeTruthy();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("should throw an error for an invalid event name", () => {
|
|
35
|
+
const contract = new Contract(mockContractAddress, mockContractAbi);
|
|
36
|
+
|
|
37
|
+
expect(() => {
|
|
38
|
+
contract.eventFilter("InvalidEvent");
|
|
39
|
+
}).toThrow("Event InvalidEvent not found in contract ABI");
|
|
40
|
+
});
|
|
41
|
+
});
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { FieldElement } from "./felt";
|
|
2
|
+
import { EventFilter } from "./filter";
|
|
3
|
+
|
|
4
|
+
import { type Abi, EventAbi, hash } from "starknet";
|
|
5
|
+
|
|
6
|
+
/** Build a stream filter from a contract ABI. */
|
|
7
|
+
export class Contract {
|
|
8
|
+
// Read-only properties for the contract's address and its ABI.
|
|
9
|
+
readonly contractAddress: FieldElement;
|
|
10
|
+
readonly contractAbi: Abi;
|
|
11
|
+
|
|
12
|
+
constructor(contractAddress: FieldElement, contractAbi: Abi) {
|
|
13
|
+
this.contractAddress = contractAddress;
|
|
14
|
+
this.contractAbi = contractAbi;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
private _findEvent(name: string): EventAbi | undefined {
|
|
18
|
+
// Find the event in the ABI matching the provided name.
|
|
19
|
+
const event: EventAbi | undefined = this.contractAbi.find(
|
|
20
|
+
(item) => item.type === "event" && item.name === name,
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
return event;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Filter events based on their name from the contract's ABI. */
|
|
27
|
+
eventFilter(
|
|
28
|
+
name: string,
|
|
29
|
+
opts: Pick<
|
|
30
|
+
EventFilter,
|
|
31
|
+
"includeReceipt" | "includeTransaction" | "includeReverted"
|
|
32
|
+
> = {},
|
|
33
|
+
): EventFilter {
|
|
34
|
+
const event = this._findEvent(name);
|
|
35
|
+
|
|
36
|
+
// Throw an error if the event is not found in the ABI
|
|
37
|
+
if (!event) {
|
|
38
|
+
throw new Error(`Event ${name} not found in contract ABI`);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Return the found event.
|
|
42
|
+
return {
|
|
43
|
+
fromAddress: this.contractAddress,
|
|
44
|
+
keys: [hash.getSelectorFromName(event.name) as `0x${string}`],
|
|
45
|
+
includeTransaction: opts.includeTransaction ?? false,
|
|
46
|
+
includeReceipt: opts.includeReceipt ?? false,
|
|
47
|
+
includeReverted: opts.includeReverted ?? false,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
}
|