Skip to content

Chore/veascan vars rename #421

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

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open

Conversation

mani99brar
Copy link
Contributor

@mani99brar mani99brar commented Apr 21, 2025

Updated var taken to saved

  • Regen for updated subgraph config after var name updates.
  • Updated all references to taken with saved

UI Changes

  • Network of veascan mentioned in title, `LATEST {network} SNAPSHOTS"
  • Taken status updated with Saved
Screenshot 2025-04-21 at 8 07 05 PM

PR-Codex overview

This PR primarily focuses on updating GraphQL query definitions in the gql.ts file to improve clarity and structure by formatting the queries with consistent indentation and spacing.

Detailed summary

  • Updated getSnapshots query for better readability.
  • Reformatted getResolvingSnapshots query for improved structure.
  • Enhanced searchSnapshots query with consistent indentation.
  • No functional changes; only formatting adjustments made to the queries.

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

Summary by CodeRabbit

  • New Features

    • Added support for displaying verification start and completion details separately, including timestamps, callers, and transaction hashes.
  • Bug Fixes

    • Updated contract addresses and start blocks for improved data accuracy on supported networks.
  • Refactor

    • Renamed snapshot status from "taken" to "saved" throughout the app and subgraphs.
    • Split verification metadata into distinct "start" and "verified" fields for enhanced clarity.
    • Adjusted filtering and display logic to align with updated schema and status terminology.
  • Style

    • Updated status labels and color coding to match new naming conventions.
  • Chores

    • Incremented package versions for all subgraph packages.

Copy link
Contributor

coderabbitai bot commented Apr 21, 2025

Walkthrough

This set of changes updates multiple subgraph and web application components to align with new contract deployments and schema evolutions. Contract addresses and start blocks for several data sources are updated in subgraph configurations. The Snapshot entity's boolean field is renamed from taken to saved across the schema, mappings, and frontend. The Verification entity is expanded to distinguish between start and verification phases, with corresponding changes in schema, event handlers, and queries. The web application's data mapping, GraphQL queries, and UI components are updated to reflect these schema changes and support new filtering and display logic.

Changes

Files/Paths Change Summary
relayer-subgraph-inbox/package.json
veascan-subgraph-inbox/package.json
veascan-subgraph-outbox/package.json
Incremented package versions.
relayer-subgraph-inbox/subgraph.yaml
veascan-subgraph-inbox/subgraph.yaml
veascan-subgraph-outbox/subgraph.yaml
Updated contract addresses, start blocks, and added/declared new event handlers for new contract deployments and events.
veascan-subgraph-inbox/schema.graphql
veascan-subgraph-inbox/src/VeaInbox.ts
veascan-web/src/components/SnapshotAccordion/AccordionTitle/ColoredLabel.tsx
veascan-web/src/components/SnapshotAccordion/AccordionTitle/index.tsx
veascan-web/src/gql/gql.ts
veascan-web/src/gql/graphql.ts
veascan-web/src/hooks/queries/getInboxData.ts
Renamed Snapshot.taken to Snapshot.saved and updated all relevant code, queries, and UI to use the new field.
veascan-subgraph-outbox/schema.graphql
veascan-subgraph-outbox/src/VeaOutbox.ts
veascan-web/src/gql/gql.ts
veascan-web/src/gql/graphql.ts
veascan-web/src/hooks/queries/getOutboxData.ts
Expanded Verification entity to separate start and verified phases; updated event handlers, queries, and schema accordingly.
veascan-web/src/App.tsx
veascan-web/src/utils/mapDataForAccordion.tsx
Updated data mapping and function signatures to support new schema and filtering logic.
veascan-web/src/components/TxFilterHeader/index.tsx Updated header to display the current network name dynamically.

Sequence Diagram(s)

sequenceDiagram
    participant SmartContract as Smart Contract
    participant Subgraph as Subgraph Mapping
    participant UI as Web UI

    SmartContract->>Subgraph: emit VerificationStarted(epoch)
    Subgraph->>Subgraph: handleVerificationStarted(event)
    Subgraph->>Subgraph: Create Verification (start fields)
    SmartContract->>Subgraph: emit Verified(epoch)
    Subgraph->>Subgraph: handleVerified(event)
    Subgraph->>Subgraph: Update Verification (verified fields)
    UI->>Subgraph: Query Verification (start & verified fields)
    Subgraph-->>UI: Return Verification data
Loading
sequenceDiagram
    participant SmartContract as Smart Contract
    participant Subgraph as Subgraph Mapping
    participant UI as Web UI

    SmartContract->>Subgraph: emit SnapshotSaved
    Subgraph->>Subgraph: Update Snapshot.saved = true
    UI->>Subgraph: Query Snapshots (saved field)
    Subgraph-->>UI: Return Snapshots with saved field
Loading

Possibly related PRs

  • Dev merge into feat/multi-network-relayer #414: Updates contract addresses and start blocks in subgraph configurations for arbitrum-sepolia network inbox data sources, directly matching the current PR's updates for similar contracts and networks.
  • Chore/contract and relayer subgraph redeployment #409: Updates contract addresses and redeploys the relayer-subgraph-inbox with corresponding address changes, involving coordinated redeployment and configuration updates of the same subgraph data sources.

Suggested labels

Type: Maintenance :construction:, Package: VeaScan Subgraph, Package: VeaScan Web

Suggested reviewers

  • alcercu

Poem

Hopping through code with a carrot in paw,
I nibbled at fields—now "saved" is the law!
Verifications split, start and finish in view,
With new addresses, our mappings are true.
Snapshots and claims, all tidy and neat,
This bunny’s delighted—our subgraphs complete!
🥕✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

veascan-web/src/gql/gql.ts

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "eslint-plugin-react".

(The package "eslint-plugin-react" was not found when loaded as a Node module from the directory "/veascan-web".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-react@latest --save-dev

The plugin "eslint-plugin-react" was referenced from the config file in "veascan-web/.eslintrc.json".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro (Legacy)

📥 Commits

Reviewing files that changed from the base of the PR and between d8a6749 and d3ea9f0.

📒 Files selected for processing (1)
  • veascan-web/src/gql/gql.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • veascan-web/src/gql/gql.ts
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: Redirect rules - veascan
  • GitHub Check: Header rules - veascan
  • GitHub Check: Pages changed - veascan
  • GitHub Check: Analyze (javascript)
  • GitHub Check: dependency-review
  • GitHub Check: test
  • GitHub Check: Scorecard analysis

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

netlify bot commented Apr 21, 2025

Deploy Preview for veascan ready!

Name Link
🔨 Latest commit 042b7f8
🔍 Latest deploy log https://app.netlify.com/sites/veascan/deploys/680f78c948d808000970c8bd
😎 Deploy Preview https://deploy-preview-421--veascan.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
veascan-web/src/utils/mapDataForAccordion.tsx (1)

146-150: Filter implementation looks good, consider using strict equality.

The filtering logic correctly filters data based on currentStatus when statusFilter is not zero.

Consider using strict equality (===) instead of loose equality (==) for better type safety:

- ? data.filter((item) => item.currentStatus == statusFilter)
+ ? data.filter((item) => item.currentStatus === statusFilter)
veascan-subgraph-outbox/src/VeaOutbox.ts (1)

106-114: Minor readability: early‑return & optional chaining

The load‑or‑create pattern is good, but the surrounding conditional can be tightened:

-    if (claim && claim.epoch.equals(event.params._epoch)) {
+    if (claim?.epoch && claim.epoch.equals(event.params._epoch)) {

Coupled with extracting the lookup helper (previous comment) you can reduce the nesting and make control flow clearer:

const claim = findClaimByEpoch(event.address, event.params._epoch);
if (!claim) return;

claim.verified = true;
claim.save();

let verification = Verification.load(claim.id) ?? new Verification(claim.id);
...

(optional chaining also satisfies the Biome “useOptionalChain” hint)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a169262 and d8a6749.

📒 Files selected for processing (19)
  • relayer-subgraph-inbox/package.json (1 hunks)
  • relayer-subgraph-inbox/subgraph.yaml (2 hunks)
  • veascan-subgraph-inbox/package.json (1 hunks)
  • veascan-subgraph-inbox/schema.graphql (1 hunks)
  • veascan-subgraph-inbox/src/VeaInbox.ts (6 hunks)
  • veascan-subgraph-inbox/subgraph.yaml (1 hunks)
  • veascan-subgraph-outbox/package.json (1 hunks)
  • veascan-subgraph-outbox/schema.graphql (1 hunks)
  • veascan-subgraph-outbox/src/VeaOutbox.ts (3 hunks)
  • veascan-subgraph-outbox/subgraph.yaml (5 hunks)
  • veascan-web/src/App.tsx (1 hunks)
  • veascan-web/src/components/SnapshotAccordion/AccordionTitle/ColoredLabel.tsx (1 hunks)
  • veascan-web/src/components/SnapshotAccordion/AccordionTitle/index.tsx (2 hunks)
  • veascan-web/src/components/TxFilterHeader/index.tsx (1 hunks)
  • veascan-web/src/gql/gql.ts (3 hunks)
  • veascan-web/src/gql/graphql.ts (26 hunks)
  • veascan-web/src/hooks/queries/getInboxData.ts (4 hunks)
  • veascan-web/src/hooks/queries/getOutboxData.ts (5 hunks)
  • veascan-web/src/utils/mapDataForAccordion.tsx (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (4)
veascan-web/src/App.tsx (1)
veascan-web/src/utils/mapDataForAccordion.tsx (1)
  • mapDataForAccordion (45-151)
veascan-web/src/components/TxFilterHeader/index.tsx (1)
veascan-web/src/contexts/FiltersContext.tsx (1)
  • useFiltersContext (189-189)
veascan-web/src/utils/mapDataForAccordion.tsx (2)
veascan-web/src/hooks/useSnapshots.ts (2)
  • InboxData (20-22)
  • OutboxData (24-24)
veascan-web/src/utils/formatTimestampToHumanReadable.tsx (1)
  • formatTimestampToHumanReadable (1-30)
veascan-subgraph-outbox/src/VeaOutbox.ts (1)
veascan-web/src/gql/graphql.ts (2)
  • Claim (147-161)
  • Verification (1131-1141)
🪛 Biome (1.9.4)
veascan-subgraph-outbox/src/VeaOutbox.ts

[error] 81-81: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: test
  • GitHub Check: dependency-review
  • GitHub Check: Scorecard analysis
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (34)
relayer-subgraph-inbox/package.json (1)

3-3: Version bump looks good.

The version increment from 0.2.3 to 0.2.4 is appropriate for the scope of changes in this PR, maintaining consistency with the other package versions.

veascan-subgraph-outbox/package.json (1)

3-3: Version bump looks good.

This version increment to 0.2.4 correctly aligns with the version in the relayer-subgraph-inbox package, maintaining consistency across related packages.

veascan-subgraph-inbox/package.json (1)

3-3: Version increment to 0.2.3 is appropriate.

The version bump from 0.2.1 to 0.2.3 reflects the schema changes (renaming taken to saved). This keeps the versioning aligned with related packages in the ecosystem.

veascan-subgraph-inbox/schema.graphql (1)

37-37:

✅ Verification successful

Field rename from taken to saved looks good.

This change correctly implements the variable rename mentioned in the PR objectives. The boolean type and non-null constraint have been preserved.


🏁 Script executed:

#!/bin/bash
# Verify that all references to the 'taken' field have been updated to 'saved'
echo "Checking for remaining references to 'taken' field in the codebase..."
rg "\.taken\b|\btaken:" --type ts --type graphql 

Length of output: 237


To ensure we catch references in .graphql files too, let’s search for the bare taken token across all files:


🏁 Script executed:

#!/bin/bash
echo "Searching for any remaining 'taken' references across the entire codebase..."
rg -n '\btaken\b'

Length of output: 66655


Let’s check specifically within the subgraph directory to ensure no leftover taken references:


🏁 Script executed:

#!/bin/bash
echo "Searching for any remaining 'taken' references in veascan‑subgraph‑inbox..."
rg -n '\btaken\b' veascan-subgraph-inbox

Length of output: 209


✅ Field rename complete: takensaved

No occurrences of taken remain in the veascan-subgraph-inbox directory. The schema field and all references have been updated to:

  • veascan-subgraph-inbox/schema.graphql (line 37):
    saved: Boolean!

Approving these changes for merge.

veascan-web/src/components/TxFilterHeader/index.tsx (2)

71-77: Good addition of network to the destructured context properties.

The addition of network to the destructured properties from useFiltersContext() is correctly implemented.


81-81: UI update for network name in title looks great.

The header now correctly displays the network name as specified in the PR objectives, making it clearer to users which network they're viewing snapshots for.

veascan-web/src/components/SnapshotAccordion/AccordionTitle/ColoredLabel.tsx (1)

12-12: Good rename from "Taken" to "Saved" in the variant colors.

This change correctly implements the requested variable renaming from "Taken" to "Saved" while maintaining the same color value "lightYellow". This aligns with the broader renaming effort described in the PR objectives.

veascan-web/src/App.tsx (1)

78-78: Proper update to pass statusFilter to mapDataForAccordion.

The addition of the statusFilter parameter ensures that snapshot data is correctly filtered according to the user's selection in the UI. This change correctly adapts to the updated function signature in the mapDataForAccordion utility.

veascan-subgraph-inbox/subgraph.yaml (2)

11-11: Updated contract address for VeaInboxArbToEthTestnet.

The contract address has been updated for the VeaInboxArbToEthTestnet data source on the arbitrum-sepolia network. This appears to align with a new contract deployment.


13-13: Updated start block for VeaInboxArbToEthTestnet indexing.

The start block has been significantly increased from 77452741 to 139057282, which corresponds with the new contract deployment. This ensures the subgraph will begin indexing from the correct block.

veascan-web/src/hooks/queries/getInboxData.ts (1)

13-13: Consistent rename of "taken" to "saved" across all GraphQL queries.

The rename from taken to saved has been consistently applied across all four GraphQL queries in this file. This ensures that the frontend properly retrieves the renamed field from the subgraph, maintaining consistency with the schema changes.

Also applies to: 44-44, 83-83, 116-116

veascan-web/src/components/SnapshotAccordion/AccordionTitle/index.tsx (2)

62-62: Rename from taken to saved looks good.

Property renamed consistently with PR objectives. This change aligns with the terminology update throughout the codebase.


133-133: Default status label updated from "Taken" to "Saved".

The default return value in the parseStatus function has been updated to reflect the new terminology. This ensures UI consistency with the data model changes.

veascan-web/src/hooks/queries/getOutboxData.ts (2)

22-24: Field names updated in verification object.

The verification fields have been renamed to be more specific:

  • timestampverifiedTimestamp
  • callerverifiedCaller
  • txHashverifiedTxHash

This change adds clarity by explicitly indicating these are verification-related timestamps.


63-65: Consistent renaming of verification fields across all queries.

The verification field renames have been consistently applied across all queries in the file. This ensures uniformity in the data structure throughout the application.

Also applies to: 104-106, 145-147, 186-188

veascan-subgraph-inbox/src/VeaInbox.ts (3)

64-64: Initialization of new snapshots updated to use saved property.

The property has been renamed from taken to saved in the snapshot initialization, maintaining consistent terminology throughout the codebase.

Also applies to: 87-87


130-130: Snapshot status update in handleSnapshotSaved renamed to saved.

The property used to mark a snapshot as taken/saved has been updated in the event handler, maintaining consistent terminology changes.


150-150: All remaining occurrences of taken renamed to saved.

The rename has been consistently applied throughout all relevant functions in the file, including in handleSnapshotSent event handler for both existing and new snapshots.

Also applies to: 207-207, 228-228

relayer-subgraph-inbox/subgraph.yaml (2)

35-37: Updated contract address and start block for VeaInboxArbToEthTestnet.

The data source has been updated to point to a new contract deployment:

  • New address: 0xAA4F00c86bf956C0Fae603D030CBc2dA7f8B7C5B
  • New start block: 139057282

This change ensures the subgraph indexes events from the latest contract deployment.


91-93: Updated contract address and start block for VeaInboxArbToGnosisTestnet.

The data source has been updated to point to a new contract deployment:

  • New address: 0xa0d410b202D69C36871d5135ce42fC7D379BBB1c
  • New start block: 139057386

This change ensures the subgraph indexes events from the latest contract deployment.

veascan-web/src/utils/mapDataForAccordion.tsx (2)

46-47: Function signature update looks good.

The function now accepts statusFilter as a parameter instead of retrieving it from context, which improves testability and decouples the function from context.


109-120: Verification property access correctly updated.

The code correctly accesses the new verification field names (verifiedTxHash, verifiedTimestamp, verifiedCaller) which aligns with the schema changes in the Verification entity.

veascan-subgraph-outbox/schema.graphql (1)

33-38: Verification entity refactoring looks good.

The schema change properly splits the verification lifecycle into two phases by replacing the single set of mandatory fields with two sets of optional fields:

  1. Start phase: startTimestamp, startCaller, startTxHash
  2. Verified phase: verifiedTimestamp, verifiedCaller, verifiedTxHash

This provides more granular tracking of the verification process.

veascan-subgraph-outbox/subgraph.yaml (5)

9-11: Contract address and start block updates look good.

The contract address and start block have been updated for the VeaOutboxArbToEthTestnet data source.


21-21: Entity list update is consistent.

Adding VerificationStarted to the entities list is consistent with the new event handling.


34-35: New event handler added correctly.

The event handler for VerificationStarted has been properly added to support the enhanced verification lifecycle tracking.


53-53: Entity list update for Devnet is consistent.

Similar to the Testnet configuration, adding VerificationStarted to the Devnet entities list maintains consistency.


66-67: Event handler added for Devnet as well.

The VerificationStarted event handler has been properly added to the Devnet data source, maintaining consistency between environments.

veascan-web/src/gql/gql.ts (4)

16-35: GraphQL queries correctly updated for snapshots.

All snapshot-related queries have been updated to use saved instead of taken, maintaining consistency with the schema changes.


88-113: Verification field names correctly updated in queries.

All claim-related queries have been updated to use the new verification field names (verifiedTimestamp, verifiedCaller, verifiedTxHash), maintaining consistency with the schema changes.


58-77: Type-safe function signatures updated correctly.

The GraphQL function signatures have been updated to match the new query strings for snapshot-related queries.


94-113: Type-safe function signatures updated for claim queries.

The GraphQL function signatures have been updated to match the new query strings for claim-related queries with the updated verification fields.

veascan-subgraph-outbox/src/VeaOutbox.ts (1)

7-8: Import looks correct – no issues found

The additional VerificationStarted import is accurate and scoped to the same generated ABI as the other events.

veascan-web/src/gql/graphql.ts (1)

278-285: Generated file – skipping detailed review

graphql.ts is auto‑generated by GraphQL code‑gen. All changes are the mechanical result of the schema rename (taken → saved) and the new Verification fields. Manual edits here will be overwritten, so no action required.

Also applies to: 381-389, 582-589, 950-956, 1059-1063, 1124-1129, 1135-1141, 1177-1233, 1247-1253, 1307-1308, 1336-1337, 1367-1368, 1397-1398, 1456-1459, 1491-1494, 1526-1529, 1561-1564, 1596-1599, 1701-1702, 1862-1863, 2060-2061, 2234-2235, 2534-2543, 2706-2715, 2880-2890, 3054-3065, 3230-3240

Comment on lines 72 to 91
export function handleVerificationStarted(event: VerificationStarted): void {
const ref = getRef(event.address);
for (
let i = ref.totalClaims.minus(BigInt.fromI32(1));
i.ge(BigInt.fromI32(0));
i = i.minus(BigInt.fromI32(1))
) {
const claimId = event.address.toHexString() + "-" + i.toString();
const claim = Claim.load(claimId);
if (claim && claim.epoch.equals(event.params._epoch)) {
const verification = new Verification(claim.id);
verification.claim = claim.id;
verification.startTimestamp = event.block.timestamp;
verification.startCaller = event.transaction.from;
verification.startTxHash = event.transaction.hash;
verification.save();
break;
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Factor‑out duplicate “claim lookup” logic & guard against overwriting an existing Verification

Both handleVerificationStarted and handleVerified walk ref.totalClaims → 0 to locate the claim for a given epoch. Duplicating this loop:

  1. Increases maintenance overhead.
  2. Risks subtle divergence if one of the handlers is updated later.
  3. Slightly hurts indexing performance for large claim sets.

In addition, if for any reason VerificationStarted fires more than once for the same claim (re‑org, buggy contract, etc.) the current code will overwrite the existing entity, wiping any previously written verified* fields.

-      const verification = new Verification(claim.id);
-      verification.claim = claim.id;
+      let verification = Verification.load(claim.id);
+      if (!verification) {
+        verification = new Verification(claim.id);
+        verification.claim = claim.id;
+      }

Consider extracting the “findClaimByEpoch” loop into a small helper:

function findClaimByEpoch(outbox: Address, epoch: BigInt): Claim | null {
  const ref = getRef(outbox);
  for (let i = ref.totalClaims.minus(BigInt.fromI32(1)); i.ge(BigInt.fromI32(0)); i = i.minus(BigInt.fromI32(1))) {
    const claim = Claim.load(outbox.toHexString() + "-" + i.toString());
    if (claim?.epoch.equals(epoch)) return claim;
  }
  return null;
}

That would turn the handler into:

const claim = findClaimByEpoch(event.address, event.params._epoch);
if (claim) {
  let verification = Verification.load(claim.id) ?? new Verification(claim.id);
  ...
}

This keeps both handlers DRY and prevents accidental field loss.

🧰 Tools
🪛 Biome (1.9.4)

[error] 81-81: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

jaybuidl
jaybuidl previously approved these changes Apr 25, 2025
@mani99brar mani99brar dismissed jaybuidl’s stale review April 28, 2025 12:19

The merge-base changed after approval.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants