@apibara/evm 2.1.0-beta.22 → 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,360 +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),
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),
71
85
  });
72
86
 
73
- export type BlockHeader = typeof BlockHeader.Type;
87
+ export type BlockHeader = CodecType<typeof BlockHeader>;
74
88
 
75
- export const Withdrawal = Schema.Struct({
76
- filterIds: Schema.Array(Schema.Number),
77
- withdrawalIndex: Schema.Number,
78
- index: Schema.BigIntFromSelf,
79
- validatorIndex: Schema.Number,
80
- address: Address,
81
- 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),
82
96
  });
83
97
 
84
- export type Withdrawal = typeof Withdrawal.Type;
98
+ export type Withdrawal = CodecType<typeof Withdrawal>;
85
99
 
86
- export const AccessListItem = Schema.Struct({
87
- address: Address,
88
- storageKeys: Schema.Array(B256),
100
+ export const AccessListItem = MessageCodec({
101
+ address: RequiredCodec(Address),
102
+ storageKeys: ArrayCodec(B256),
89
103
  });
90
104
 
91
- export type AccessListItem = typeof AccessListItem.Type;
105
+ export type AccessListItem = CodecType<typeof AccessListItem>;
92
106
 
93
- export const Signature = Schema.Struct({
94
- r: U256,
95
- s: U256,
96
- v: U256,
97
- 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),
98
112
  });
99
113
 
100
- export type Signature = typeof Signature.Type;
101
-
102
- export const Transaction = Schema.Struct({
103
- filterIds: Schema.Array(Schema.Number),
104
- transactionIndex: Schema.Number,
105
- transactionHash: B256,
106
- nonce: Schema.BigIntFromSelf,
107
- from: Address,
108
- to: Schema.optional(Address),
109
- value: U256,
110
- gasPrice: Schema.optional(U128),
111
- gas: U128,
112
- maxFeePerGas: Schema.optional(U128),
113
- maxPriorityFeePerGas: Schema.optional(U128),
114
- input: BytesFromUint8Array,
115
- signature: Schema.optional(Signature),
116
- chainId: Schema.optional(Schema.BigIntFromSelf),
117
- accessList: Schema.Array(AccessListItem),
118
- transactionType: Schema.BigIntFromSelf,
119
- maxFeePerBlobGas: Schema.optional(U128),
120
- blobVersionedHashes: Schema.Array(B256),
121
- 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),
122
136
  });
123
137
 
124
- export type Transaction = typeof Transaction.Type;
125
-
126
- export const TransactionReceipt = Schema.Struct({
127
- filterIds: Schema.Array(Schema.Number),
128
- transactionIndex: Schema.Number,
129
- transactionHash: B256,
130
- cumulativeGasUsed: U128,
131
- gasUsed: U128,
132
- effectiveGasPrice: U128,
133
- from: Address,
134
- to: Schema.optional(Address),
135
- contractAddress: Schema.optional(Address),
136
- logsBloom: Bloom,
137
- transactionType: Schema.BigIntFromSelf,
138
- blobGasUsed: Schema.optional(U128),
139
- blobGasPrice: Schema.optional(U128),
140
- 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),
141
155
  });
142
156
 
143
- export type TransactionReceipt = typeof TransactionReceipt.Type;
144
-
145
- export const Log = Schema.Struct({
146
- filterIds: Schema.Array(Schema.Number),
147
- address: Address,
148
- topics: Schema.Array(B256),
149
- data: BytesFromUint8Array,
150
- logIndex: Schema.Number,
151
- logIndexInTransaction: Schema.Number,
152
- transactionIndex: Schema.Number,
153
- transactionHash: B256,
154
- 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),
155
169
  });
156
170
 
157
- export type Log = typeof Log.Type;
158
-
159
- export const CallType = Schema.transform(
160
- Schema.Enums(proto.data.CallType),
161
- Schema.Literal(
162
- "unknown",
163
- "call",
164
- "delegateCall",
165
- "callCode",
166
- "delegateCall",
167
- "staticCall",
168
- "authCall",
169
- ),
170
- {
171
- decode(value) {
172
- const enumMap = {
173
- [proto.data.CallType.CALL]: "call",
174
- [proto.data.CallType.CALL_CODE]: "callCode",
175
- [proto.data.CallType.DELEGATE_CALL]: "delegateCall",
176
- [proto.data.CallType.STATIC_CALL]: "staticCall",
177
- [proto.data.CallType.AUTH_CALL]: "authCall",
178
- [proto.data.CallType.UNSPECIFIED]: "unknown",
179
- [proto.data.CallType.UNRECOGNIZED]: "unknown",
180
- } as const;
181
-
182
- return enumMap[value] ?? "unknown";
183
- },
184
- encode(value) {
185
- throw new Error("encode: not implemented");
186
- },
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;
187
188
  },
188
- );
189
-
190
- export type CallType = typeof CallType.Type;
191
-
192
- export const CreationMethod = Schema.transform(
193
- Schema.Enums(proto.data.CreationMethod),
194
- Schema.Literal("unknown", "create", "create2", "eofCreate"),
195
- {
196
- decode(value) {
197
- const enumMap = {
198
- [proto.data.CreationMethod.CREATE]: "create",
199
- [proto.data.CreationMethod.CREATE2]: "create2",
200
- [proto.data.CreationMethod.EOF_CREATE]: "eofCreate",
201
- [proto.data.CallType.UNSPECIFIED]: "unknown",
202
- [proto.data.CallType.UNRECOGNIZED]: "unknown",
203
- } as const;
204
-
205
- return enumMap[value] ?? "unknown";
206
- },
207
- encode(value) {
208
- throw new Error("encode: not implemented");
209
- },
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";
210
201
  },
211
- );
212
-
213
- export type CreationMethod = typeof CreationMethod.Type;
214
-
215
- export const CallAction = Schema.Struct({
216
- _tag: tag("call"),
217
- call: Schema.Struct({
218
- fromAddress: Address,
219
- type: CallType,
220
- gas: Schema.BigIntFromSelf,
221
- input: BytesFromUint8Array,
222
- toAddress: Address,
223
- value: U256,
224
- }),
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),
225
242
  });
226
243
 
227
- export type CallAction = typeof CallAction.Type;
228
-
229
- export const CreateAction = Schema.Struct({
230
- _tag: tag("create"),
231
- create: Schema.Struct({
232
- fromAddress: Address,
233
- gas: Schema.BigIntFromSelf,
234
- init: BytesFromUint8Array,
235
- value: U256,
236
- creationMethod: CreationMethod,
237
- }),
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),
238
252
  });
239
253
 
240
- export type CreateAction = typeof CreateAction.Type;
254
+ export type CreateAction = CodecType<typeof CreateAction>;
241
255
 
