Skip to content
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

feat(torii): add transaction hash to erc_transfers table #2520

Closed
wants to merge 1 commit into from

Conversation

lambda-0x
Copy link
Collaborator

@lambda-0x lambda-0x commented Oct 11, 2024

Stack:

⚠️ Part of a stack created by spr. Do not merge manually using the UI - doing so may have unexpected results.

Summary by CodeRabbit

  • New Features

    • Introduced a new function to extract transaction hashes from event IDs, enhancing event processing capabilities.
    • Added a transaction_hash field to the erc_transfers table for improved data capture during token transfers.
  • Bug Fixes

    • Updated method signatures across various processors to ensure the transaction hash is utilized correctly.
  • Documentation

    • Enhanced comments in processing methods to clarify expectations for event ID formatting.
  • Style

    • Updated field names in mappings to follow camelCase formatting and ensure non-nullable types.
  • Chores

    • Modified database schema to include the new transaction_hash column in the erc_transfers table.

Copy link

codecov bot commented Oct 11, 2024

Codecov Report

Attention: Patch coverage is 0% with 43 lines in your changes missing coverage. Please review.

Project coverage is 69.31%. Comparing base (67a1747) to head (1ee2bb6).
Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
...torii/core/src/processors/erc20_legacy_transfer.rs 0.00% 11 Missing ⚠️
crates/torii/core/src/processors/erc20_transfer.rs 0.00% 11 Missing ⚠️
crates/torii/core/src/sql/erc.rs 0.00% 8 Missing ⚠️
crates/torii/core/src/engine.rs 0.00% 5 Missing ⚠️
...rates/torii/graphql/src/object/erc/erc_transfer.rs 0.00% 4 Missing ⚠️
...orii/core/src/processors/erc721_legacy_transfer.rs 0.00% 2 Missing ⚠️
...rates/torii/core/src/processors/erc721_transfer.rs 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2520      +/-   ##
==========================================
- Coverage   69.35%   69.31%   -0.04%     
==========================================
  Files         388      388              
  Lines       49988    50025      +37     
==========================================
+ Hits        34667    34674       +7     
- Misses      15321    15351      +30     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

coderabbitai bot commented Oct 12, 2024

Walkthrough

Ohayo, sensei! This pull request introduces several changes primarily in the engine.rs file, adding a function to extract transaction hashes from event IDs. It modifies event and transaction processing across multiple processor files to utilize this new function. Additionally, updates are made to SQL handling methods to store transaction hashes, along with changes to GraphQL mappings for non-nullable types and camelCase formatting. A new column for transaction hashes is also added to the database schema, ensuring consistency and clarity in handling token transfers.

Changes

File Path Change Summary
crates/torii/core/src/engine.rs Added function get_transaction_hash_from_event_id for extracting transaction hashes from event IDs.
crates/torii/core/src/processors/erc20_legacy_transfer.rs
.../erc20_transfer.rs
.../erc721_legacy_transfer.rs
.../erc721_transfer.rs
Updated process method signatures to use event_id and integrated transaction_hash into transfer handling.
crates/torii/core/src/sql/erc.rs Modified handle_erc20_transfer and handle_erc721_transfer methods to include transaction_hash.
crates/torii/graphql/src/mapping.rs
.../erc/erc_balance.rs
.../erc/erc_transfer.rs
Updated field types to non-nullable and renamed fields to camelCase; added transactionHash field.
crates/torii/migrations/20241011103804_add_transaction_hash_in_erc_transfers_table.sql Added transaction_hash column to erc_transfers table, defined as NOT NULL.

Possibly related PRs

Suggested reviewers

  • glihm: Suggested for review due to familiarity with the relevant codebase and potential insights into the changes made.

🪧 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 anywhere in the PR title to generate the title automatically.

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

@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: 3

🧹 Outside diff range and nitpick comments (7)
crates/torii/core/src/processors/erc721_transfer.rs (1)

Line range hint 53-62: Ohayo once more, sensei! Excellent implementation!

The addition of get_transaction_hash_from_event_id and its inclusion in the db.handle_erc721_transfer call is spot on. This change aligns perfectly with the PR objectives to add transaction hash to the erc_transfers table.

One small suggestion to consider:

You might want to add a debug log for the transaction hash, similar to how you're logging other transfer details. This could be helpful for troubleshooting. Here's a suggested addition:

 debug!(target: LOG_TARGET, from = ?from, to = ?to, token_id = ?token_id, "ERC721 Transfer");
+debug!(target: LOG_TARGET, transaction_hash = ?transaction_hash, "ERC721 Transfer Transaction Hash");

What do you think, sensei? Would this additional logging be useful?

crates/torii/core/src/processors/erc721_legacy_transfer.rs (2)

44-44: Signature update is on point, sensei!

Removing the underscore from _event_id aligns perfectly with its new usage in the method. Great attention to detail!

Consider adding a brief comment explaining the purpose of the event_id parameter for improved code readability.


53-53: Ohayo, sensei! Excellent addition of transaction hash handling!

The new line extracting the transaction hash and its subsequent use in db.handle_erc721_transfer significantly improves the traceability of ERC721 transfers. This change aligns perfectly with the PR objectives.

Consider adding a brief comment explaining the importance of including the transaction hash in the transfer record.

Also applies to: 62-62

crates/torii/core/src/processors/erc20_legacy_transfer.rs (1)

50-64: Ohayo, sensei! These changes are looking mighty fine!

The addition of transaction_hash and its integration into the db.handle_erc20_transfer call align perfectly with our PR objectives. Great job on seamlessly incorporating this new piece of information!

A small suggestion to enhance readability:

Consider extracting the db.handle_erc20_transfer call into a separate line for better readability. Here's a quick example:

let transfer_result = db.handle_erc20_transfer(
    token_address,
    from,
    to,
    value,
    world.provider(),
    block_timestamp,
    &transaction_hash,
);
transfer_result.await?;

This separation makes the code a bit easier on the eyes and could potentially make future modifications simpler. What do you think, sensei?

crates/torii/graphql/src/object/erc/erc_balance.rs (1)

Line range hint 83-110: Ohayo, sensei! Consider a small refactoring opportunity.

While the changes improve naming consistency, there's an opportunity to reduce code duplication between the ERC20 and ERC721 logic. Consider extracting the common parts of the token metadata creation into a separate function. This could make the code more maintainable and easier to extend in the future.

For example:

fn create_token_metadata(row: &BalanceQueryResultRaw, token_id: Option<String>) -> Value {
    Value::Object(ValueMapping::from([
        (Name::new("contractAddress"), Value::String(row.contract_address.clone())),
        (Name::new("name"), Value::String(row.name.clone())),
        (Name::new("symbol"), Value::String(row.symbol.clone())),
        (Name::new("tokenId"), token_id.map_or(Value::Null, Value::String)),
        (Name::new("decimals"), Value::String(row.decimals.to_string())),
    ]))
}

This function could then be called from both the ERC20 and ERC721 branches, reducing duplication and making the code more DRY.

crates/torii/core/src/engine.rs (2)

613-614: Ohayo, sensei! Consider centralizing the event_id format information.

The comments explaining the event_id format are identical in two locations. To improve maintainability, consider:

  1. Creating a constant for the event_id format.
  2. Adding this information to the documentation of the relevant ERC processors.

This approach would reduce duplication and make it easier to update if the format changes in the future.

Also applies to: 686-687


Line range hint 613-910: Ohayo, sensei! Consider a broader refactoring for event_id handling.

The changes you've made are improving the handling of event_ids and transaction hashes. To further enhance consistency and maintainability across the codebase, consider:

  1. Creating a dedicated EventId struct that encapsulates the parsing and validation logic.
  2. Using this struct throughout the codebase instead of raw strings for event_ids.
  3. Implementing methods on EventId for extracting components like transaction hash, block number, etc.

This approach would centralize the event_id logic, making it easier to maintain and reducing the risk of inconsistencies.

Would you like me to sketch out a basic structure for this EventId struct?

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 9b47e7c and 375f1d6.

📒 Files selected for processing (10)
  • crates/torii/core/src/engine.rs (3 hunks)
  • crates/torii/core/src/processors/erc20_legacy_transfer.rs (2 hunks)
  • crates/torii/core/src/processors/erc20_transfer.rs (3 hunks)
  • crates/torii/core/src/processors/erc721_legacy_transfer.rs (4 hunks)
  • crates/torii/core/src/processors/erc721_transfer.rs (4 hunks)
  • crates/torii/core/src/sql/erc.rs (7 hunks)
  • crates/torii/graphql/src/mapping.rs (1 hunks)
  • crates/torii/graphql/src/object/erc/erc_balance.rs (2 hunks)
  • crates/torii/graphql/src/object/erc/erc_transfer.rs (3 hunks)
  • crates/torii/migrations/20241011103804_add_transaction_hash_in_erc_transfers_table.sql (1 hunks)
