Skip to content

Make fields not nullable #137

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "beaconchain: make fields required",
"packageName": "@apibara/beaconchain",
"email": "[email protected]",
"dependentChangeType": "patch"
}
7 changes: 7 additions & 0 deletions change/@apibara-evm-792c8a2f-e1df-4606-9ba7-a2dacb1264aa.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "evm: make more fields required",
"packageName": "@apibara/evm",
"email": "[email protected]",
"dependentChangeType": "patch"
Comment on lines +2 to +6
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Consider using a major version bump instead of patch.

The changes to make fields required are breaking changes that affect backward compatibility. According to semver:

  • A patch should only contain backward compatible bug fixes
  • Breaking changes should trigger a major version bump
-  "type": "prerelease",
-  "dependentChangeType": "patch"
+  "type": "prerelease",
+  "dependentChangeType": "major"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"type": "prerelease",
"comment": "evm: make more fields required",
"packageName": "@apibara/evm",
"email": "[email protected]",
"dependentChangeType": "patch"
"type": "prerelease",
"comment": "evm: make more fields required",
"packageName": "@apibara/evm",
"email": "[email protected]",
"dependentChangeType": "major"

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "starknet: make some types required",
"packageName": "@apibara/starknet",
"email": "[email protected]",
"dependentChangeType": "patch"
}
12 changes: 2 additions & 10 deletions examples/beaconchain-client/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,9 @@ const command = defineCommand({
console.log(response);

const filter = Filter.make({
// blobs: [{ includeTransaction: true }],
// transactions: [
// {
// // create: true,
// // to: "0xFf00000000000000000000000000000000102421",
// // to: "0xAD3C787556B1E9D32D3AE4f2A0B4b1dC6692eDAc",
// // includeBlob: true,
// },
// ],
validators: [{}],
transactions: [{}],
blobs: [{}],
// validators: [{}],
});

const startBlock = 5_931_000;
Expand Down
7 changes: 4 additions & 3 deletions examples/evm-client/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const command = defineCommand({
args: {
stream: {
type: "string",
default: "https://sepolia.ethereum.a5a.ch",
default: "https://ethereum-sepolia.preview.apibara.org",
description: "EVM stream URL",
},
authToken: {
Expand All @@ -36,8 +36,9 @@ const command = defineCommand({
console.log(response);

const filter = Filter.make({
header: "on_data",
transactions: [{}],
transactions: [
{ includeReceipt: true, transactionStatus: "all", includeLogs: true },
],
withdrawals: [{}],
logs: [{}],
});
Expand Down
43 changes: 17 additions & 26 deletions examples/starknet-client/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
import assert from "node:assert";
import { createClient } from "@apibara/protocol";
import {
type Abi,
Filter,
StarknetStream,
decodeEvent,
getSelector,
} from "@apibara/starknet";
import { type Abi, Filter, StarknetStream } from "@apibara/starknet";
import { defineCommand, runMain } from "citty";
import consola from "consola";
import { colors } from "consola/utils";
import { formatUnits } from "viem";

const abi = [
{
Expand Down Expand Up @@ -62,20 +54,19 @@ const command = defineCommand({
console.log(response);

const filter = Filter.make({
events: [
{
address:
"0x053c91253bc9682c04929ca02ed00b3e423f6710d2ee7e0d5ebb06f3ecf368a8",
keys: [getSelector("Transfer")],
},
],
transactions: [{ includeReceipt: true }],
messages: [{}],
events: [{}],
storageDiffs: [{}],
contractChanges: [{}],
nonceUpdates: [{}],
});

const request = StarknetStream.Request.make({
filter: [filter],
finality: "accepted",
finality: "pending",
startingCursor: {
orderKey: 1_078_335n,
orderKey: 1_083_705n,
},
});

Expand All @@ -95,14 +86,14 @@ const command = defineCommand({
);

for (const event of block.events) {
const { args, transactionHash } = decodeEvent({
abi,
eventName: "Transfer",
event,
});
consola.info(
`${prettyAddress(args.from)} -> ${prettyAddress(args.to)} ${formatUnits(args.value, 6)} ${colors.gray(transactionHash ?? "")}`,
);
// const { args, transactionHash } = decodeEvent({
// abi,
// eventName: "Transfer",
// event,
// });
// consola.info(
// `${prettyAddress(args.from)} -> ${prettyAddress(args.to)} ${formatUnits(args.value, 6)} ${colors.gray(transactionHash ?? "")}`,
// );
Comment on lines +89 to +96
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Remove commented code.

Instead of keeping commented code in the codebase:

  1. Remove it if it's no longer needed
  2. If it's for reference, move it to documentation
  3. If it's temporary, create a TODO issue to track its restoration

}
}

Expand Down
103 changes: 56 additions & 47 deletions packages/beaconchain/src/block.ts
Original file line number Diff line number Diff line change
@@ -1,91 +1,100 @@
import { AccessListItem, Signature } from "@apibara/evm";
import { AccessListItem } from "@apibara/evm";
import { BytesFromUint8Array } from "@apibara/protocol";
import { Schema } from "@effect/schema";

import { Address, B256, B384, U128, U256, ValidatorStatus } from "./common";
import * as proto from "./proto";

export const ExecutionPayload = Schema.Struct({
parentHash: Schema.optional(B256),
feeRecipient: Schema.optional(Address),
stateRoot: Schema.optional(B256),
receiptsRoot: Schema.optional(B256),
parentHash: B256,
feeRecipient: Address,
stateRoot: B256,
receiptsRoot: B256,
logsBloom: BytesFromUint8Array,
prevRandao: Schema.optional(B256),
blockNumber: Schema.optional(Schema.BigIntFromSelf),
timestamp: Schema.optional(Schema.DateFromSelf),
prevRandao: B256,
blockNumber: Schema.BigIntFromSelf,
timestamp: Schema.DateFromSelf,
});

export type ExecutionPayload = typeof ExecutionPayload.Type;

export const BlockHeader = Schema.Struct({
slot: Schema.BigIntFromSelf,
proposerIndex: Schema.Number,
parentRoot: Schema.optional(B256),
stateRoot: Schema.optional(B256),
parentRoot: B256,
stateRoot: B256,
randaoReveal: BytesFromUint8Array,
depositCount: Schema.optional(Schema.BigIntFromSelf),
depositRoot: Schema.optional(B256),
blockHash: Schema.optional(B256),
graffiti: Schema.optional(B256),
depositCount: Schema.BigIntFromSelf,
depositRoot: B256,
blockHash: B256,
graffiti: B256,
executionPayload: Schema.optional(ExecutionPayload),
blobKzgCommitments: Schema.optional(Schema.Array(B384)),
blobKzgCommitments: Schema.Array(B384),
});

export type BlockHeader = typeof BlockHeader.Type;

export const Validator = Schema.Struct({
filterIds: Schema.optional(Schema.Array(Schema.Number)),
validatorIndex: Schema.optional(Schema.Number),
balance: Schema.optional(Schema.BigIntFromSelf),
status: Schema.optional(ValidatorStatus),
pubkey: Schema.optional(B384),
withdrawalCredentials: Schema.optional(B256),
effectiveBalance: Schema.optional(Schema.BigIntFromSelf),
slashed: Schema.optional(Schema.Boolean),
activationEligibilityEpoch: Schema.optional(Schema.BigIntFromSelf),
activationEpoch: Schema.optional(Schema.BigIntFromSelf),
exitEpoch: Schema.optional(Schema.BigIntFromSelf),
withdrawableEpoch: Schema.optional(Schema.BigIntFromSelf),
filterIds: Schema.Array(Schema.Number),
validatorIndex: Schema.Number,
balance: Schema.BigIntFromSelf,
status: ValidatorStatus,
pubkey: B384,
withdrawalCredentials: B256,
effectiveBalance: Schema.BigIntFromSelf,
slashed: Schema.Boolean,
activationEligibilityEpoch: Schema.BigIntFromSelf,
activationEpoch: Schema.BigIntFromSelf,
exitEpoch: Schema.BigIntFromSelf,
withdrawableEpoch: Schema.BigIntFromSelf,
});

export const Blob = Schema.Struct({
filterIds: Schema.optional(Schema.Array(Schema.Number)),
blobIndex: Schema.optional(Schema.Number),
blob: Schema.optional(Schema.Uint8ArrayFromSelf),
kzgCommitment: Schema.optional(B384),
kzgProof: Schema.optional(B384),
kzgCommitmentInclusionProof: Schema.optional(Schema.Array(B256)),
blobHash: Schema.optional(B256),
transactionIndex: Schema.optional(Schema.Number),
transactionHash: Schema.optional(B256),
filterIds: Schema.Array(Schema.Number),
blobIndex: Schema.Number,
blob: Schema.Uint8ArrayFromSelf,
kzgCommitment: B384,
kzgProof: B384,
kzgCommitmentInclusionProof: Schema.Array(B256),
blobHash: B256,
transactionIndex: Schema.Number,
transactionHash: B256,
});

export const Signature = Schema.Struct({
r: Schema.optional(U256),
s: Schema.optional(U256),
v: Schema.optional(U256),
YParity: Schema.optional(Schema.Boolean),
});

export type Signature = typeof Signature.Type;

export const Transaction = Schema.Struct({
filterIds: Schema.optional(Schema.Array(Schema.Number)),
transactionHash: Schema.optional(B256),
nonce: Schema.optional(Schema.BigIntFromSelf),
transactionIndex: Schema.optional(Schema.Number),
from: Schema.optional(Address),
filterIds: Schema.Array(Schema.Number),
transactionHash: B256,
nonce: Schema.BigIntFromSelf,
transactionIndex: Schema.Number,
from: Address,
to: Schema.optional(Address),
value: Schema.optional(U256),
value: U256,
gasPrice: Schema.optional(U128),
gasLimit: Schema.optional(U128),
maxFeePerGas: Schema.optional(U128),
maxPriorityFeePerGas: Schema.optional(U128),
input: Schema.optional(Schema.Uint8ArrayFromSelf),
input: Schema.Uint8ArrayFromSelf,
signature: Schema.optional(Signature),
chainId: Schema.optional(Schema.BigIntFromSelf),
accessList: Schema.optional(Schema.Array(AccessListItem)),
transactionType: Schema.optional(Schema.BigIntFromSelf),
accessList: Schema.Array(AccessListItem),
transactionType: Schema.BigIntFromSelf,
maxFeePerBlobGas: Schema.optional(U128),
blobVersionedHashes: Schema.optional(Schema.Array(B256)),
blobVersionedHashes: Schema.Array(B256),
});

export type Transaction = typeof Transaction.Type;

export const Block = Schema.Struct({
header: Schema.optional(BlockHeader),
header: BlockHeader,
validators: Schema.Array(Validator),
blobs: Schema.Array(Blob),
transactions: Schema.Array(Transaction),
Expand Down
Loading
Loading