@apibara/evm 2.1.0-beta.23 → 2.1.0-beta.24

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/block.ts CHANGED
@@ -1,361 +1,365 @@
1
- import { Bytes, BytesFromUint8Array } from "@apibara/protocol";
2
- import { Schema } from "@effect/schema";
3
-
1
+ import { BytesFromUint8Array } from "@apibara/protocol";
2
+
3
+ import {
4
+ ArrayCodec,
5
+ BigIntCodec,
6
+ BooleanCodec,
7
+ type Codec,
8
+ type CodecType,
9
+ DateCodec,
10
+ MessageCodec,
11
+ NumberCodec,
12
+ OneOfCodec,
13
+ OptionalCodec,
14
+ StringCodec,
15
+ } from "@apibara/protocol/codec";
16
+ import { RequiredCodec } from "@apibara/protocol/codec";
4
17
  import { Address, B256, U128, U256 } from "./common";
5
- import { tag } from "./helpers";
6
18
  import * as proto from "./proto";
7
19
 
8
- export const Bloom = Schema.transform(
9
- Schema.Struct({
10
- value: BytesFromUint8Array,
11
- }),
12
- Bytes,
13
- {
14
- strict: false,
15
- encode(value) {
16
- throw new Error("Not implemented");
17
- },
18
- decode({ value }) {
19
- return value;
20
- },
20
+ export const Bloom: Codec<
21
+ `0x${string}` | undefined,
22
+ { value?: Uint8Array | undefined }
23
+ > = {
24
+ encode(x) {
25
+ return { value: BytesFromUint8Array.encode(x) };
26
+ },
27
+ decode({ value }) {
28
+ return BytesFromUint8Array.decode(value);
21
29
  },
22
- );
23
-
24
- export type Bloom = typeof Bloom.Type;
25
-
26
- export const TransactionStatus = Schema.transform(
27
- Schema.Enums(proto.data.TransactionStatus),
28
- Schema.Literal("unknown", "succeeded", "reverted"),
29
- {
30
- decode(value) {
31
- const enumMap = {
32
- [proto.data.TransactionStatus.SUCCEEDED]: "succeeded",
33
- [proto.data.TransactionStatus.REVERTED]: "reverted",
34
- [proto.data.TransactionStatus.UNSPECIFIED]: "unknown",
35
- [proto.data.TransactionStatus.UNRECOGNIZED]: "unknown",
36
- } as const;
37
-
38
- return enumMap[value] ?? "unknown";
39
- },
40
- encode(value) {
41
- throw new Error("encode: not implemented");
42
- },
30
+ };
31
+
32
+ export type Bloom = CodecType<typeof Bloom>;
33
+
34
+ export const TransactionStatus: Codec<
35
+ "unknown" | "succeeded" | "reverted",
36
+ proto.data.TransactionStatus
37
+ > = {
38
+ encode(x) {
39
+ const enumMap = {
40
+ unknown: proto.data.TransactionStatus.UNSPECIFIED,
41
+ succeeded: proto.data.TransactionStatus.SUCCEEDED,
42
+ reverted: proto.data.TransactionStatus.REVERTED,
43
+ } as const;
44
+
45
+ return enumMap[x] ?? proto.data.TransactionStatus.UNSPECIFIED;
43
46
  },
44
- );
45
-
46
- export type TransactionStatus = typeof TransactionStatus.Type;
47
-
48
- export const BlockHeader = Schema.Struct({
49
- blockNumber: Schema.BigIntFromSelf,
50
- blockHash: B256,
51
- parentBlockHash: B256,
52
- unclesHash: B256,
53
- miner: Address,
54
- stateRoot: B256,
55
- transactionsRoot: B256,
56
- receiptsRoot: B256,
57
- logsBloom: Bloom,
58
- difficulty: U256,
59
- gasLimit: U128,
60
- gasUsed: U128,
61
- timestamp: Schema.DateFromSelf,
62
- extraData: BytesFromUint8Array,
63
- mixHash: Schema.optional(B256),
64
- nonce: Schema.optional(Schema.BigIntFromSelf),
65
- baseFeePerGas: Schema.optional(U128),
66
- withdrawalsRoot: Schema.optional(B256),
67
- totalDifficulty: Schema.optional(U256),
68
- blobGasUsed: Schema.optional(U128),
69
- excessBlobGas: Schema.optional(U128),
70
- parentBeaconBlockRoot: Schema.optional(B256),
71
- requestsHash: Schema.optional(B256),
47
+ decode(p) {
48
+ const enumMap = {
49
+ [proto.data.TransactionStatus.SUCCEEDED]: "succeeded",
50
+ [proto.data.TransactionStatus.REVERTED]: "reverted",
51
+ [proto.data.TransactionStatus.UNSPECIFIED]: "unknown",
52
+ [proto.data.TransactionStatus.UNRECOGNIZED]: "unknown",
53
+ } as const;
54
+
55
+ return enumMap[p] ?? "unknown";
56
+ },
57
+ };
58
+
59
+ export type TransactionStatus = CodecType<typeof TransactionStatus>;
60
+
61
+ export const BlockHeader = MessageCodec({
62
+ blockNumber: RequiredCodec(BigIntCodec),
63
+ blockHash: RequiredCodec(B256),
64
+ parentBlockHash: RequiredCodec(B256),
65
+ unclesHash: RequiredCodec(B256),
66
+ miner: RequiredCodec(Address),
67
+ stateRoot: RequiredCodec(B256),
68
+ transactionsRoot: RequiredCodec(B256),
69
+ receiptsRoot: RequiredCodec(B256),
70
+ logsBloom: RequiredCodec(Bloom),
71
+ difficulty: RequiredCodec(U256),
72
+ gasLimit: RequiredCodec(U128),
73
+ gasUsed: RequiredCodec(U128),
74
+ timestamp: RequiredCodec(DateCodec),
75
+ extraData: RequiredCodec(BytesFromUint8Array),
76
+ mixHash: OptionalCodec(B256),
77
+ nonce: OptionalCodec(BigIntCodec),
78
+ baseFeePerGas: OptionalCodec(U128),
79
+ withdrawalsRoot: OptionalCodec(B256),
80
+ totalDifficulty: OptionalCodec(U256),
81
+ blobGasUsed: OptionalCodec(U128),
82
+ excessBlobGas: OptionalCodec(U128),
83
+ parentBeaconBlockRoot: OptionalCodec(B256),
84
+ requestsHash: OptionalCodec(B256),
72
85
  });
73
86
 
74
- export type BlockHeader = typeof BlockHeader.Type;
87
+ export type BlockHeader = CodecType<typeof BlockHeader>;
75
88
 
76
- export const Withdrawal = Schema.Struct({
77
- filterIds: Schema.Array(Schema.Number),
78
- withdrawalIndex: Schema.Number,
79
- index: Schema.BigIntFromSelf,
80
- validatorIndex: Schema.Number,
81
- address: Address,
82
- amount: Schema.BigIntFromSelf,
89
+ export const Withdrawal = MessageCodec({
90
+ filterIds: ArrayCodec(NumberCodec),
91
+ withdrawalIndex: RequiredCodec(NumberCodec),
92
+ index: RequiredCodec(BigIntCodec),
93
+ validatorIndex: RequiredCodec(NumberCodec),
94
+ address: RequiredCodec(Address),
95
+ amount: RequiredCodec(BigIntCodec),
83
96
  });
84
97
 
85
- export type Withdrawal = typeof Withdrawal.Type;
98
+ export type Withdrawal = CodecType<typeof Withdrawal>;
86
99
 
87
- export const AccessListItem = Schema.Struct({
88
- address: Address,
89
- storageKeys: Schema.Array(B256),
100
+ export const AccessListItem = MessageCodec({
101
+ address: RequiredCodec(Address),
102
+ storageKeys: ArrayCodec(B256),
90
103
  });
91
104
 
92
- export type AccessListItem = typeof AccessListItem.Type;
105
+ export type AccessListItem = CodecType<typeof AccessListItem>;
93
106
 
94
- export const Signature = Schema.Struct({
95
- r: U256,
96
- s: U256,
97
- v: Schema.optional(U256),
98
- YParity: Schema.optional(Schema.Boolean),
107
+ export const Signature = MessageCodec({
108
+ r: RequiredCodec(U256),
109
+ s: RequiredCodec(U256),
110
+ v: OptionalCodec(U256),
111
+ YParity: OptionalCodec(BooleanCodec),
99
112
  });
100
113
 
101
- export type Signature = typeof Signature.Type;
102
-
103
- export const Transaction = Schema.Struct({
104
- filterIds: Schema.Array(Schema.Number),
105
- transactionIndex: Schema.Number,
106
- transactionHash: B256,
107
- nonce: Schema.BigIntFromSelf,
108
- from: Address,
109
- to: Schema.optional(Address),
110
- value: U256,
111
- gasPrice: Schema.optional(U128),
112
- gas: U128,
113
- maxFeePerGas: Schema.optional(U128),
114
- maxPriorityFeePerGas: Schema.optional(U128),
115
- input: BytesFromUint8Array,
116
- signature: Schema.optional(Signature),
117
- chainId: Schema.optional(Schema.BigIntFromSelf),
118
- accessList: Schema.Array(AccessListItem),
119
- transactionType: Schema.BigIntFromSelf,
120
- maxFeePerBlobGas: Schema.optional(U128),
121
- blobVersionedHashes: Schema.Array(B256),
122
- transactionStatus: TransactionStatus,
114
+ export type Signature = CodecType<typeof Signature>;
115
+
116
+ export const Transaction = MessageCodec({
117
+ filterIds: ArrayCodec(NumberCodec),
118
+ transactionIndex: RequiredCodec(NumberCodec),
119
+ transactionHash: RequiredCodec(B256),
120
+ nonce: RequiredCodec(BigIntCodec),
121
+ from: RequiredCodec(Address),
122
+ to: OptionalCodec(Address),
123
+ value: RequiredCodec(U256),
124
+ gasPrice: OptionalCodec(U128),
125
+ gas: RequiredCodec(U128),
126
+ maxFeePerGas: OptionalCodec(U128),
127
+ maxPriorityFeePerGas: OptionalCodec(U128),
128
+ input: RequiredCodec(BytesFromUint8Array),
129
+ signature: OptionalCodec(Signature),
130
+ chainId: OptionalCodec(BigIntCodec),
131
+ accessList: ArrayCodec(AccessListItem),
132
+ transactionType: RequiredCodec(BigIntCodec),
133
+ maxFeePerBlobGas: OptionalCodec(U128),
134
+ blobVersionedHashes: ArrayCodec(B256),
135
+ transactionStatus: RequiredCodec(TransactionStatus),
123
136
  });
124
137
 
125
- export type Transaction = typeof Transaction.Type;
126
-
127
- export const TransactionReceipt = Schema.Struct({
128
- filterIds: Schema.Array(Schema.Number),
129
- transactionIndex: Schema.Number,
130
- transactionHash: B256,
131
- cumulativeGasUsed: U128,
132
- gasUsed: U128,
133
- effectiveGasPrice: U128,
134
- from: Address,
135
- to: Schema.optional(Address),
136
- contractAddress: Schema.optional(Address),
137
- logsBloom: Bloom,
138
- transactionType: Schema.BigIntFromSelf,
139
- blobGasUsed: Schema.optional(U128),
140
- blobGasPrice: Schema.optional(U128),
141
- transactionStatus: TransactionStatus,
138
+ export type Transaction = CodecType<typeof Transaction>;
139
+
140
+ export const TransactionReceipt = MessageCodec({
141
+ filterIds: ArrayCodec(NumberCodec),
142
+ transactionIndex: RequiredCodec(NumberCodec),
143
+ transactionHash: RequiredCodec(B256),
144
+ cumulativeGasUsed: RequiredCodec(U128),
145
+ gasUsed: RequiredCodec(U128),
146
+ effectiveGasPrice: RequiredCodec(U128),
147
+ from: RequiredCodec(Address),
148
+ to: OptionalCodec(Address),
149
+ contractAddress: OptionalCodec(Address),
150
+ logsBloom: RequiredCodec(Bloom),
151
+ transactionType: RequiredCodec(BigIntCodec),
152
+ blobGasUsed: OptionalCodec(U128),
153
+ blobGasPrice: OptionalCodec(U128),
154
+ transactionStatus: RequiredCodec(TransactionStatus),
142
155
  });
143
156
 
144
- export type TransactionReceipt = typeof TransactionReceipt.Type;
145
-
146
- export const Log = Schema.Struct({
147
- filterIds: Schema.Array(Schema.Number),
148
- address: Address,
149
- topics: Schema.Array(B256),
150
- data: BytesFromUint8Array,
151
- logIndex: Schema.Number,
152
- logIndexInTransaction: Schema.Number,
153
- transactionIndex: Schema.Number,
154
- transactionHash: B256,
155
- transactionStatus: TransactionStatus,
157
+ export type TransactionReceipt = CodecType<typeof TransactionReceipt>;
158
+
159
+ export const Log = MessageCodec({
160
+ filterIds: ArrayCodec(NumberCodec),
161
+ address: RequiredCodec(Address),
162
+ topics: ArrayCodec(B256),
163
+ data: RequiredCodec(BytesFromUint8Array),
164
+ logIndex: RequiredCodec(NumberCodec),
165
+ logIndexInTransaction: RequiredCodec(NumberCodec),
166
+ transactionIndex: RequiredCodec(NumberCodec),
167
+ transactionHash: RequiredCodec(B256),
168
+ transactionStatus: RequiredCodec(TransactionStatus),
156
169
  });
157
170
 
158
- export type Log = typeof Log.Type;
159
-
160
- export const CallType = Schema.transform(
161
- Schema.Enums(proto.data.CallType),
162
- Schema.Literal(
163
- "unknown",
164
- "call",
165
- "delegateCall",
166
- "callCode",
167
- "delegateCall",
168
- "staticCall",
169
- "authCall",
170
- ),
171
- {
172
- decode(value) {
173
- const enumMap = {
174
- [proto.data.CallType.CALL]: "call",
175
- [proto.data.CallType.CALL_CODE]: "callCode",
176
- [proto.data.CallType.DELEGATE_CALL]: "delegateCall",
177
- [proto.data.CallType.STATIC_CALL]: "staticCall",
178
- [proto.data.CallType.AUTH_CALL]: "authCall",
179
- [proto.data.CallType.UNSPECIFIED]: "unknown",
180
- [proto.data.CallType.UNRECOGNIZED]: "unknown",
181
- } as const;
182
-
183
- return enumMap[value] ?? "unknown";
184
- },
185
- encode(value) {
186
- throw new Error("encode: not implemented");
187
- },
171
+ export type Log = CodecType<typeof Log>;
172
+
173
+ export const CallType: Codec<
174
+ "unknown" | "call" | "delegateCall" | "callCode" | "staticCall" | "authCall",
175
+ proto.data.CallType
176
+ > = {
177
+ encode(x) {
178
+ const enumMap = {
179
+ unknown: proto.data.CallType.UNSPECIFIED,
180
+ call: proto.data.CallType.CALL,
181
+ callCode: proto.data.CallType.CALL_CODE,
182
+ delegateCall: proto.data.CallType.DELEGATE_CALL,
183
+ staticCall: proto.data.CallType.STATIC_CALL,
184
+ authCall: proto.data.CallType.AUTH_CALL,
185
+ } as const;
186
+
187
+ return enumMap[x] ?? proto.data.CallType.UNSPECIFIED;
188
188
  },
189
- );
190
-
191
- export type CallType = typeof CallType.Type;
192
-
193
- export const CreationMethod = Schema.transform(
194
- Schema.Enums(proto.data.CreationMethod),
195
- Schema.Literal("unknown", "create", "create2", "eofCreate"),
196
- {
197
- decode(value) {
198
- const enumMap = {
199
- [proto.data.CreationMethod.CREATE]: "create",
200
- [proto.data.CreationMethod.CREATE2]: "create2",
201
- [proto.data.CreationMethod.EOF_CREATE]: "eofCreate",
202
- [proto.data.CallType.UNSPECIFIED]: "unknown",
203
- [proto.data.CallType.UNRECOGNIZED]: "unknown",
204
- } as const;
205
-
206
- return enumMap[value] ?? "unknown";
207
- },
208
- encode(value) {
209
- throw new Error("encode: not implemented");
210
- },
189
+ decode(p) {
190
+ const enumMap = {
191
+ [proto.data.CallType.CALL]: "call",
192
+ [proto.data.CallType.CALL_CODE]: "callCode",
193
+ [proto.data.CallType.DELEGATE_CALL]: "delegateCall",
194
+ [proto.data.CallType.STATIC_CALL]: "staticCall",
195
+ [proto.data.CallType.AUTH_CALL]: "authCall",
196
+ [proto.data.CallType.UNSPECIFIED]: "unknown",
197
+ [proto.data.CallType.UNRECOGNIZED]: "unknown",
198
+ } as const;
199
+
200
+ return enumMap[p] ?? "unknown";
211
201
  },
212
- );
213
-
214
- export type CreationMethod = typeof CreationMethod.Type;
215
-
216
- export const CallAction = Schema.Struct({
217
- _tag: tag("call"),
218
- call: Schema.Struct({
219
- fromAddress: Address,
220
- type: CallType,
221
- gas: Schema.BigIntFromSelf,
222
- input: BytesFromUint8Array,
223
- toAddress: Address,
224
- value: U256,
225
- }),
202
+ };
203
+
204
+ export type CallType = CodecType<typeof CallType>;
205
+
206
+ export const CreationMethod: Codec<
207
+ "unknown" | "create" | "create2" | "eofCreate",
208
+ proto.data.CreationMethod
209
+ > = {
210
+ encode(x) {
211
+ const enumMap = {
212
+ unknown: proto.data.CreationMethod.UNSPECIFIED,
213
+ create: proto.data.CreationMethod.CREATE,
214
+ create2: proto.data.CreationMethod.CREATE2,
215
+ eofCreate: proto.data.CreationMethod.EOF_CREATE,
216
+ } as const;
217
+
218
+ return enumMap[x] ?? proto.data.CreationMethod.UNSPECIFIED;
219
+ },
220
+ decode(p) {
221
+ const enumMap = {
222
+ [proto.data.CreationMethod.CREATE]: "create",
223
+ [proto.data.CreationMethod.CREATE2]: "create2",
224
+ [proto.data.CreationMethod.EOF_CREATE]: "eofCreate",
225
+ [proto.data.CreationMethod.UNSPECIFIED]: "unknown",
226
+ [proto.data.CreationMethod.UNRECOGNIZED]: "unknown",
227
+ } as const;
228
+
229
+ return enumMap[p] ?? "unknown";
230
+ },
231
+ };
232
+
233
+ export type CreationMethod = CodecType<typeof CreationMethod>;
234
+
235
+ export const CallAction = MessageCodec({
236
+ fromAddress: RequiredCodec(Address),
237
+ type: RequiredCodec(CallType),
238
+ gas: RequiredCodec(BigIntCodec),
239
+ input: RequiredCodec(BytesFromUint8Array),
240
+ toAddress: RequiredCodec(Address),
241
+ value: RequiredCodec(U256),
226
242
  });
227
243
 
228
- export type CallAction = typeof CallAction.Type;
229
-
230
- export const CreateAction = Schema.Struct({
231
- _tag: tag("create"),
232
- create: Schema.Struct({
233
- fromAddress: Address,
234
- gas: Schema.BigIntFromSelf,
235
- init: BytesFromUint8Array,
236
- value: U256,
237
- creationMethod: CreationMethod,
238
- }),
244
+ export type CallAction = CodecType<typeof CallAction>;
245
+
246
+ export const CreateAction = MessageCodec({
247
+ fromAddress: RequiredCodec(Address),
248
+ gas: RequiredCodec(BigIntCodec),
249
+ init: RequiredCodec(BytesFromUint8Array),
250
+ value: RequiredCodec(U256),
251
+ creationMethod: RequiredCodec(CreationMethod),
239
252
  });
240
253
 
241
- export type CreateAction = typeof CreateAction.Type;
254
+ export type CreateAction = CodecType<typeof CreateAction>;
242
255
 
243
- export const SelfDestructAction = Schema.Struct({
244
- _tag: tag("selfDestruct"),
245
- selfDestruct: Schema.Struct({
246
- address: Address,
247
- balance: U256,
248
- refundAddress: Address,
249
- }),
256
+ export const SelfDestructAction = MessageCodec({
257
+ address: RequiredCodec(Address),
258
+ balance: RequiredCodec(U256),
259
+ refundAddress: RequiredCodec(Address),
250
260
  });
251
261
 
252
- export type SelfDestructAction = typeof SelfDestructAction.Type;
253
-
254
- export const RewardType = Schema.transform(
255
- Schema.Enums(proto.data.RewardType),
256
- Schema.Literal("unknown", "block", "uncle"),
257
- {
258
- decode(value) {
259
- const enumMap = {
260
- [proto.data.RewardType.BLOCK]: "block",
261
- [proto.data.RewardType.UNCLE]: "uncle",
262
- [proto.data.RewardType.UNSPECIFIED]: "unknown",
263
- [proto.data.RewardType.UNRECOGNIZED]: "unknown",
264
- } as const;
265
-
266
- return enumMap[value] ?? "unknown";
267
- },
268
- encode(value) {
269
- throw new Error("encode: not implemented");
270
- },
262
+ export type SelfDestructAction = CodecType<typeof SelfDestructAction>;
263
+
264
+ export const RewardType: Codec<
265
+ "unknown" | "block" | "uncle",
266
+ proto.data.RewardType
267
+ > = {
268
+ encode(x) {
269
+ const enumMap = {
270
+ unknown: proto.data.RewardType.UNSPECIFIED,
271
+ block: proto.data.RewardType.BLOCK,
272
+ uncle: proto.data.RewardType.UNCLE,
273
+ } as const;
274
+
275
+ return enumMap[x] ?? proto.data.RewardType.UNSPECIFIED;
276
+ },
277
+ decode(p) {
278
+ const enumMap = {
279
+ [proto.data.RewardType.BLOCK]: "block",
280
+ [proto.data.RewardType.UNCLE]: "uncle",
281
+ [proto.data.RewardType.UNSPECIFIED]: "unknown",
282
+ [proto.data.RewardType.UNRECOGNIZED]: "unknown",
283
+ } as const;
284
+
285
+ return enumMap[p] ?? "unknown";
271
286
  },
272
- );
287
+ };
273
288
 
274
- export type RewardType = typeof RewardType.Type;
289
+ export type RewardType = CodecType<typeof RewardType>;
275
290
 
276
- export const RewardAction = Schema.Struct({
277
- _tag: tag("reward"),
278
- reward: Schema.Struct({
279
- author: Address,
280
- type: RewardType,
281
- value: U256,
282
- }),
291
+ export const RewardAction = MessageCodec({
292
+ author: RequiredCodec(Address),
293
+ type: RequiredCodec(RewardType),
294
+ value: RequiredCodec(U256),
283
295
  });
284
296
 
285
- export type RewardAction = typeof RewardAction.Type;
297
+ export type RewardAction = CodecType<typeof RewardAction>;
286
298
 
287
- export const CallOutput = Schema.Struct({
288
- _tag: tag("callOutput"),
289
- callOutput: Schema.Struct({
290
- gasUsed: Schema.BigIntFromSelf,
291
- output: BytesFromUint8Array,
292
- }),
299
+ export const CallOutput = MessageCodec({
300
+ gasUsed: RequiredCodec(BigIntCodec),
301
+ output: RequiredCodec(BytesFromUint8Array),
293
302
  });
294
303
 
295
- export type CallOutput = typeof CallOutput.Type;
304
+ export type CallOutput = CodecType<typeof CallOutput>;
296
305
 
297
- export const CreateOutput = Schema.Struct({
298
- _tag: tag("createOutput"),
299
- createOutput: Schema.Struct({
300
- address: Address,
301
- code: BytesFromUint8Array,
302
- gasUsed: Schema.BigIntFromSelf,
303
- }),
306
+ export const CreateOutput = MessageCodec({
307
+ address: RequiredCodec(Address),
308
+ code: RequiredCodec(BytesFromUint8Array),
309
+ gasUsed: RequiredCodec(BigIntCodec),
304
310
  });
305
311
 
306
- export type CreateOutput = typeof CreateOutput.Type;
312
+ export type CreateOutput = CodecType<typeof CreateOutput>;
307
313
 
308
- export const Trace = Schema.Struct({
309
- action: Schema.Union(
310
- CallAction,
311
- CreateAction,
312
- SelfDestructAction,
313
- RewardAction,
314
+ export const Trace = MessageCodec({
315
+ action: RequiredCodec(
316
+ OneOfCodec({
317
+ call: CallAction,
318
+ create: CreateAction,
319
+ selfDestruct: SelfDestructAction,
320
+ reward: RewardAction,
321
+ }),
314
322
  ),
315
- error: Schema.optional(Schema.String),
316
- output: Schema.optional(Schema.Union(CallOutput, CreateOutput)),
317
- subtraces: Schema.Number,
318
- traceAddress: Schema.Array(Schema.Number),
323
+ error: OptionalCodec(StringCodec),
324
+ output: OptionalCodec(
325
+ OneOfCodec({
326
+ callOutput: CallOutput,
327
+ createOutput: CreateOutput,
328
+ }),
329
+ ),
330
+ subtraces: RequiredCodec(NumberCodec),
331
+ traceAddress: ArrayCodec(NumberCodec),
319
332
  });
320
333
 
321
- export type Trace = typeof Trace.Type;
334
+ export type Trace = CodecType<typeof Trace>;
322
335
 
323
- export const TransactionTrace = Schema.Struct({
324
- filterIds: Schema.Array(Schema.Number),
325
- transactionIndex: Schema.Number,
326
- transactionHash: B256,
327
- traces: Schema.Array(Trace),
336
+ export const TransactionTrace = MessageCodec({
337
+ filterIds: ArrayCodec(NumberCodec),
338
+ transactionIndex: RequiredCodec(NumberCodec),
339
+ transactionHash: RequiredCodec(B256),
340
+ traces: ArrayCodec(Trace),
328
341
  });
329
342
 
330
- export type TransactionTrace = typeof TransactionTrace.Type;
343
+ export type TransactionTrace = CodecType<typeof TransactionTrace>;
331
344
 
332
- export const Block = Schema.Struct({
333
- header: BlockHeader,
334
- withdrawals: Schema.Array(Withdrawal),
335
- transactions: Schema.Array(Transaction),
336
- receipts: Schema.Array(TransactionReceipt),
337
- logs: Schema.Array(Log),
338
- traces: Schema.Array(TransactionTrace),
345
+ export const Block = MessageCodec({
346
+ header: RequiredCodec(BlockHeader),
347
+ withdrawals: ArrayCodec(Withdrawal),
348
+ transactions: ArrayCodec(Transaction),
349
+ receipts: ArrayCodec(TransactionReceipt),
350
+ logs: ArrayCodec(Log),
351
+ traces: ArrayCodec(TransactionTrace),
339
352
  });
340
353
 
341
- export type Block = typeof Block.Type;
342
-
343
- export const BlockFromBytes = Schema.transform(
344
- Schema.Uint8ArrayFromSelf,
345
- Schema.NullOr(Block),
346
- {
347
- strict: false,
348
- decode(value) {
349
- if (value.length === 0) {
350
- return null;
351
- }
352
- return proto.data.Block.decode(value);
353
- },
354
- encode(value) {
355
- if (value === null) {
356
- return new Uint8Array();
357
- }
358
- return proto.data.Block.encode(value).finish();
359
- },
354
+ export type Block = CodecType<typeof Block>;
355
+
356
+ export const BlockFromBytes: Codec<Block, Uint8Array> = {
357
+ encode(x) {
358
+ const block = Block.encode(x);
359
+ return proto.data.Block.encode(block).finish();
360
+ },
361
+ decode(p) {
362
+ const block = proto.data.Block.decode(p);
363
+ return Block.decode(block);
360
364
  },
361
- );
365
+ };