🧰 Additional context used
🔇 Additional comments (23)
crates/torii/core/src/processors/erc20_transfer.rs (4)

10-10: Ohayo, sensei! New import looks good!

The addition of get_transaction_hash_from_event_id aligns perfectly with our mission to enhance the erc_transfers table with transaction hash information. It's like adding a secret ingredient to our code ramen!


44-44: Ohayo again, sensei! Parameter update looks sharp!

Removing the underscore from _event_id is like unveiling a hidden treasure in our code dojo. It signals that we're now putting this parameter to good use. Excellent move!


53-53: Transaction hash extraction, a true code ninja move!

Ohayo, sensei! This line is the heart of our mission. By extracting the transaction hash from the event ID, we're adding a powerful new technique to our ERC20 transfer arsenal. Well done!


55-64: Ohayo once more, sensei! Method call upgrade is masterful!

The db.handle_erc20_transfer call has evolved like a Pokémon! Not only is it more readable with its multi-line format, but it now includes the crucial &transaction_hash parameter. This completes our quest to enhance the erc_transfers table. Excellent work, code samurai!

crates/torii/core/src/processors/erc721_transfer.rs (2)

10-10: Ohayo, sensei! Nice import addition!

The new import statement for get_transaction_hash_from_event_id is well-placed and specific. It's great to see you're importing only what's needed for the upcoming changes.


44-44: Ohayo again, sensei! Sharp eye on that parameter!

Excellent move renaming _event_id to event_id. This change clearly signals that we're now using this parameter in the method. It's a small but important detail that improves code clarity.

crates/torii/core/src/processors/erc721_legacy_transfer.rs (2)

10-10: Ohayo, sensei! New import looks good!

The addition of get_transaction_hash_from_event_id import is spot-on for the new functionality. It's properly scoped and follows our naming conventions.


10-10: Ohayo, sensei! Overall, these changes are a solid improvement!

The modifications to include transaction hash information in ERC721 transfer processing align perfectly with the PR objectives. They enhance traceability and data completeness for ERC721 transfers.

Here's a quick summary of the changes:

  1. Added import for get_transaction_hash_from_event_id
  2. Updated method signature to use event_id
  3. Extracted transaction hash from event ID
  4. Included transaction hash in database handling

These changes collectively contribute to a more robust and informative ERC721 transfer processing system. Great work, sensei!

Also applies to: 44-44, 53-53, 62-62

crates/torii/core/src/processors/erc20_legacy_transfer.rs (2)

10-10: Ohayo, sensei! New import looks good!

The new import for get_transaction_hash_from_event_id is well-placed and aligns with the upcoming changes in the process method.


44-44: Signature update looks sharp, sensei!

The removal of the underscore prefix from event_id nicely indicates that we're now using this parameter. It's a clean change that aligns well with the new functionality.

crates/torii/graphql/src/object/erc/erc_balance.rs (2)

83-85: Ohayo, sensei! Excellent work on improving naming conventions!

The changes to camelCase for object keys (tokenId, contractAddress, tokenMetadata) in the "erc20" branch enhance code consistency and readability. This aligns well with JavaScript/TypeScript conventions, which is beneficial for GraphQL APIs.

Also applies to: 91-91


100-100: Consistency across token types - well done, sensei!

The changes to camelCase for object keys (contractAddress, tokenId, tokenMetadata) in the "erc721" branch maintain consistency with the ERC20 implementation. This uniform approach across different token types enhances the overall code quality and API consistency.

Also applies to: 103-103, 110-110

crates/torii/graphql/src/mapping.rs (4)

149-151: Ohayo, sensei! Great improvements to ERC_BALANCE_TYPE_MAPPING!

The changes look good and bring several improvements:

  1. All fields are now non-nullable (TypeRef::named_nn), which is excellent for required fields.
  2. Renaming "token_metadata" to "tokenMetadata" improves consistency with GraphQL naming conventions.

These updates enhance type safety and align better with GraphQL best practices. Nice work!


155-161: Ohayo again, sensei! Excellent updates to ERC_TRANSFER_TYPE_MAPPING!