242
- export const SelfDestructAction = Schema.Struct({
243
- _tag: tag("selfDestruct"),
244
- selfDestruct: Schema.Struct({
245
- address: Address,
246
- balance: U256,
247
- refundAddress: Address,
248
- }),
256
+ export const SelfDestructAction = MessageCodec({
257
+ address: RequiredCodec(Address),
258
+ balance: RequiredCodec(U256),
259
+ refundAddress: RequiredCodec(Address),
249
260
  });
250
261
 
251
- export type SelfDestructAction = typeof SelfDestructAction.Type;
252
-
253
- export const RewardType = Schema.transform(
254
- Schema.Enums(proto.data.RewardType),
255
- Schema.Literal("unknown", "block", "uncle"),
256
- {
257
- decode(value) {
258
- const enumMap = {
259
- [proto.data.RewardType.BLOCK]: "block",
260
- [proto.data.RewardType.UNCLE]: "uncle",
261
- [proto.data.RewardType.UNSPECIFIED]: "unknown",
262
- [proto.data.RewardType.UNRECOGNIZED]: "unknown",
263
- } as const;
264
-
265
- return enumMap[value] ?? "unknown";
266
- },
267
- encode(value) {
268
- throw new Error("encode: not implemented");
269
- },
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";
270
286
  },
271
- );
287
+ };
272
288
 
273
- export type RewardType = typeof RewardType.Type;
289
+ export type RewardType = CodecType<typeof RewardType>;
274
290
 
275
- export const RewardAction = Schema.Struct({
276
- _tag: tag("reward"),
277
- reward: Schema.Struct({
278
- author: Address,
279
- type: RewardType,
280
- value: U256,
281
- }),
291
+ export const RewardAction = MessageCodec({
292
+ author: RequiredCodec(Address),
293
+ type: RequiredCodec(RewardType),
294
+ value: RequiredCodec(U256),
282
295
  });
283
296
 
284
- export type RewardAction = typeof RewardAction.Type;
297
+ export type RewardAction = CodecType<typeof RewardAction>;
285
298
 
286
- export const CallOutput = Schema.Struct({
287
- _tag: tag("callOutput"),
288
- callOutput: Schema.Struct({
289
- gasUsed: Schema.BigIntFromSelf,
290
- output: BytesFromUint8Array,
291
- }),
299
+ export const CallOutput = MessageCodec({
300
+ gasUsed: RequiredCodec(BigIntCodec),
301
+ output: RequiredCodec(BytesFromUint8Array),
292
302
  });
293
303
 
294
- export type CallOutput = typeof CallOutput.Type;
304
+ export type CallOutput = CodecType<typeof CallOutput>;
295
305
 
296
- export const CreateOutput = Schema.Struct({
297
- _tag: tag("createOutput"),
298
- createOutput: Schema.Struct({
299
- address: Address,
300
- code: BytesFromUint8Array,
301
- gasUsed: Schema.BigIntFromSelf,
302
- }),
306
+ export const CreateOutput = MessageCodec({
307
+ address: RequiredCodec(Address),
308
+ code: RequiredCodec(BytesFromUint8Array),
309
+ gasUsed: RequiredCodec(BigIntCodec),
303
310
  });
304
311
 
305
- export type CreateOutput = typeof CreateOutput.Type;
312
+ export type CreateOutput = CodecType<typeof CreateOutput>;
306
313
 
307
- export const Trace = Schema.Struct({
308
- action: Schema.Union(
309
- CallAction,
310
- CreateAction,
311
- SelfDestructAction,
312
- RewardAction,
314
+ export const Trace = MessageCodec({
315
+ action: RequiredCodec(
316
+ OneOfCodec({
317
+ call: CallAction,
318
+ create: CreateAction,
319
+ selfDestruct: SelfDestructAction,
320
+ reward: RewardAction,
321
+ }),
313
322
  ),
314
- error: Schema.optional(Schema.String),
315
- output: Schema.optional(Schema.Union(CallOutput, CreateOutput)),
316
- subtraces: Schema.Number,
317
- 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),
318
332
  });
319
333
 
320
- export type Trace = typeof Trace.Type;
334
+ export type Trace = CodecType<typeof Trace>;
321
335
 
322
- export const TransactionTrace = Schema.Struct({
323
- filterIds: Schema.Array(Schema.Number),
324
- transactionIndex: Schema.Number,
325
- transactionHash: B256,
326
- 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),
327
341
  });
328
342
 
329
- export type TransactionTrace = typeof TransactionTrace.Type;
343
+ export type TransactionTrace = CodecType<typeof TransactionTrace>;
330
344
 
331
- export const Block = Schema.Struct({
332
- header: BlockHeader,
333
- withdrawals: Schema.Array(Withdrawal),
334
- transactions: Schema.Array(Transaction),
335
- receipts: Schema.Array(TransactionReceipt),
336
- logs: Schema.Array(Log),
337
- 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),
338
352
  });
339
353
 
340
- export type Block = typeof Block.Type;
341
-
342
- export const BlockFromBytes = Schema.transform(
343
- Schema.Uint8ArrayFromSelf,
344
- Schema.NullOr(Block),
345
- {
346
- strict: false,
347
- decode(value) {
348
- if (value.length === 0) {
349
- return null;
350
- }
351
- return proto.data.Block.decode(value);
352
- },
353
- encode(value) {
354
- if (value === null) {
355
- return new Uint8Array();
356
- }
357
- return proto.data.Block.encode(value).finish();
358
- },
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);
359
364
  },
360
- );
365
+ };