@apibara/starknet 2.1.0-beta.23 → 2.1.0-beta.25

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/src/filter.ts CHANGED
@@ -1,7 +1,14 @@
1
- import { Schema } from "@effect/schema";
2
-
3
- import { FieldElement, FieldElementProto } from "./common";
4
- import { tag } from "./helpers";
1
+ import {
2
+ ArrayCodec,
3
+ BooleanCodec,
4
+ type Codec,
5
+ type CodecType,
6
+ MessageCodec,
7
+ NumberCodec,
8
+ OneOfCodec,
9
+ OptionalCodec,
10
+ } from "@apibara/protocol/codec";
11
+ import { FieldElement } from "./common";
5
12
  import * as proto from "./proto";
6
13
 
7
14
  /** Header options.
@@ -10,90 +17,87 @@ import * as proto from "./proto";
10
17
  * - `on_data`: receive headers only if any other filter matches.
11
18
  * - `on_data_or_on_new_block`: receive headers only if any other filter matches and for "live" blocks.
12
19
  */
13
- export const HeaderFilter = Schema.transform(
14
- Schema.Enums(proto.filter.HeaderFilter),
15
- Schema.Literal("always", "on_data", "on_data_or_on_new_block", "unknown"),
16
- {
17
- decode(value) {
18
- const enumMap = {
19
- [proto.filter.HeaderFilter.ALWAYS]: "always",
20
- [proto.filter.HeaderFilter.ON_DATA]: "on_data",
21
- [proto.filter.HeaderFilter.ON_DATA_OR_ON_NEW_BLOCK]:
22
- "on_data_or_on_new_block",
23
- [proto.filter.HeaderFilter.UNSPECIFIED]: "unknown",
24
- [proto.filter.HeaderFilter.UNRECOGNIZED]: "unknown",
25
- } as const;
26
- return enumMap[value] ?? "unknown";
27
- },
28
- encode(value) {
29
- switch (value) {
30
- case "always":
31
- return proto.filter.HeaderFilter.ALWAYS;
32
- case "on_data":
33
- return proto.filter.HeaderFilter.ON_DATA;
34
- case "on_data_or_on_new_block":
35
- return proto.filter.HeaderFilter.ON_DATA_OR_ON_NEW_BLOCK;
36
- default:
37
- return proto.filter.HeaderFilter.UNSPECIFIED;
38
- }
39
- },
20
+ export const HeaderFilter: Codec<
21
+ "always" | "on_data" | "on_data_or_on_new_block" | "unknown",
22
+ proto.filter.HeaderFilter
23
+ > = {
24
+ encode(x) {
25
+ switch (x) {
26
+ case "always":
27
+ return proto.filter.HeaderFilter.ALWAYS;
28
+ case "on_data":
29
+ return proto.filter.HeaderFilter.ON_DATA;
30
+ case "on_data_or_on_new_block":
31
+ return proto.filter.HeaderFilter.ON_DATA_OR_ON_NEW_BLOCK;
32
+ default:
33
+ return proto.filter.HeaderFilter.UNSPECIFIED;
34
+ }
35
+ },
36
+ decode(p) {
37
+ const enumMap = {
38
+ [proto.filter.HeaderFilter.ALWAYS]: "always",
39
+ [proto.filter.HeaderFilter.ON_DATA]: "on_data",
40
+ [proto.filter.HeaderFilter.ON_DATA_OR_ON_NEW_BLOCK]:
41
+ "on_data_or_on_new_block",
42
+ [proto.filter.HeaderFilter.UNSPECIFIED]: "unknown",
43
+ [proto.filter.HeaderFilter.UNRECOGNIZED]: "unknown",
44
+ } as const;
45
+ return enumMap[p] ?? "unknown";
40
46
  },
41
- );
47
+ };
42
48
 
43
- export type HeaderFilter = typeof HeaderFilter.Type;
49
+ export type HeaderFilter = CodecType<typeof HeaderFilter>;
44
50
 
45
51
  /** An event key filter. Use `null` to match any event key. */
46
- export const Key = Schema.transform(
47
- Schema.Struct({ value: Schema.UndefinedOr(FieldElementProto) }),
48
- Schema.NullOr(FieldElement),
49
- {
50
- decode({ value }) {
51
- if (value === undefined) {
52
- return null;
53
- }
54
- return value;
55
- },
56
- encode(value) {
57
- if (value === null) {
58
- return { value: undefined };
59
- }
60
- return { value };
61
- },
52
+ export const Key: Codec<
53
+ FieldElement | null,
54
+ { value?: proto.common.FieldElement | undefined }
55
+ > = {
56
+ encode(x) {
57
+ if (x === null) {
58
+ return { value: undefined };
59
+ }
60
+ return { value: FieldElement.encode(x) };
61
+ },
62
+ decode(p) {
63
+ if (p.value === undefined) {
64
+ return null;
65
+ }
66
+ return FieldElement.decode(p.value);
62
67
  },
63
- );
64
-
65
- export type Key = typeof Key.Type;
66
-
67
- export const TransactionStatusFilter = Schema.transform(
68
- Schema.Enums(proto.filter.TransactionStatusFilter),
69
- Schema.Literal("succeeded", "reverted", "all", "unknown"),
70
- {
71
- decode(value) {
72
- const enumMap = {
73
- [proto.filter.TransactionStatusFilter.SUCCEEDED]: "succeeded",
74
- [proto.filter.TransactionStatusFilter.REVERTED]: "reverted",
75
- [proto.filter.TransactionStatusFilter.ALL]: "all",
76
- [proto.filter.TransactionStatusFilter.UNSPECIFIED]: "unknown",
77
- [proto.filter.TransactionStatusFilter.UNRECOGNIZED]: "unknown",
78
- } as const;
79
- return enumMap[value] ?? "unknown";
80
- },
81
- encode(value) {
82
- switch (value) {
83
- case "succeeded":
84
- return proto.filter.TransactionStatusFilter.SUCCEEDED;
85
- case "reverted":
86
- return proto.filter.TransactionStatusFilter.REVERTED;
87
- case "all":
88
- return proto.filter.TransactionStatusFilter.ALL;
89
- default:
90
- return proto.filter.TransactionStatusFilter.UNSPECIFIED;
91
- }
92
- },
68
+ };
69
+
70
+ export type Key = CodecType<typeof Key>;
71
+
72
+ export const TransactionStatusFilter: Codec<
73
+ "succeeded" | "reverted" | "all" | "unknown",
74
+ proto.filter.TransactionStatusFilter
75
+ > = {
76
+ encode(x) {
77
+ switch (x) {
78
+ case "succeeded":
79
+ return proto.filter.TransactionStatusFilter.SUCCEEDED;
80
+ case "reverted":
81
+ return proto.filter.TransactionStatusFilter.REVERTED;
82
+ case "all":
83
+ return proto.filter.TransactionStatusFilter.ALL;
84
+ default:
85
+ return proto.filter.TransactionStatusFilter.UNSPECIFIED;
86
+ }
93
87
  },
94
- );
88
+ decode(p) {
89
+ const enumMap = {
90
+ [proto.filter.TransactionStatusFilter.SUCCEEDED]: "succeeded",
91
+ [proto.filter.TransactionStatusFilter.REVERTED]: "reverted",
92
+ [proto.filter.TransactionStatusFilter.ALL]: "all",
93
+ [proto.filter.TransactionStatusFilter.UNSPECIFIED]: "unknown",
94
+ [proto.filter.TransactionStatusFilter.UNRECOGNIZED]: "unknown",
95
+ } as const;
96
+ return enumMap[p] ?? "unknown";
97
+ },
98
+ };
95
99
 
96
- export type TransactionStatusFilter = typeof TransactionStatusFilter.Type;
100
+ export type TransactionStatusFilter = CodecType<typeof TransactionStatusFilter>;
97
101
 
98
102
  /** Filter events.
99
103
  *
@@ -108,20 +112,20 @@ export type TransactionStatusFilter = typeof TransactionStatusFilter.Type;
108
112
  * @prop includeSiblings Include the sibling events of the matched events.
109
113
  * @prop includeTransactionTrace Include the trace of the transaction that emitted the event.
110
114
  */
111
- export const EventFilter = Schema.Struct({
112
- id: Schema.optional(Schema.Number),
113
- address: Schema.optional(FieldElement),
114
- keys: Schema.optional(Schema.Array(Key)),
115
- strict: Schema.optional(Schema.Boolean),
116
- transactionStatus: Schema.optional(TransactionStatusFilter),
117
- includeTransaction: Schema.optional(Schema.Boolean),
118
- includeReceipt: Schema.optional(Schema.Boolean),
119
- includeMessages: Schema.optional(Schema.Boolean),
120
- includeSiblings: Schema.optional(Schema.Boolean),
121
- includeTransactionTrace: Schema.optional(Schema.Boolean),
115
+ export const EventFilter = MessageCodec({
116
+ id: OptionalCodec(NumberCodec),
117
+ address: OptionalCodec(FieldElement),
118
+ keys: OptionalCodec(ArrayCodec(Key)),
119
+ strict: OptionalCodec(BooleanCodec),
120
+ transactionStatus: OptionalCodec(TransactionStatusFilter),
121
+ includeTransaction: OptionalCodec(BooleanCodec),
122
+ includeReceipt: OptionalCodec(BooleanCodec),
123
+ includeMessages: OptionalCodec(BooleanCodec),
124
+ includeSiblings: OptionalCodec(BooleanCodec),
125
+ includeTransactionTrace: OptionalCodec(BooleanCodec),
122
126
  });
123
127
 
124
- export type EventFilter = typeof EventFilter.Type;
128
+ export type EventFilter = Readonly<CodecType<typeof EventFilter>>;
125
129
 
126
130
  /** Filter messages to L1.
127
131
  *
@@ -133,97 +137,74 @@ export type EventFilter = typeof EventFilter.Type;
133
137
  * @prop includeEvents Include events from the same transaction.
134
138
  * @prop includeTransactionTrace Include the trace of the transaction that sent the message.
135
139
  */
136
- export const MessageToL1Filter = Schema.Struct({
137
- id: Schema.optional(Schema.Number),
138
- fromAddress: Schema.optional(FieldElement),
139
- toAddress: Schema.optional(FieldElement),
140
- transactionStatus: Schema.optional(TransactionStatusFilter),
141
- includeTransaction: Schema.optional(Schema.Boolean),
142
- includeReceipt: Schema.optional(Schema.Boolean),
143
- includeEvents: Schema.optional(Schema.Boolean),
144
- includeTransactionTrace: Schema.optional(Schema.Boolean),
145
- });
146
-
147
- export type MessageToL1Filter = typeof MessageToL1Filter.Type;
148
-
149
- export const InvokeTransactionV0Filter = Schema.Struct({
150
- _tag: tag("invokeV0"),
151
- invokeV0: Schema.Struct({}),
152
- });
153
-
154
- export type InvokeTransactionV0Filter = typeof InvokeTransactionV0Filter.Type;
155
-
156
- export const InvokeTransactionV1Filter = Schema.Struct({
157
- _tag: tag("invokeV1"),
158
- invokeV1: Schema.Struct({}),
159
- });
160
-
161
- export type InvokeTransactionV1Filter = typeof InvokeTransactionV1Filter.Type;
162
-
163
- export const InvokeTransactionV3Filter = Schema.Struct({
164
- _tag: tag("invokeV3"),
165
- invokeV3: Schema.Struct({}),
166
- });
167
-
168
- export type InvokeTransactionV3Filter = typeof InvokeTransactionV3Filter.Type;
169
-
170
- export const DeployTransactionFilter = Schema.Struct({
171
- _tag: tag("deploy"),
172
- deploy: Schema.Struct({}),
173
- });
174
-
175
- export type DeployTransactionFilter = typeof DeployTransactionFilter.Type;
176
-
177
- export const DeclareV0TransactionFilter = Schema.Struct({
178
- _tag: tag("declareV0"),
179
- declareV0: Schema.Struct({}),
180
- });
181
-
182
- export type DeclareV0TransactionFilter = typeof DeclareV0TransactionFilter.Type;
183
-
184
- export const DeclareV1TransactionFilter = Schema.Struct({
185
- _tag: tag("declareV1"),
186
- declareV1: Schema.Struct({}),
187
- });
188
-
189
- export type DeclareV1TransactionFilter = typeof DeclareV1TransactionFilter.Type;
190
-
191
- export const DeclareV2TransactionFilter = Schema.Struct({
192
- _tag: tag("declareV2"),
193
- declareV2: Schema.Struct({}),
194
- });
195
-
196
- export type DeclareV2TransactionFilter = typeof DeclareV2TransactionFilter.Type;
197
-
198
- export const DeclareV3TransactionFilter = Schema.Struct({
199
- _tag: tag("declareV3"),
200
- declareV3: Schema.Struct({}),
201
- });
202
-
203
- export type DeclareV3TransactionFilter = typeof DeclareV3TransactionFilter.Type;
204
-
205
- export const L1HandlerTransactionFilter = Schema.Struct({
206
- _tag: tag("l1Handler"),
207
- l1Handler: Schema.Struct({}),
208
- });
209
-
210
- export type L1HandlerTransactionFilter = typeof L1HandlerTransactionFilter.Type;
211
-
212
- export const DeployAccountV1TransactionFilter = Schema.Struct({
213
- _tag: tag("deployAccountV1"),
214
- deployAccountV1: Schema.Struct({}),
140
+ export const MessageToL1Filter = MessageCodec({
141
+ id: OptionalCodec(NumberCodec),
142
+ fromAddress: OptionalCodec(FieldElement),
143
+ toAddress: OptionalCodec(FieldElement),
144
+ transactionStatus: OptionalCodec(TransactionStatusFilter),
145
+ includeTransaction: OptionalCodec(BooleanCodec),
146
+ includeReceipt: OptionalCodec(BooleanCodec),
147
+ includeEvents: OptionalCodec(BooleanCodec),
148
+ includeTransactionTrace: OptionalCodec(BooleanCodec),
215
149
  });
216
150
 
217
- export type DeployAccountV1TransactionFilter =
218
- typeof DeployAccountV1TransactionFilter.Type;
219
-
220
- export const DeployAccountV3TransactionFilter = Schema.Struct({
221
- _tag: tag("deployAccountV3"),
222
- deployAccountV3: Schema.Struct({}),
223
- });
224
-
225
- export type DeployAccountV3TransactionFilter =
226
- typeof DeployAccountV3TransactionFilter.Type;
151
+ export type MessageToL1Filter = Readonly<CodecType<typeof MessageToL1Filter>>;
152
+
153
+ // Transaction type filters
154
+ export const InvokeTransactionV0Filter = MessageCodec({});
155
+ export type InvokeTransactionV0Filter = Readonly<
156
+ CodecType<typeof InvokeTransactionV0Filter>
157
+ >;
158
+
159
+ export const InvokeTransactionV1Filter = MessageCodec({});
160
+ export type InvokeTransactionV1Filter = Readonly<
161
+ CodecType<typeof InvokeTransactionV1Filter>
162
+ >;
163
+
164
+ export const InvokeTransactionV3Filter = MessageCodec({});
165
+ export type InvokeTransactionV3Filter = Readonly<
166
+ CodecType<typeof InvokeTransactionV3Filter>
167
+ >;
168
+
169
+ export const DeployTransactionFilter = MessageCodec({});
170
+ export type DeployTransactionFilter = Readonly<
171
+ CodecType<typeof DeployTransactionFilter>
172
+ >;
173
+
174
+ export const DeclareV0TransactionFilter = MessageCodec({});
175
+ export type DeclareV0TransactionFilter = Readonly<
176
+ CodecType<typeof DeclareV0TransactionFilter>
177
+ >;
178
+
179
+ export const DeclareV1TransactionFilter = MessageCodec({});
180
+ export type DeclareV1TransactionFilter = Readonly<
181
+ CodecType<typeof DeclareV1TransactionFilter>
182
+ >;
183
+
184
+ export const DeclareV2TransactionFilter = MessageCodec({});
185
+ export type DeclareV2TransactionFilter = Readonly<
186
+ CodecType<typeof DeclareV2TransactionFilter>
187
+ >;
188
+
189
+ export const DeclareV3TransactionFilter = MessageCodec({});
190
+ export type DeclareV3TransactionFilter = Readonly<
191
+ CodecType<typeof DeclareV3TransactionFilter>
192
+ >;
193
+
194
+ export const L1HandlerTransactionFilter = MessageCodec({});
195
+ export type L1HandlerTransactionFilter = Readonly<
196
+ CodecType<typeof L1HandlerTransactionFilter>
197
+ >;
198
+
199
+ export const DeployAccountV1TransactionFilter = MessageCodec({});
200
+ export type DeployAccountV1TransactionFilter = Readonly<
201
+ CodecType<typeof DeployAccountV1TransactionFilter>
202
+ >;
203
+
204
+ export const DeployAccountV3TransactionFilter = MessageCodec({});
205
+ export type DeployAccountV3TransactionFilter = Readonly<
206
+ CodecType<typeof DeployAccountV3TransactionFilter>
207
+ >;
227
208
 
228
209
  /** Filter transactions.
229
210
  *
@@ -233,122 +214,108 @@ export type DeployAccountV3TransactionFilter =
233
214
  * @prop includeMessages Include messages sent in the transaction.
234
215
  * @prop includeTrace Include the transaction's trace.
235
216
  */
236
- export const TransactionFilter = Schema.Struct({
237
- id: Schema.optional(Schema.Number),
238
- transactionStatus: Schema.optional(TransactionStatusFilter),
239
- includeReceipt: Schema.optional(Schema.Boolean),
240
- includeMessages: Schema.optional(Schema.Boolean),
241
- includeEvents: Schema.optional(Schema.Boolean),
242
- includeTrace: Schema.optional(Schema.Boolean),
243
- transactionType: Schema.optional(
244
- Schema.Union(
245
- InvokeTransactionV0Filter,
246
- InvokeTransactionV1Filter,
247
- InvokeTransactionV3Filter,
248
- DeployTransactionFilter,
249
- DeclareV0TransactionFilter,
250
- DeclareV1TransactionFilter,
251
- DeclareV2TransactionFilter,
252
- DeclareV3TransactionFilter,
253
- DeclareV3TransactionFilter,
254
- L1HandlerTransactionFilter,
255
- DeployAccountV1TransactionFilter,
256
- DeployAccountV3TransactionFilter,
257
- ),
217
+ export const TransactionFilter = MessageCodec({
218
+ id: OptionalCodec(NumberCodec),
219
+ transactionStatus: OptionalCodec(TransactionStatusFilter),
220
+ includeReceipt: OptionalCodec(BooleanCodec),
221
+ includeMessages: OptionalCodec(BooleanCodec),
222
+ includeEvents: OptionalCodec(BooleanCodec),
223
+ includeTrace: OptionalCodec(BooleanCodec),
224
+ transactionType: OptionalCodec(
225
+ OneOfCodec({
226
+ invokeV0: InvokeTransactionV0Filter,
227
+ invokeV1: InvokeTransactionV1Filter,
228
+ invokeV3: InvokeTransactionV3Filter,
229
+ deploy: DeployTransactionFilter,
230
+ declareV0: DeclareV0TransactionFilter,
231
+ declareV1: DeclareV1TransactionFilter,
232
+ declareV2: DeclareV2TransactionFilter,
233
+ declareV3: DeclareV3TransactionFilter,
234
+ l1Handler: L1HandlerTransactionFilter,
235
+ deployAccountV1: DeployAccountV1TransactionFilter,
236
+ deployAccountV3: DeployAccountV3TransactionFilter,
237
+ }),
258
238
  ),
259
239
  });
260
240
 
261
- export type TransactionFilter = typeof TransactionFilter.Type;
241
+ export type TransactionFilter = Readonly<CodecType<typeof TransactionFilter>>;
262
242
 
263
243
  /** Filter storage diffs.
264
244
  *
265
245
  * @prop contractAddress Filter by contract address.
266
246
  */
267
- export const StorageDiffFilter = Schema.Struct({
268
- id: Schema.optional(Schema.Number),
269
- contractAddress: Schema.optional(FieldElement),
247
+ export const StorageDiffFilter = MessageCodec({
248
+ id: OptionalCodec(NumberCodec),
249
+ contractAddress: OptionalCodec(FieldElement),
270
250
  });
271
251
 
272
- export type StorageDiffFilter = typeof StorageDiffFilter.Type;
252
+ export type StorageDiffFilter = Readonly<CodecType<typeof StorageDiffFilter>>;
273
253
 
274
254
  /** Filter declared classes. */
275
- export const DeclaredClassFilter = Schema.Struct({
276
- _tag: tag("declaredClass"),
277
- declaredClass: Schema.Struct({}),
278
- });
255
+ export const DeclaredClassFilter = MessageCodec({});
256
+ export type DeclaredClassFilter = Readonly<
257
+ CodecType<typeof DeclaredClassFilter>
258
+ >;
279
259
 
280
- export type DeclaredClassFilter = typeof DeclaredClassFilter.Type;
260
+ export const ReplacedClassFilter = MessageCodec({});
261
+ export type ReplacedClassFilter = Readonly<
262
+ CodecType<typeof ReplacedClassFilter>
263
+ >;
281
264
 
282
- export const ReplacedClassFilter = Schema.Struct({
283
- _tag: tag("replacedClass"),
284
- replacedClass: Schema.Struct({}),
285
- });
286
-
287
- export type ReplacedClassFilter = typeof ReplacedClassFilter.Type;
288
-
289
- export const DeployedContractFilter = Schema.Struct({
290
- _tag: tag("deployedContract"),
291
- deployedContract: Schema.Struct({}),
292
- });
293
-
294
- export type DeployedContractFilter = typeof DeployedContractFilter.Type;
265
+ export const DeployedContractFilter = MessageCodec({});
266
+ export type DeployedContractFilter = Readonly<
267
+ CodecType<typeof DeployedContractFilter>
268
+ >;
295
269
 
296
270
  /** Filter contract changes. */
297
- export const ContractChangeFilter = Schema.Struct({
298
- id: Schema.optional(Schema.Number),
299
- change: Schema.optional(
300
- Schema.Union(
301
- DeclaredClassFilter,
302
- ReplacedClassFilter,
303
- DeployedContractFilter,
304
- ),
271
+ export const ContractChangeFilter = MessageCodec({
272
+ id: OptionalCodec(NumberCodec),
273
+ change: OptionalCodec(
274
+ OneOfCodec({
275
+ declaredClass: DeclaredClassFilter,
276
+ replacedClass: ReplacedClassFilter,
277
+ deployedContract: DeployedContractFilter,
278
+ }),
305
279
  ),
306
280
  });
307
281
 
308
- export type ContractChangeFilter = typeof ContractChangeFilter.Type;
282
+ export type ContractChangeFilter = Readonly<
283
+ CodecType<typeof ContractChangeFilter>
284
+ >;
309
285
 
310
286
  /** Filter updates to nonces.
311
287
  *
312
288
  * @prop contractAddress Filter by contract address.
313
289
  */
314
- export const NonceUpdateFilter = Schema.Struct({
315
- id: Schema.optional(Schema.Number),
316
- contractAddress: Schema.optional(FieldElement),
290
+ export const NonceUpdateFilter = MessageCodec({
291
+ id: OptionalCodec(NumberCodec),
292
+ contractAddress: OptionalCodec(FieldElement),
317
293
  });
318
294
 
319
- export type NonceUpdateFilter = typeof NonceUpdateFilter.Type;
295
+ export type NonceUpdateFilter = Readonly<CodecType<typeof NonceUpdateFilter>>;
320
296
 
321
- export const Filter = Schema.Struct({
322
- header: Schema.optional(HeaderFilter),
323
- transactions: Schema.optional(Schema.Array(TransactionFilter)),
324
- events: Schema.optional(Schema.Array(EventFilter)),
325
- messages: Schema.optional(Schema.Array(MessageToL1Filter)),
326
- storageDiffs: Schema.optional(Schema.Array(StorageDiffFilter)),
327
- contractChanges: Schema.optional(Schema.Array(ContractChangeFilter)),
328
- nonceUpdates: Schema.optional(Schema.Array(NonceUpdateFilter)),
297
+ export const Filter = MessageCodec({
298
+ header: OptionalCodec(HeaderFilter),
299
+ transactions: OptionalCodec(ArrayCodec(TransactionFilter)),
300
+ events: OptionalCodec(ArrayCodec(EventFilter)),
301
+ messages: OptionalCodec(ArrayCodec(MessageToL1Filter)),
302
+ storageDiffs: OptionalCodec(ArrayCodec(StorageDiffFilter)),
303
+ contractChanges: OptionalCodec(ArrayCodec(ContractChangeFilter)),
304
+ nonceUpdates: OptionalCodec(ArrayCodec(NonceUpdateFilter)),
329
305
  });
330
306
 
331
- export type Filter = typeof Filter.Type;
332
-
333
- export const filterToProto = Schema.encodeSync(Filter);
334
- export const filterFromProto = Schema.decodeSync(Filter);
335
-
336
- export const FilterFromBytes = Schema.transform(
337
- Schema.Uint8ArrayFromSelf,
338
- Filter,
339
- {
340
- strict: false,
341
- decode(value) {
342
- return proto.filter.Filter.decode(value);
343
- },
344
- encode(value) {
345
- return proto.filter.Filter.encode(value).finish();
346
- },
347
- },
348
- );
307
+ export type Filter = Readonly<CodecType<typeof Filter>>;
349
308
 
350
- export const filterToBytes = Schema.encodeSync(FilterFromBytes);
351
- export const filterFromBytes = Schema.decodeSync(FilterFromBytes);
309
+ export const FilterFromBytes: Codec<Filter, Uint8Array> = {
310
+ encode(x) {
311
+ const filter = Filter.encode(x);
312
+ return proto.filter.Filter.encode(filter).finish();
313
+ },
314
+ decode(p) {
315
+ const filter = proto.filter.Filter.decode(p);
316
+ return Filter.decode(filter);
317
+ },
318
+ };
352
319
 
353
320
  export function mergeFilter(a: Filter, b: Filter): Filter {
354
321
  const header = mergeHeaderFilter(a.header, b.header);
package/src/index.ts CHANGED
@@ -15,6 +15,8 @@ export { getBigIntSelector, getEventSelector, getSelector } from "./abi";
15
15
 
16
16
  declare module "abi-wan-kanabi" {
17
17
  interface Config {
18
+ AddressType: `0x${string}`;
19
+ ClassHashType: `0x${string}`;
18
20
  FeltType: bigint;
19
21
  BigIntType: bigint;
20
22
  U256Type: bigint;
package/src/parser.ts CHANGED
@@ -77,7 +77,7 @@ export function parseU256(data: readonly FieldElement[], offset: number) {
77
77
  export function parseAsHex(data: readonly FieldElement[], offset: number) {
78
78
  assertInBounds(data, offset);
79
79
  return {
80
- out: String(data[offset]),
80
+ out: data[offset],
81
81
  offset: offset + 1,
82
82
  };
83
83
  }
@@ -96,7 +96,7 @@ export function parseFelt252(data: readonly FieldElement[], offset: number) {
96
96
  };
97
97
  }
98
98
 
99
- export function parseEmpty(data: readonly FieldElement[], offset: number) {
99
+ export function parseEmpty(_data: readonly FieldElement[], offset: number) {
100
100
  return { out: null, offset };
101
101
  }
102
102
 
@@ -132,13 +132,13 @@ export function parseOption<T>(type: Parser<T>) {
132
132
  };
133
133
  }
134
134
 
135
- export function parseStruct<T extends { [key: string]: unknown }>(
135
+ export function parseStruct<T extends Record<string, unknown>>(
136
136
  parsers: { [K in keyof T]: { index: number; parser: Parser<T[K]> } },
137
- ) {
137
+ ): Parser<{ [K in keyof T]: T[K] }> {
138
138
  const sortedParsers = Object.entries(parsers).sort(
139
139
  (a, b) => a[1].index - b[1].index,
140
140
  );
141
- return (data: readonly FieldElement[], startingOffset: number) => {
141
+ const parser = (data: readonly FieldElement[], startingOffset: number) => {
142
142
  let offset = startingOffset;
143
143
  const out: Record<string, unknown> = {};
144
144
  for (const [key, { parser }] of sortedParsers) {
@@ -148,6 +148,7 @@ export function parseStruct<T extends { [key: string]: unknown }>(
148
148
  }
149
149
  return { out, offset };
150
150
  };
151
+ return parser as Parser<{ [K in keyof T]: T[K] }>;
151
152
  }
152
153
 
153
154
  export function parseTuple<T extends Parser<unknown>[]>(
@@ -1,32 +0,0 @@
1
- import * as _effect_schema_AST from '@effect/schema/AST';
2
- import { Schema } from '@effect/schema';
3
-
4
- /** Wire representation of `FieldElement`. */
5
- declare const FieldElementProto: Schema.Struct<{
6
- x0: typeof Schema.BigIntFromSelf;
7
- x1: typeof Schema.BigIntFromSelf;
8
- x2: typeof Schema.BigIntFromSelf;
9
- x3: typeof Schema.BigIntFromSelf;
10
- }>;
11
- /** Field element. */
12
- declare const FieldElement: Schema.transform<Schema.Struct<{
13
- x0: typeof Schema.BigIntFromSelf;
14
- x1: typeof Schema.BigIntFromSelf;
15
- x2: typeof Schema.BigIntFromSelf;
16
- x3: typeof Schema.BigIntFromSelf;
17
- }>, Schema.SchemaClass<`0x${string}`, `0x${string}`, never>>;
18
- type FieldElement = Schema.Schema.Type<typeof FieldElement>;
19
- declare const feltToProto: (a: `0x${string}`, overrideOptions?: _effect_schema_AST.ParseOptions) => {
20
- readonly x0: bigint;
21
- readonly x1: bigint;
22
- readonly x2: bigint;
23
- readonly x3: bigint;
24
- };
25
- declare const feltFromProto: (i: {
26
- readonly x0: bigint;
27
- readonly x1: bigint;
28
- readonly x2: bigint;
29
- readonly x3: bigint;
30
- }, overrideOptions?: _effect_schema_AST.ParseOptions) => `0x${string}`;
31
-
32
- export { FieldElement as F, FieldElementProto as a, feltFromProto as b, feltToProto as f };