These changes bring significant improvements:

  1. All fields are now non-nullable (TypeRef::named_nn), enhancing type safety.
  2. Renaming "executed_at" to "executedAt" and "token_metadata" to "tokenMetadata" improves consistency with GraphQL naming conventions.
  3. The addition of the "transactionHash" field (also non-nullable) aligns perfectly with the PR objective of adding transaction hash to the erc_transfers table.

These updates not only improve the type definitions but also extend the functionality as intended. Great job!


165-169: Ohayo once more, sensei! Fantastic improvements to ERC_TOKEN_TYPE_MAPPING!

The changes here are on point:

  1. All fields are now non-nullable (TypeRef::named_nn), which greatly enhances type safety.
  2. Renaming "token_id" to "tokenId" and "contract_address" to "contractAddress" improves consistency with GraphQL naming conventions.

These updates bring the ERC_TOKEN_TYPE_MAPPING in line with best practices and make it more robust. Excellent work!


149-169: Ohayo, sensei! Overall fantastic improvements to the GraphQL type mappings!

The changes across ERC_BALANCE_TYPE_MAPPING, ERC_TRANSFER_TYPE_MAPPING, and ERC_TOKEN_TYPE_MAPPING consistently enhance the code quality:

  1. All fields are now non-nullable (TypeRef::named_nn), significantly improving type safety.
  2. Field names have been updated to camelCase, aligning with GraphQL naming conventions.
  3. The addition of the "transactionHash" field to ERC_TRANSFER_TYPE_MAPPING fulfills the PR objective.

These updates not only improve the robustness of the type definitions but also enhance the overall consistency and functionality of the GraphQL schema. Great job on these changes!

crates/torii/core/src/sql/erc.rs (3)

28-28: Ohayo, sensei! The ERC20 transfer handler now includes the transaction hash. Sugoi!

The addition of the transaction_hash parameter and its usage in store_erc_transfer_event aligns perfectly with the PR objective. The implementation looks clean and doesn't interfere with existing logic. Nicely done!

Also applies to: 47-47


84-84: Ohayo again, sensei! The ERC721 transfer handler is now equipped with transaction hash powers!

Just like its ERC20 counterpart, this function has been updated to include the transaction_hash parameter and pass it along to store_erc_transfer_event. The changes are consistent and well-implemented. Excellent work!

Also applies to: 102-102


Line range hint 314-338: Ohayo once more, sensei! The ERC transfer event storage now captures the essence of transactions!

The store_erc_transfer_event function has been skillfully updated to include the transaction_hash. The SQL query and parameters have been adjusted accordingly. This change aligns perfectly with the PR objective. Excellent implementation!

However, to ensure the harmony of our codebase, we should verify that all calls to this function have been updated to include the new transaction_hash parameter.

Let's use our ninja skills to check for any missed function calls:

crates/torii/graphql/src/object/erc/erc_transfer.rs (4)

82-83: Adding contract_type and transaction_hash to the SELECT statement

Ohayo, sensei! Including c.contract_type and et.transaction_hash in the SELECT statement is appropriate and ensures that all necessary data is retrieved for processing ERC transfers.


107-108: Simplify contract type matching with case-insensitive comparison

Converting row.contract_type to lowercase before matching simplifies the logic and handles different casing consistently.


123-125: Include executedAt and transactionHash in transfer objects

Ohayo, sensei! Adding executedAt and transactionHash to the transfer objects enhances the data returned to clients, improving transparency and traceability of transactions.

Also applies to: 146-148


184-184: Extend TransferQueryResultRaw struct with transaction_hash

Ohayo, sensei! Adding transaction_hash to the TransferQueryResultRaw struct ensures that all relevant transaction data is captured and available for processing.

@@ -0,0 +1 @@
ALTER TABLE erc_transfers ADD COLUMN transaction_hash TEXT NOT NULL;
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Ohayo, sensei! Consider handling existing data when adding the new NOT NULL column.

The addition of the transaction_hash column aligns well with the PR objectives. However, adding a NOT NULL column to an existing table without a DEFAULT value might cause issues if there are existing rows in the erc_transfers table.

To address this, consider the following options:

  1. If the table is empty or you're certain all existing data can be safely discarded:

    TRUNCATE TABLE erc_transfers;
    ALTER TABLE erc_transfers ADD COLUMN transaction_hash TEXT NOT NULL;
  2. If existing data needs to be preserved, use a two-step migration:

    -- Step 1: Add the column as nullable
    ALTER TABLE erc_transfers ADD COLUMN transaction_hash TEXT;
    
    -- Step 2 (in a separate migration after data population):
    ALTER TABLE erc_transfers ALTER COLUMN transaction_hash SET NOT NULL;
  3. If a default value is appropriate:

    ALTER TABLE erc_transfers ADD COLUMN transaction_hash TEXT NOT NULL DEFAULT 'placeholder_hash';

Choose the option that best fits your data requirements and existing table state, sensei.

Would you like assistance in implementing one of these solutions or in creating a data migration script?

Comment on lines +908 to +910
pub(crate) fn get_transaction_hash_from_event_id(event_id: &str) -> String {
event_id.split(':').nth(1).unwrap().to_string()
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Ohayo, sensei! Consider adding error handling to get_transaction_hash_from_event_id.

The function assumes the event_id format is always correct. To improve robustness, consider:

  1. Adding error handling for cases where the split doesn't produce enough parts.
  2. Validating the extracted transaction hash (e.g., checking if it's a valid hex string).

Here's a potential implementation:

pub(crate) fn get_transaction_hash_from_event_id(event_id: &str) -> Result<String, &'static str> {
    event_id.split(':').nth(1).ok_or("Invalid event_id format").map(|s| s.to_string())
}

This change would make the function more resilient to incorrect inputs.

Comment on lines 129 to 131
// contract_address:token_id
let token_id = row.token_id.split(':').collect::<Vec<&str>>();
assert!(token_id.len() == 2);
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Avoid using assert! for input validation

Using assert! for input validation can cause the application to panic if token_id does not split into two parts. Consider handling this scenario gracefully to prevent unexpected crashes.

Here's a suggested change:

 let token_id = row.token_id.split(':').collect::<Vec<&str>>();
- assert!(token_id.len() == 2);
+ if token_id.len() != 2 {
+     warn!("Invalid token_id format: {}", row.token_id);
+     continue;
+ }
📝 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
// contract_address:token_id
let token_id = row.token_id.split(':').collect::<Vec<&str>>();
assert!(token_id.len() == 2);
// contract_address:token_id
let token_id = row.token_id.split(':').collect::<Vec<&str>>();
if token_id.len() != 2 {
warn!("Invalid token_id format: {}", row.token_id);
continue;
}

Copy link

@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: 0

🧹 Outside diff range and nitpick comments (3)
crates/torii/core/src/sql/erc.rs (1)

Line range hint 314-338: Ohayo once more, sensei! LGTM with a small suggestion.

The changes to store_erc_transfer_event are well-implemented, adding the transaction_hash to the method signature, SQL query, and query parameters. This aligns perfectly with the PR objective and maintains the existing logic.

A small suggestion for consistency:

Consider changing line 338 from:

Argument::String(transaction_hash.to_string()),

to:

Argument::String(transaction_hash.to_owned()),

This change would be more idiomatic and consistent with how other string arguments are handled in this method (e.g., token_id.to_string()). Both achieve the same result, but to_owned() is more commonly used when converting &str to String.

crates/torii/core/src/engine.rs (2)

686-687: Ohayo again, sensei! Good consistency in documentation.

These comments mirror the ones added earlier, maintaining consistency in explaining the event_id format. However, if this information is repeated often, consider centralizing it in a documentation comment or constant to avoid duplication.


906-910: Ohayo, sensei! Nice utility function, but let's make it more robust.

The new get_transaction_hash_from_event_id function is a useful addition. However, it assumes the event_id format is always correct. Consider adding error handling for cases where the split doesn't produce enough parts or the transaction hash is invalid.

Here's a suggestion to improve robustness:

pub(crate) fn get_transaction_hash_from_event_id(event_id: &str) -> Result<String, &'static str> {
    event_id.split(':').nth(1).ok_or("Invalid event_id format").map(|s| s.to_string())
}

This change would make the function more resilient to incorrect inputs.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 375f1d6 and 49fd019.

📒 Files selected for processing (10)
  • crates/torii/core/src/engine.rs (3 hunks)
  • crates/torii/core/src/processors/erc20_legacy_transfer.rs (2 hunks)
  • crates/torii/core/src/processors/erc20_transfer.rs (3 hunks)
  • crates/torii/core/src/processors/erc721_legacy_transfer.rs (4 hunks)
  • crates/torii/core/src/processors/erc721_transfer.rs (4 hunks)
  • crates/torii/core/src/sql/erc.rs (7 hunks)
  • crates/torii/graphql/src/mapping.rs (1 hunks)
  • crates/torii/graphql/src/object/erc/erc_balance.rs (2 hunks)
  • crates/torii/graphql/src/object/erc/erc_transfer.rs (3 hunks)
  • crates/torii/migrations/20241011103804_add_transaction_hash_in_erc_transfers_table.sql (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (8)
  • crates/torii/core/src/processors/erc20_legacy_transfer.rs
  • crates/torii/core/src/processors/erc20_transfer.rs
  • crates/torii/core/src/processors/erc721_legacy_transfer.rs
  • crates/torii/core/src/processors/erc721_transfer.rs
  • crates/torii/graphql/src/mapping.rs
  • crates/torii/graphql/src/object/erc/erc_balance.rs
  • crates/torii/graphql/src/object/erc/erc_transfer.rs
  • crates/torii/migrations/20241011103804_add_transaction_hash_in_erc_transfers_table.sql
🧰 Additional context used
🔇 Additional comments (4)
crates/torii/core/src/sql/erc.rs (2)

28-28: Ohayo, sensei! LGTM: Transaction hash parameter added correctly.

The addition of the transaction_hash parameter to the handle_erc20_transfer method and its usage in the store_erc_transfer_event call align perfectly with the PR objective. The changes are minimal and focused, maintaining the existing logic while enhancing the data captured for ERC20 transfers.

Also applies to: 47-47


84-84: Ohayo again, sensei! LGTM: Consistent changes for ERC721 transfers.

The modifications to handle_erc721_transfer mirror those made to handle_erc20_transfer, demonstrating excellent consistency. The transaction_hash parameter is added to the method signature and correctly passed to store_erc_transfer_event, aligning perfectly with the PR objective and maintaining the existing logic.

Also applies to: 102-102

crates/torii/core/src/engine.rs (2)

613-614: Ohayo, sensei! Nice addition of clarifying comments.

These comments provide valuable context about the expected format of event_id for erc* processors. This improves code readability and maintainability.


Line range hint 1-910: Ohayo, sensei! Overall, these changes enhance the codebase.

The additions to this file improve documentation and add useful functionality:

  1. The new comments clarify the expected event_id format, enhancing code readability.
  2. The get_transaction_hash_from_event_id function provides a centralized way to extract transaction hashes from event IDs.

These changes align well with the PR objective of adding transaction hash to the erc_transfers table. They lay the groundwork for consistent handling of transaction hashes across the codebase.

To further improve:

  1. Consider centralizing the event_id format documentation if it's used in multiple places.
  2. Ensure that the new get_transaction_hash_from_event_id function is used consistently wherever transaction hashes are extracted from event IDs.

Great work on enhancing the codebase's clarity and functionality!

Copy link

@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: 0

🧹 Outside diff range and nitpick comments (2)
crates/torii/graphql/src/object/erc/erc_transfer.rs (2)

125-125: Ohayo, sensei! LGTM with a small suggestion.

The addition of the transactionHash field to the ERC20 transfer object is spot-on and aligns perfectly with our PR objective. Great job on maintaining consistency with GraphQL naming conventions by using camelCase!

A small suggestion to optimize memory usage:

Consider removing the .clone() call on row.transaction_hash. Since this is the last use of row, you can use row.transaction_hash directly without cloning. Here's the suggested change:

- (Name::new("transactionHash"), Value::String(row.transaction_hash.clone())),
+ (Name::new("transactionHash"), Value::String(row.transaction_hash)),

This minor optimization can help reduce unnecessary memory allocations.


148-148: Ohayo again, sensei! LGTM with the same suggestion as before.

Excellent work on adding the transactionHash field to the ERC721 transfer object as well. This maintains consistency across different token standards and fulfills our PR objective.

As with the ERC20 case, we can make a small optimization:

Consider removing the .clone() call on row.transaction_hash. Since this is the last use of row, you can use row.transaction_hash directly without cloning. Here's the suggested change:

- (Name::new("transactionHash"), Value::String(row.transaction_hash.clone())),
+ (Name::new("transactionHash"), Value::String(row.transaction_hash)),

This minor change can help reduce unnecessary memory allocations.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 49fd019 and 1ee2bb6.

📒 Files selected for processing (9)
  • crates/torii/core/src/engine.rs (3 hunks)
  • crates/torii/core/src/processors/erc20_legacy_transfer.rs (2 hunks)
  • crates/torii/core/src/processors/erc20_transfer.rs (3 hunks)
  • crates/torii/core/src/processors/erc721_legacy_transfer.rs (4 hunks)
  • crates/torii/core/src/processors/erc721_transfer.rs (4 hunks)
  • crates/torii/core/src/sql/erc.rs (7 hunks)
  • crates/torii/graphql/src/mapping.rs (1 hunks)
  • crates/torii/graphql/src/object/erc/erc_transfer.rs (4 hunks)
  • crates/torii/migrations/20241011103804_add_transaction_hash_in_erc_transfers_table.sql (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (7)
  • crates/torii/core/src/engine.rs
  • crates/torii/core/src/processors/erc20_legacy_transfer.rs
  • crates/torii/core/src/processors/erc20_transfer.rs
  • crates/torii/core/src/processors/erc721_legacy_transfer.rs
  • crates/torii/core/src/processors/erc721_transfer.rs
  • crates/torii/core/src/sql/erc.rs
  • crates/torii/migrations/20241011103804_add_transaction_hash_in_erc_transfers_table.sql
🧰 Additional context used
🔇 Additional comments (5)
crates/torii/graphql/src/object/erc/erc_transfer.rs (2)

82-83: Ohayo, sensei! LGTM: Transaction hash added to the query.

The addition of et.transaction_hash to the SELECT statement aligns perfectly with the PR objective of enhancing the erc_transfers table with transaction hash information. This change ensures that we retrieve the transaction hash along with other transfer details, providing a more comprehensive dataset for our GraphQL resolvers.


184-184: Ohayo once more, sensei! LGTM: TransferQueryResultRaw struct updated.

The addition of the transaction_hash: String field to the TransferQueryResultRaw struct is spot-on. This change ensures that we can properly deserialize the transaction hash from our SQL query results, which is crucial for our PR objective. The field is correctly set as public and uses the appropriate String type, maintaining consistency with other fields in the struct.

crates/torii/graphql/src/mapping.rs (3)

165-169: Ohayo, sensei! Confirm non-null constraints for ERC_TOKEN_TYPE_MAPPING fields.

The fields name, symbol, tokenId, decimals, and contractAddress have been updated to be non-nullable. Please ensure:

  • All records in the erc_token table have these fields populated.
  • Any data ingestion processes provide values for these fields.
  • Client applications are aware of these fields being non-nullable to prevent any unexpected behavior.

To check for null values in these fields, execute:

#!/bin/bash
# Description: Verify no null values exist in the key fields of the 'erc_token' table.

psql $DATABASE_URL -c "
SELECT COUNT(*) AS null_count FROM erc_token
WHERE name IS NULL OR symbol IS NULL OR token_id IS NULL
OR decimals IS NULL OR contract_address IS NULL;
"

The count should be 0, confirming all fields are properly populated.


155-161: Ohayo, sensei! Ensure data integrity for non-nullable fields and the new transactionHash.

The fields from, to, amount, type, executedAt, tokenMetadata have been updated to non-nullable types, and a new non-nullable field transactionHash has been added to ERC_TRANSFER_TYPE_MAPPING. It's important to:

  1. Verify that all existing and incoming data for these fields are non-null.
  2. Confirm that the addition of transactionHash is correctly handled in all parts of the application, including data ingestion and queries.

To verify there are no null values and that transactionHash is properly populated, run:

Expect null_count to be 0 to ensure data integrity.


149-151: Ohayo, sensei! Verify non-nullable fields in ERC_BALANCE_TYPE_MAPPING.

The fields balance, type, and tokenMetadata have been changed to non-nullable types using TypeRef::named_nn. This means these fields must always have values. Please ensure that all data sources and database entries guarantee these fields are always populated to prevent potential null reference exceptions or runtime errors.

To confirm that there are no records with null values for these fields in the existing database, you can run the following script:

The expected result is null_count equals 0, indicating no null values are present.

@lambda-0x
Copy link
Collaborator Author

✓ Commit merged in pull request #2526

@lambda-0x lambda-0x closed this Oct 13, 2024
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