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

Contract schema #382

Merged
merged 14 commits into from
Mar 28, 2024
Merged

Contract schema #382

merged 14 commits into from
Mar 28, 2024

Conversation

kpob
Copy link
Contributor

@kpob kpob commented Mar 19, 2024

The next pull request will add:

  • errors description
  • odra-schema create documentation
  • update changelog.md

Summary by CodeRabbit

  • New Features
    • Introduced a function for retrieving contract schemas across various modules.
    • Added version information to token contracts for enhanced clarity.
    • Expanded error handling capabilities with new error enums and attributes in multiple modules.
    • Enhanced event handling with new attributes and metadata for better event tracking and management.
  • Refactor
    • Simplified the initialization process in core structures for better usability.
    • Streamlined the schema file writing process with new functions and refactored logic.
    • Renamed and modified various modules and functions for improved clarity and consistency.
  • Documentation
    • Updated and clarified documentation comments across several modules to provide better guidance and understanding of functionalities.
  • Bug Fixes
    • Addressed various internal enhancements to improve stability and performance.
  • Style
    • Standardized code styling across modules for better readability and maintenance.

Copy link
Contributor

coderabbitai bot commented Mar 19, 2024

Walkthrough

This update brings significant refinements across various aspects, focusing on schema generation, event handling, error management, and documentation within a smart contract framework. Key improvements include method renaming for clarity, simplification of initialization processes, introduction of new functions for schema retrieval, and adjustments in module and event declarations to streamline error handling and event generation.

Changes

Files Change Summary
core/src/args.rs Renamed cl_type() to ty() for EntrypointArgument trait
core/src/contract_def.rs Renamed fields for Entrypoint, Argument, and Event structs
examples/src/features/collecting_events.rs Modified event declarations and added metadata using odra::event
odra-macros/src/ast/entrypoints_item.rs, odra-macros/src/ast/schema/custom_item.rs Renamed fields for clarity and consistency
odra-macros/src/ast/schema/errors.rs Introduced functionality for defining schema errors
odra-macros/src/ir/mod.rs Added methods for schema identifier generation and documentation extraction
odra-macros/src/utils/syn.rs Added functions for attribute handling and field extraction
odra-schema/build.rs, odra-schema/src/lib.rs, odra-schema/src/ty.rs Added Rust version retrieval, schema functionality, and CL type definitions

Possibly related issues

  • Odra Docs in the main repository. #255: The restructuring of documentation chapters, inclusion of code examples, and adoption of mdBook align with the objectives of enhancing documentation and improving synchronization with code changes.

Poem

In the realm of code, where logic plays,
A rabbit hopped, through nights and days.
Refining contracts, with nimble hops,
Where errors fade and complexity drops.
🌟 With every change, a clearer path,
For devs to follow, free from wrath.
🐰 CodeRabbit's joy, in each commit,
Crafting a world, where all can fit.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

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>.
    • Generate unit-tests 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 tests 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link

codecov bot commented Mar 21, 2024

Codecov Report

Attention: Patch coverage is 96.70185% with 50 lines in your changes are missing coverage. Please review.

❗ No coverage uploaded for pull request base (release/0.8.2@ee1ca6e). Click here to learn what that means.

Files Patch % Lines
odra-schema/src/lib.rs 95.20% 14 Missing ⚠️
odra-schema/src/custom_type.rs 0.00% 12 Missing ⚠️
odra-macros/src/utils/syn.rs 90.90% 6 Missing ⚠️
modules/src/erc721/erc721_base.rs 63.63% 4 Missing ⚠️
odra-macros/src/ast/schema/custom_item.rs 97.46% 4 Missing ⚠️
odra-macros/src/ast/schema/errors.rs 96.36% 4 Missing ⚠️
examples/src/features/collecting_events.rs 72.72% 3 Missing ⚠️
odra-macros/src/ir/config.rs 95.38% 3 Missing ⚠️
Additional details and impacted files
@@               Coverage Diff                @@
##             release/0.8.2     #382   +/-   ##
================================================
  Coverage                 ?   86.08%           
================================================
  Files                    ?      136           
  Lines                    ?    15101           
  Branches                 ?        0           
================================================
  Hits                     ?    13000           
  Misses                   ?     2101           
  Partials                 ?        0           

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

Base automatically changed from feature/maybe-arg to release/0.8.2 March 21, 2024 12:25
@kpob kpob marked this pull request as ready for review March 21, 2024 12:47
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.

Review Status

Actionable comments generated: 6

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between ee1ca6e and 1d64b9d.
Files ignored due to path filters (5)
  • Cargo.toml is excluded by: !**/*.toml
  • core/Cargo.toml is excluded by: !**/*.toml
  • odra-schema/Cargo.toml is excluded by: !**/*.toml
  • odra/Cargo.toml is excluded by: !**/*.toml
  • rustfmt.toml is excluded by: !**/*.toml
Files selected for processing (54)
  • core/src/args.rs (5 hunks)
  • core/src/entry_point_callback.rs (1 hunks)
  • examples/bin/build_schema.rs (1 hunks)
  • examples/src/contracts/owned_token.rs (1 hunks)
  • examples/src/contracts/tlw.rs (3 hunks)
  • examples/src/features/collecting_events.rs (1 hunks)
  • examples/src/features/events.rs (1 hunks)
  • examples/src/features/handling_errors.rs (1 hunks)
  • examples/src/features/module_nesting.rs (4 hunks)
  • modules/bin/build_schema.rs (1 hunks)
  • modules/src/access/access_control.rs (2 hunks)
  • modules/src/access/events.rs (5 hunks)
  • modules/src/access/ownable.rs (3 hunks)
  • modules/src/erc1155/erc1155_base.rs (1 hunks)
  • modules/src/erc1155/mod.rs (3 hunks)
  • modules/src/erc1155_receiver.rs (2 hunks)
  • modules/src/erc1155_token.rs (1 hunks)
  • modules/src/erc20.rs (3 hunks)
  • modules/src/erc721/erc721_base.rs (2 hunks)
  • modules/src/erc721/extensions/erc721_metadata.rs (2 hunks)
  • modules/src/erc721/mod.rs (3 hunks)
  • modules/src/erc721_token.rs (1 hunks)
  • modules/src/security/events.rs (1 hunks)
  • modules/src/security/pauseable.rs (1 hunks)
  • modules/src/wrapped_native.rs (2 hunks)
  • odra-build/src/lib.rs (1 hunks)
  • odra-macros/src/ast/contract_ref_item.rs (3 hunks)
  • odra-macros/src/ast/event/mod.rs (1 hunks)
  • odra-macros/src/ast/host_ref_item.rs (4 hunks)
  • odra-macros/src/ast/mod.rs (2 hunks)
  • odra-macros/src/ast/module_impl_item.rs (2 hunks)
  • odra-macros/src/ast/module_struct_item.rs (2 hunks)
  • odra-macros/src/ast/schema/contract_schema.rs (1 hunks)
  • odra-macros/src/ast/schema/custom_item.rs (1 hunks)
  • odra-macros/src/ast/schema/custom_types.rs (1 hunks)
  • odra-macros/src/ast/schema/entry_points.rs (1 hunks)
  • odra-macros/src/ast/schema/errors.rs (1 hunks)
  • odra-macros/src/ast/schema/events.rs (1 hunks)
  • odra-macros/src/ast/schema/mod.rs (1 hunks)
  • odra-macros/src/ir/config.rs (3 hunks)
  • odra-macros/src/ir/delegate.rs (1 hunks)
  • odra-macros/src/ir/mod.rs (3 hunks)
  • odra-macros/src/lib.rs (3 hunks)
  • odra-macros/src/test_utils.rs (3 hunks)
  • odra-macros/src/utils/syn.rs (3 hunks)
  • odra-schema/build.rs (1 hunks)
  • odra-schema/src/custom_type.rs (1 hunks)
  • odra-schema/src/lib.rs (1 hunks)
  • odra-schema/src/ty.rs (1 hunks)
  • odra/src/lib.rs (1 hunks)
  • templates/blank/bin/build_schema.rs (1 hunks)
  • templates/full/bin/build_schema.rs (1 hunks)
  • templates/workspace/flapper/bin/build_schema.rs (1 hunks)
  • templates/workspace/flipper/bin/build_schema.rs (1 hunks)
Files skipped from review due to trivial changes (1)
  • odra-macros/src/ast/schema/mod.rs
Additional comments: 120
modules/src/security/events.rs (2)
  • 7-7: The use of the #[odra::event] attribute for the Paused struct is a positive change, aligning with the updated event handling mechanism in the Odra framework. This approach enhances clarity and consistency in event declarations.
  • 14-14: Similarly, applying the #[odra::event] attribute to the Unpaused struct is consistent with the framework's updated event handling strategy. It ensures uniformity across event declarations and improves the developer experience.
odra-schema/build.rs (1)
  • 1-15: The addition of a build script to capture and set the Rust version as an environment variable (RUSTC_VERSION) is a thoughtful enhancement. It can be useful for conditional compilation or logging purposes. Ensure that this environment variable is utilized appropriately in the crate to justify its inclusion.
odra-macros/src/ast/module_struct_item.rs (2)
  • 5-5: The addition of SchemaItem, SchemaEventsItem, and SchemaErrorsItem imports from the schema module is a necessary step to support the new schema-related functionalities introduced in the ModuleStructItem struct. This aligns with the PR's objective to enhance schema generation capabilities.
  • 16-19: Integrating SchemaItem, SchemaEventsItem, and SchemaErrorsItem into the ModuleStructItem struct significantly enhances its schema handling capabilities. This change facilitates more comprehensive schema generation and customization, aligning with the PR's objectives. Ensure that these new items are properly utilized in the schema generation process.
Verification successful

To further verify the utilization of SchemaItem and SchemaEventsItem in the schema generation process, additional information is needed. Specifically, we need to find evidence of their methods or properties being accessed or called within the schema generation context.


The provided context confirms the integration and utilization of SchemaItem, SchemaEventsItem, and SchemaErrorsItem in the schema generation process. The implementations of ToTokens and TryFrom traits for both SchemaItem and SchemaEventsItem indicate their active role in transforming module structure into schema definitions, aligning with the review comment's assertion that these changes enhance schema handling capabilities. This verification supports the approval of the changes mentioned in the review comment.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify the utilization of SchemaItem, SchemaEventsItem, and SchemaErrorsItem in schema generation.
rg 'schema_item|schema_events_item|schema_errors' odra-macros/src

Length of output: 2021



Script:

#!/bin/bash
# Search for evidence of SchemaItem and SchemaEventsItem being actively used in schema generation.
rg 'SchemaItem|SchemaEventsItem' odra-macros/src -A 3

Length of output: 4009

odra-macros/src/ast/mod.rs (2)
  • 21-22: The addition of schema and event modules is a strategic enhancement to the odra-macros crate, expanding its capabilities in handling schema and event-related functionalities. This modular approach improves maintainability and extensibility.
  • 33-34: Exposing SchemaCustomTypeItem, SchemaErrorItem, and OdraEventItem as public entities from the schema and event modules is crucial for enabling external crates to leverage these functionalities. This change supports the PR's goal of enhancing schema generation and event handling capabilities.
odra-build/src/lib.rs (1)
  • 20-26: > 📝 NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [1-1]

The removal of the test_flags_with_env test function from odra-build/src/lib.rs could potentially reduce test coverage, especially for environment flag handling logic. Consider adding alternative tests to cover this functionality or justify the removal if the test is no longer relevant due to changes in the build process.

odra-macros/src/ast/module_impl_item.rs (2)
  • 5-5: The addition of SchemaCustomTypesItem and SchemaEntrypointsItem imports from the schema module supports the new schema-related functionalities introduced in the ModuleImplItem struct. This aligns with the PR's objective to enhance schema generation capabilities.
  • 24-25: Incorporating SchemaEntrypointsItem and SchemaCustomTypesItem into the ModuleImplItem struct enhances its schema handling capabilities, facilitating more detailed and customizable schema generation for module implementations. Ensure these new items are effectively utilized in the schema generation process.
Verification successful

The investigation confirms that SchemaEntrypointsItem and SchemaCustomTypesItem are utilized in the schema generation process. Their definitions, along with implementations of ToTokens and TryFrom<&ModuleImplIR>, indicate they play a significant role in transforming module implementation details into schema components. This aligns with the initial review comment, supporting the conclusion that these items facilitate detailed and customizable schema generation for module implementations.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify the utilization of SchemaEntrypointsItem and SchemaCustomTypesItem in schema generation.
rg 'schema_entrypoints|schema_custom_types' odra-macros/src

Length of output: 803



Script:

#!/bin/bash
# Investigate the usage of SchemaEntrypointsItem and SchemaCustomTypesItem in schema generation.
# Search for functions or logic that utilize these items in the context of schema generation.
rg 'SchemaEntrypointsItem|SchemaCustomTypesItem' odra-macros/src -A 3 -B 3

Length of output: 6660

examples/src/features/events.rs (2)
  • 6-6: The modification of the PartyContract struct to include event specifications using the #[odra::module(events = [PartyStarted])] attribute is a significant improvement. It directly associates events with the contract module, enhancing clarity and making event handling more intuitive.
  • 10-10: Updating the PartyStarted struct with the #[odra::event] attribute aligns with the framework's updated event handling strategy. This change ensures consistency across event declarations and improves the developer experience in defining and handling events.
odra/src/lib.rs (1)
  • 52-53: The conditional re-export of odra_schema as schema for non-WASM targets is a thoughtful addition, enhancing the framework's versatility and usability across different development environments. This change supports the PR's goal of improving the developer experience by making schema-related functionalities more accessible in non-WASM contexts.
modules/src/access/events.rs (5)
  • 1-10: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [7-11]

The update to use #[odra::event] for the OwnershipTransferred event struct is correctly implemented and aligns with the PR's objectives to standardize event handling.

  • 13-19: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [16-20]

The OwnershipTransferStarted event struct correctly uses the #[odra::event] attribute, ensuring consistency in event declaration.

  • 25-31: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [28-34]

The RoleAdminChanged event struct's use of #[odra::event] is correct, facilitating a unified approach to event management.

  • 36-42: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [39-45]

The RoleGranted event struct is properly annotated with #[odra::event], which is in line with the PR's goal of improving event handling.

  • 47-53: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [50-56]

The RoleRevoked event struct's implementation of #[odra::event] is correct, enhancing the consistency of event declarations.

modules/src/erc721/extensions/erc721_metadata.rs (2)
  • 4-4: Including the self error variant in the import statement improves clarity in error handling within the module.
  • 21-21: Adjusting the module attribute to specify errors with #[odra::module(errors = [Error])] is a best practice that enhances error management in the module.
modules/src/security/pauseable.rs (2)
  • 8-8: Explicitly including all error variants in the import statement enhances clarity in error handling.
  • 14-14: Updating the odra::module attribute to specify both events and errors used by the module is a good practice that improves the module's maintainability and clarity.
odra-macros/src/ir/delegate.rs (1)
  • 35-45: Adding a condition to check for empty attributes before adding a delegation comment is a thoughtful improvement that enhances code readability and maintainability by avoiding unnecessary duplication.
templates/blank/bin/build_schema.rs (3)
  • 8-8: The addition of the casper_contract_schema() function aligns with the PR's objectives to enhance schema generation capabilities, facilitating the retrieval of contract schemas.
  • 20-36: Modifications to the main() function, including the structured approach to writing schema files for both contract and module schemas, align with the PR's goal of improving the schema generation process.
  • 45-67: The to_snake_case() helper function is a useful addition for string conversion, enhancing the flexibility and usability of the schema generation process.
templates/full/bin/build_schema.rs (3)
  • 8-8: The addition of the casper_contract_schema() function aligns with the PR's objectives to enhance schema generation capabilities, facilitating the retrieval of contract schemas.
  • 20-36: Modifications to the main() function, including the structured approach to writing schema files for both contract and module schemas, align with the PR's goal of improving the schema generation process.
  • 45-67: The to_snake_case() helper function is a useful addition for string conversion, enhancing the flexibility and usability of the schema generation process.
templates/workspace/flapper/bin/build_schema.rs (3)
  • 8-8: The addition of the casper_contract_schema() function aligns with the PR's objectives to enhance schema generation capabilities, facilitating the retrieval of contract schemas.
  • 20-36: Modifications to the main() function, including the structured approach to writing schema files for both contract and module schemas, align with the PR's goal of improving the schema generation process.
  • 45-67: The to_snake_case() helper function is a useful addition for string conversion, enhancing the flexibility and usability of the schema generation process.
templates/workspace/flipper/bin/build_schema.rs (3)
  • 8-8: The addition of the casper_contract_schema() function aligns with the PR's objectives to enhance schema generation capabilities, facilitating the retrieval of contract schemas.
  • 20-36: Modifications to the main() function, including the structured approach to writing schema files for both contract and module schemas, align with the PR's goal of improving the schema generation process.
  • 45-67: The to_snake_case() helper function is a useful addition for string conversion, enhancing the flexibility and usability of the schema generation process.
examples/bin/build_schema.rs (3)
  • 8-8: The addition of the casper_contract_schema() function declaration is correctly scoped for non-WASM targets, aligning with its intended use case.
  • 20-35: The updates to the main function, including the use of casper_contract_schema() and to_snake_case(), as well as the improved file writing logic, enhance clarity and maintainability. However, consider adding a comment explaining the necessity and safety of using unsafe for calling casper_contract_schema() and module_schema().
  • 45-67: The to_snake_case() function is well-implemented and ensures consistent naming conventions in generated schema files.
modules/bin/build_schema.rs (3)
  • 8-8: The addition of the casper_contract_schema() function declaration is correctly scoped for non-WASM targets, aligning with its intended use case.
  • 20-35: The updates to the main function, including the use of casper_contract_schema() and to_snake_case(), as well as the improved file writing logic, enhance clarity and maintainability. However, consider adding a comment explaining the necessity and safety of using unsafe for calling casper_contract_schema() and module_schema().
  • 45-67: The to_snake_case() function is well-implemented and ensures consistent naming conventions in generated schema files.
examples/src/features/collecting_events.rs (2)
  • 6-12: The transition to using the odra::event attribute for event declarations simplifies event handling and enhances code readability and maintainability.
  • 17-21: The addition of module name and version metadata using the odra::module attribute is a significant improvement for module identification and versioning.
odra-macros/src/ast/event/mod.rs (2)
  • 9-48: The ToTokens implementation for OdraEventItem correctly transforms event structs for schema generation, using appropriate traits and practices for including custom types from event fields.
  • 62-72: The custom_struct function accurately generates representations of custom structs for schema purposes, ensuring correct handling of field names and types.
examples/src/features/handling_errors.rs (1)
  • 6-6: The inclusion of the errors = [Error] parameter in the odra::module attribute significantly improves error handling within the module by making it more explicit and manageable.
core/src/entry_point_callback.rs (1)
  • 90-90: The modification to the new method of the Argument struct simplifies initialization and improves clarity, aligning with best practices for struct initialization in Rust.
modules/src/erc1155_receiver.rs (1)
  • 59-72: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [69-84]

The use of #[odra::event] for event structs simplifies declarations and enhances the consistency of event handling within the framework, aligning with its goals of providing a more intuitive approach to event management.

odra-macros/src/ast/schema/custom_types.rs (1)
  • 13-51: The ToTokens implementation for SchemaCustomTypesItem correctly transforms custom types for schema generation, using a comprehensive approach to include all relevant types from the module's functions.
odra-schema/src/ty.rs (1)
  • 8-170: The implementations of the NamedCLTyped trait for various types are correctly mapping Rust types to their corresponding CL types. This is crucial for schema generation and ensuring that the contract's interface is accurately represented in the blockchain's type system. The code is clean, follows Rust conventions, and doesn't introduce any apparent performance or security issues.
modules/src/erc721/mod.rs (1)
  • 56-66: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [59-87]

The update to use the #[odra::event] attribute for event declarations (Transfer, Approval, and ApprovalForAll) aligns with the new event handling mechanism. This change ensures that events are correctly registered and handled within the Odra framework, improving the developer experience and consistency across different modules.

modules/src/erc1155/mod.rs (1)
  • 72-78: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [60-148]

The transition to using the #[odra::event] attribute for the TransferSingle, TransferBatch, and ApprovalForAll event structs in the ERC1155 module is a positive change. It standardizes event declaration and handling within the Odra framework, ensuring that events are processed efficiently and consistently. This update enhances the framework's capabilities for managing multi-token contracts.

odra-macros/src/ast/schema/contract_schema.rs (1)
  • 4-71: The SchemaItem struct and its implementation of the ToTokens trait for generating contract schema items are well-designed. The code is clear and follows Rust conventions. The use of the quote! macro to generate the schema-related code dynamically is appropriate and leverages Rust's powerful macro system for code generation. This approach facilitates the automatic generation of contract schemas, enhancing the developer experience by reducing manual coding requirements.
examples/src/contracts/owned_token.rs (1)
  • 8-8: The update to the OwnedToken contract, including its renaming to MyTokenContact and the addition of version information (version = "1.0.0"), is correctly implemented using the #[odra::module] attribute. This change not only improves the contract's identification within the framework but also introduces versioning, which is essential for managing contract updates and compatibility.
odra-macros/src/ir/config.rs (1)
  • 22-129: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [25-168]

The introduction of new keywords (name, version, events, errors) and corresponding structures (ModuleName, ModuleVersion, ModuleErrors, ModuleError) for module configuration parsing is a significant enhancement. This update allows for more detailed and structured configuration of modules, including naming, versioning, and specifying custom events and errors. The parsing logic is well-implemented, ensuring that module configurations are correctly interpreted and applied.

odra-schema/src/custom_type.rs (1)
  • 12-181: The implementation of traits for custom types, errors, and events using macros is efficient and reduces boilerplate code. The specific implementations for Maybe, SubModule, Var, Mapping, List, and Sequence are correctly defined, ensuring that these types are properly handled during schema generation. This approach enhances the flexibility and extensibility of the schema generation process, allowing for a wide range of types to be accurately represented in contract schemas.
odra-macros/src/lib.rs (3)
  • 53-58: The updates to the derive_odra_type function, which now generates schema and odra_type separately before combining them, enhance the clarity and maintainability of the code. This approach allows for more granular control over the generated code and facilitates debugging and future enhancements.
  • 68-73: Similar to the derive_odra_type function, the derive_odra_error function's update to generate schema and odra_error separately before combining them improves code maintainability and clarity. This structured approach is beneficial for managing complex code generation scenarios.
  • 134-137: The introduction of the event macro is a significant addition, simplifying the implementation of event-related boilerplate code. This macro enhances the developer experience by reducing the amount of manual coding required for event declarations and schema generation, aligning with the Odra framework's goals of efficiency and developer-friendliness.
odra-macros/src/test_utils.rs (4)
  • 85-87: Adding documentation comments for the get_owner and set_owner functions within the delegate! block improves code readability and understanding. Good practice to include such comments for public-facing API functions.
  • 92-92: The addition of a documentation comment for the name function is a positive change, enhancing the clarity and usability of the code. It's beneficial for developers to understand the purpose and usage of this function quickly.
  • 114-118: The modification of the attr variable to include additional fields like name, version, and errors is a significant enhancement. It enriches the metadata associated with the module, potentially improving the schema generation process and error handling capabilities.
  • 144-146: Including descriptions for enum variants in the custom_enum function is a valuable addition. It not only improves the readability of the code but also aids in generating more informative and user-friendly documentation and error messages.
examples/src/features/module_nesting.rs (4)
  • 14-14: Specifying events with the OperationEnded event in the NestedOdraTypesContract struct is a clear and concise way to declare the events that this contract can emit. This change aligns with best practices for event management in smart contracts.
  • 71-71: Adding PartialEq and Eq traits to the Status enum enables equality comparisons, which can be particularly useful in contract logic, such as conditionals or assertions. This is a good practice for types that may need to be compared.
  • 79-79: Similarly, implementing PartialEq and Eq for the OperationResult struct enhances its usability within the contract by allowing instances of this type to be compared directly. This is a beneficial change for handling operation results more effectively.
  • 91-91: Updating the event declaration for OperationEnded to use the odra::event attribute standardizes event management across the module. This change ensures consistency and leverages the framework's capabilities for event handling.
modules/src/access/access_control.rs (1)
  • 30-30: Including the Error enum in the list of errors for the AccessControl struct is a crucial update. It expands the error handling capabilities of the module, allowing for more descriptive and specific error messages that can aid in debugging and user feedback.
modules/src/erc721/erc721_base.rs (1)
  • 16-16: Adding the Error enum to the list of errors in the Erc721Base struct's odra::module attribute is a significant improvement. It ensures that the module can leverage the full range of defined errors, enhancing the robustness and clarity of error handling within the ERC721 implementation.
core/src/args.rs (5)
  • 85-85: Renaming the method cl_type() to ty() in the EntrypointArgument trait and its implementations simplifies the naming convention and aligns with Rust's preference for concise naming. This change is likely to improve the developer experience by making the trait's purpose more intuitive.
  • 97-97: The update to use the new ty() method in the implementation for Maybe<T> where T: CLTyped + ToBytes is consistent with the renaming in the trait. This ensures that the codebase remains consistent and that the trait's implementations correctly reflect the updated method name.
  • 120-120: Similarly, updating the ty() method in the implementation for types that implement CLTyped + ToBytes is a necessary change following the renaming in the trait. This consistency is crucial for maintaining the integrity of the trait's contract across its implementations.
  • 140-140: Ensuring that the parameter function uses the updated ty() method for generating Casper entrypoint arguments is an important detail. This change ensures that the utility function remains functional and consistent with the trait's new method signature.
  • 149-149: The use of the ty() method in the odra_argument function for generating Odra's entrypoint argument representation is correctly updated. This adaptation is essential for the function to continue working as expected with the updated trait.
modules/src/erc1155/erc1155_base.rs (1)
  • 13-13: Adding the Error event to the list of events in the #[odra::module] attribute for the Erc1155Base struct is a crucial enhancement. It allows the module to communicate error conditions more effectively, improving the contract's usability and debuggability.
odra-macros/src/ast/schema/errors.rs (1)
  • 1-153: The addition of structures and implementations for handling schema errors in odra-macros/src/ast/schema/errors.rs is a significant improvement. It enhances the framework's ability to generate and manage schema errors, contributing to a more robust and developer-friendly environment for smart contract development. The use of traits and implementations to dynamically generate schema errors based on the contract's defined errors is a sophisticated approach that leverages Rust's type system and macro capabilities effectively.
odra-macros/src/ast/schema/events.rs (4)
  • 5-8: The SchemaEventsItem struct is well-defined, encapsulating the necessary data for schema event generation. However, consider adding documentation comments to explain the purpose of each field, especially for public structs or those used in complex processes. This will improve maintainability and understandability of the code.
  • 11-66: The implementation of ToTokens for SchemaEventsItem is comprehensive, effectively generating the necessary tokens for schema events. A few points to consider:
  • Ensure that the usage of #[automatically_derived] and #[cfg(not(target_arch = "wasm32"))] attributes aligns with the project's standards and goals. These attributes are crucial for conditional compilation and indicating derived implementations.
  • The chaining of events and types to collect into a BTreeSet before collecting into a Vec is an interesting approach to ensure uniqueness. Verify that this behavior is intended and document the rationale behind it to avoid confusion.
  • The use of quote::quote! for code generation is appropriate, but ensure that all generated code adheres to the project's coding standards, especially in terms of error handling and type safety.

Overall, the implementation appears solid, but adding comments to explain complex or non-obvious parts of the code would enhance readability and maintainability.

  • 68-78: The TryFrom<&ModuleStructIR> for SchemaEventsItem implementation is straightforward and correctly handles the conversion. It's good practice to ensure that error handling is robust and that any potential failure points are adequately addressed. In this case, the ? operator is used effectively to propagate errors. Adding a brief comment explaining the conversion process and any assumptions made could further improve code clarity.
  • 80-133: The test module provides a basic test case for the custom_types_works function. Consider the following improvements:
  • Expanding the test coverage to include more scenarios, especially edge cases or failure modes, would enhance the robustness of the code.
  • Adding comments to explain the purpose of each test and the expected outcomes can make the tests more understandable and maintainable.

Testing is a critical aspect of ensuring code quality, and thorough test coverage can significantly reduce the risk of bugs and regressions.

odra-schema/src/lib.rs (11)
  • 49-55: The function argument correctly handles the distinction between required and optional arguments by leveraging the is_required method from the EntrypointArgument trait. This is a good practice as it ensures that the schema accurately reflects the argument's optionality.
  • 57-72: The entry_point function effectively captures the necessary information to define an entry point in the contract schema. It properly uses generics to allow for flexible type definitions and includes all relevant fields such as name, description, is_mutable, and arguments. This function is well-structured and follows best practices for schema definition.
  • 74-80: The struct_member function is concise and correctly constructs a StructMember instance. It properly handles the conversion of the type to a NamedCLType, which is essential for the schema generation process. This function is a good example of a utility function that simplifies the creation of schema elements.
  • 82-89: The enum_typed_variant function is well-implemented, providing a straightforward way to define an enum variant with an associated type. It correctly uses the NamedCLTyped trait to obtain the type information, which is crucial for accurate schema generation.
  • 91-98: The enum_variant function simplifies the creation of unit enum variants for the schema. By defaulting the type to NamedCLType::Unit, it ensures that the schema accurately represents unit variants. This function is a useful utility for schema generation.
  • 100-106: The custom_struct function provides a clean and efficient way to define custom struct types for the schema. It correctly aggregates StructMember instances into a CustomType::Struct, which is essential for representing complex data structures in the schema.
  • 108-114: The custom_enum function effectively handles the creation of custom enum types for the schema. By aggregating EnumVariant instances into a CustomType::Enum, it allows for the representation of complex enumerations in the schema. This function is well-designed and follows best practices for schema definition.
  • 116-121: The event function is straightforward and correctly constructs an Event instance. It captures the essential information needed to define an event in the contract schema. This function is a good example of a utility function that simplifies the creation of schema elements.
  • 123-129: The error function is well-implemented, providing a simple way to define custom errors for the schema. It correctly captures the error name, description, and discriminant, which are crucial for accurately representing errors in the schema.
  • 131-183: The schema function is a comprehensive and well-structured function that aggregates all necessary components to define a complete contract schema. It correctly handles entry points, events, custom types, and errors, providing a holistic view of the contract's interface. This function demonstrates a good understanding of schema generation requirements and follows best practices.
  • 186-221: The call_method function is well-designed, providing a clear and concise way to define the call method for the contract. It includes essential arguments such as PACKAGE_HASH_KEY_NAME_ARG, ALLOW_KEY_OVERRIDE_ARG, and IS_UPGRADABLE_ARG, which are crucial for contract deployment and upgradeability. This function is a good example of a utility function that simplifies the creation of schema elements.
odra-macros/src/utils/syn.rs (4)
  • 141-147: The docs_attrs function correctly filters and collects documentation attributes from a given set of attributes. This is essential for extracting documentation comments that can be used in schema generation or other code generation tasks. The implementation is concise and follows best practices for working with attributes in Rust macros.
  • 196-211: The extract_named_field function provides a straightforward way to extract named fields from a struct definition. This is crucial for schema generation and other code generation tasks that require detailed information about struct fields. The function correctly handles the case where a field is unnamed, returning an appropriate error.
  • 213-229: The extract_unit_variants function is well-implemented, providing a clean way to extract unit variants from an enum definition. This is important for schema generation and other code generation tasks that require detailed information about enum variants. The function correctly checks for unit variants and returns an appropriate error if non-unit variants are found.
  • 231-249: The transform_variants function is a flexible utility that allows for the transformation of enum variants using a provided function. This is useful for schema generation and other code generation tasks that require custom processing of enum variants. The implementation is well-designed, correctly handling discriminants and ensuring that variants are transformed as expected.
odra-macros/src/ast/schema/custom_item.rs (4)
  • 11-56: The implementation of ToTokens for SchemaCustomTypeItem is comprehensive and well-structured. It correctly handles both enum and struct types, generating the appropriate schema elements. The use of utility functions for transforming fields and variants into schema elements is a good practice, ensuring that the schema generation process is modular and maintainable.
  • 59-65: The custom_enum function within SchemaCustomTypeItem's implementation uses the transform_variants utility function effectively to generate schema elements for enum variants. This approach is efficient and ensures that the schema accurately represents the enum's structure.
  • 67-76: The custom_struct function within SchemaCustomTypeItem's implementation correctly iterates over struct fields, transforming them into schema elements. This method is clear and concise, ensuring that the schema accurately represents the struct's structure.
  • 79-100: The TryFrom implementation for SchemaCustomTypeItem is well-designed, providing a clear mechanism for converting from TypeIR to SchemaCustomTypeItem. It correctly handles the extraction of named fields and unit variants, which is essential for accurate schema generation. The error handling for unsupported data types (e.g., unions) is appropriate and ensures that only supported types are processed.
odra-macros/src/ast/schema/entry_points.rs (3)
  • 13-54: The implementation of ToTokens for SchemaEntrypointsItem is well-structured and effectively generates schema elements for entry points. It correctly handles function documentation, return types, mutability, and arguments, ensuring that the schema accurately represents the contract's entry points. The use of utility functions for argument transformation is a good practice, enhancing the modularity and maintainability of the schema generation process.
  • 57-65: The args_to_tokens function provides a clean and efficient way to transform function arguments into schema elements. It correctly handles the dereferencing of types and the conversion of argument names, ensuring that the schema accurately represents function arguments.
  • 67-76: The TryFrom implementation for SchemaEntrypointsItem is clear and concise, providing a straightforward mechanism for converting from ModuleImplIR to SchemaEntrypointsItem. It correctly extracts the module identifier and functions, which are essential for accurate schema generation of entry points.
examples/src/contracts/tlw.rs (3)
  • 6-6: The module declaration has been updated to remove the Error type. This change simplifies the contract by removing unused error handling capabilities. However, it's important to ensure that all references to the Error enum within the contract have been appropriately handled or removed to avoid compilation errors.
  • 93-93: The use of odra::event for the Deposit struct aligns with the updated event declaration approach in the Odra framework. This change ensures that events are correctly registered and emitted within the contract, enhancing the contract's event handling capabilities.
  • 102-102: Similar to the Deposit struct, the use of odra::event for the Withdrawal struct is consistent with the updated event declaration approach in the Odra framework. This change simplifies event handling and ensures that events are accurately represented in the contract schema.
modules/src/wrapped_native.rs (1)
  • 98-108: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [101-114]

The use of #[odra::event] for event struct annotations in the events module is a good practice as it ensures consistency and leverages the Odra framework's capabilities for event management. This change aligns with the PR's objective to enhance event handling within the Odra framework.

modules/src/erc20.rs (2)
  • 9-9: Adding the Error enum to the #[odra::module] attribute in the Erc20 struct is a significant improvement. It enhances error handling by making the custom errors defined in the errors module directly usable within the Erc20 module. This change aligns with the PR's objective to improve error handling within the Odra framework.
  • 162-172: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [165-180]

The update to use #[odra::event] for event struct annotations in the events module is consistent with best practices for event declaration within the Odra framework. This change ensures that events are properly managed and emitted, contributing to the overall goal of enhancing event handling in the framework.

modules/src/access/ownable.rs (2)
  • 18-18: The addition of the Error enum to the #[odra::module] attribute for the Ownable struct is a positive change. It enhances the module's error handling capabilities by making the custom errors defined in the errors module directly usable within the Ownable module. This update supports the PR's objective to improve error handling within the Odra framework.
  • 93-93: Similarly, adding the Error enum to the #[odra::module] attribute for the Ownable2Step struct improves error handling by integrating custom errors directly into the module. This change is consistent with the PR's goal of enhancing error management across the framework.
odra-macros/src/ast/contract_ref_item.rs (3)
  • 373-373: The documentation comment for the get_owner function is marked as "A". This seems to be a placeholder or an incomplete comment. It's important for documentation comments to provide clear and useful information about the function's purpose and behavior.

Consider updating the comment to accurately describe what the get_owner function does, including any relevant details about its return value or side effects.

  • 389-389: The documentation comment for the set_owner function is marked as "C". Similar to the previous comment, this appears to be a placeholder or an incomplete comment.

Please provide a more descriptive comment that explains the function's purpose, its parameters, and any effects it has on the contract's state.

  • 406-406: The documentation comment for the name function is marked as "W". This follows the pattern of incomplete or placeholder documentation comments observed in the previous functions.

It would be beneficial to replace this placeholder with a detailed comment that describes the function's functionality, especially what the name function returns and any relevant context.

odra-macros/src/ir/mod.rs (5)
  • 67-73: The contract_schema_mod_ident method generates an identifier for the contract schema module. This method uses the camel_to_snake utility function to ensure the generated identifier follows the snake_case naming convention.

This implementation is clear and follows Rust's naming conventions for identifiers. The use of Ident::new with the module's span is appropriate for maintaining source code location information.

  • 103-109: The errors method retrieves a list of error types defined in the module's configuration. This method correctly handles the case where the configuration item is not a module, returning an empty vector in such cases.

The implementation is straightforward and handles different configuration scenarios appropriately. It ensures that error types can be retrieved for further processing in the macro system.

  • 111-117: The contract_name method retrieves the contract's name from the module's configuration. Similar to the errors method, it handles non-module configurations by returning an empty string.

This method is implemented correctly and provides a clean way to access the contract name for use in schema generation or other macro-related tasks.

  • 119-125: The contract_version method retrieves the contract's version from the module's configuration. It follows the same pattern as the contract_name method, ensuring consistency in handling different configuration types.

The approach taken here is consistent with other configuration retrieval methods, providing a reliable way to access the contract version.

  • 411-427: The docs method extracts documentation strings from function attributes. It processes the attributes to find documentation comments and collects them into a vector of strings.

This method is well-implemented, using a clear and efficient approach to extract documentation strings. It will be useful for generating detailed schema documentation or other documentation-related features in the Odra framework.

modules/src/erc721_token.rs (1)
  • 20-20: The addition of the errors field to the #[odra::module] attribute, incorporating the Error enum for enhanced error handling, is a significant improvement. It aligns with the PR's objectives to refine error management within the Odra framework.
modules/src/erc1155_token.rs (1)
  • 16-16: The addition of the errors field to the #[odra::module] attribute, specifying the Error type for error handling, is a positive change that aligns with the PR objectives of enhancing error handling capabilities within the Odra framework. Ensure that the Error type is properly defined and consistently used throughout the module for comprehensive error handling.

odra-macros/src/ast/host_ref_item.rs Outdated Show resolved Hide resolved
odra-macros/src/ast/host_ref_item.rs Outdated Show resolved Hide resolved
odra-macros/src/ast/host_ref_item.rs Outdated Show resolved Hide resolved
odra-macros/src/ast/host_ref_item.rs Outdated Show resolved Hide resolved
odra-macros/src/ast/host_ref_item.rs Outdated Show resolved Hide resolved
odra-macros/src/ast/host_ref_item.rs Outdated Show resolved Hide resolved
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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 1d64b9d and 76e6ee9.
Files ignored due to path filters (1)
  • odra/Cargo.toml is excluded by: !**/*.toml
Files selected for processing (6)
  • modules/src/access/access_control.rs (4 hunks)
  • modules/src/access/ownable.rs (7 hunks)
  • modules/src/erc20.rs (7 hunks)
  • modules/src/erc721/erc721_base.rs (8 hunks)
  • modules/src/erc721/extensions/erc721_metadata.rs (3 hunks)
  • modules/src/security/pauseable.rs (2 hunks)
Files skipped from review as they are similar to previous changes (6)
  • modules/src/access/access_control.rs
  • modules/src/access/ownable.rs
  • modules/src/erc20.rs
  • modules/src/erc721/erc721_base.rs
  • modules/src/erc721/extensions/erc721_metadata.rs
  • modules/src/security/pauseable.rs

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 76e6ee9 and 5792168.
Files selected for processing (3)
  • odra-macros/src/ast/schema/entry_points.rs (1 hunks)
  • odra-macros/src/test_utils.rs (3 hunks)
  • odra-schema/src/custom_type.rs (1 hunks)
Files skipped from review as they are similar to previous changes (3)
  • odra-macros/src/ast/schema/entry_points.rs
  • odra-macros/src/test_utils.rs
  • odra-schema/src/custom_type.rs

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 5792168 and 21dd163.
Files selected for processing (2)
  • odra-macros/src/ast/contract_ref_item.rs (3 hunks)
  • odra-macros/src/ast/host_ref_item.rs (4 hunks)
Files skipped from review as they are similar to previous changes (2)
  • odra-macros/src/ast/contract_ref_item.rs
  • odra-macros/src/ast/host_ref_item.rs

@kpob kpob requested a review from zie1ony March 25, 2024 08:21
Copy link
Contributor

@zie1ony zie1ony left a comment

Choose a reason for hiding this comment

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

Good code.

examples/bin/build_schema.rs Show resolved Hide resolved
examples/src/contracts/tlw.rs Outdated Show resolved Hide resolved
examples/src/contracts/tlw.rs Show resolved Hide resolved
examples/src/contracts/owned_token.rs Show resolved Hide resolved
odra-build/src/lib.rs Show resolved Hide resolved
odra-macros/src/ast/event/mod.rs Outdated Show resolved Hide resolved
odra-macros/src/test_utils.rs Show resolved Hide resolved
odra-schema/Cargo.toml Show resolved Hide resolved
odra-schema/src/ty.rs Show resolved Hide resolved
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.

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 21dd163 and 0655a07.
Files selected for processing (22)
  • examples/bin/build_schema.rs (1 hunks)
  • examples/src/contracts/tlw.rs (3 hunks)
  • examples/src/features/handling_errors.rs (1 hunks)
  • modules/bin/build_schema.rs (1 hunks)
  • modules/src/access/access_control.rs (4 hunks)
  • modules/src/access/ownable.rs (7 hunks)
  • modules/src/erc1155/erc1155_base.rs (1 hunks)
  • modules/src/erc1155_token.rs (1 hunks)
  • modules/src/erc20.rs (7 hunks)
  • modules/src/erc721/erc721_base.rs (8 hunks)
  • modules/src/erc721/extensions/erc721_metadata.rs (3 hunks)
  • modules/src/erc721_token.rs (1 hunks)
  • modules/src/security/pauseable.rs (2 hunks)
  • odra-macros/src/ast/event/mod.rs (1 hunks)
  • odra-macros/src/ast/schema/errors.rs (1 hunks)
  • odra-macros/src/ir/config.rs (3 hunks)
  • odra-macros/src/ir/mod.rs (3 hunks)
  • odra-macros/src/test_utils.rs (3 hunks)
  • templates/blank/bin/build_schema.rs (1 hunks)
  • templates/full/bin/build_schema.rs (1 hunks)
  • templates/workspace/flapper/bin/build_schema.rs (1 hunks)
  • templates/workspace/flipper/bin/build_schema.rs (1 hunks)
Files skipped from review as they are similar to previous changes (21)
  • examples/src/contracts/tlw.rs
  • examples/src/features/handling_errors.rs
  • modules/bin/build_schema.rs
  • modules/src/access/access_control.rs
  • modules/src/access/ownable.rs
  • modules/src/erc1155/erc1155_base.rs
  • modules/src/erc1155_token.rs
  • modules/src/erc20.rs
  • modules/src/erc721/erc721_base.rs
  • modules/src/erc721/extensions/erc721_metadata.rs
  • modules/src/erc721_token.rs
  • modules/src/security/pauseable.rs
  • odra-macros/src/ast/event/mod.rs
  • odra-macros/src/ast/schema/errors.rs
  • odra-macros/src/ir/config.rs
  • odra-macros/src/ir/mod.rs
  • odra-macros/src/test_utils.rs
  • templates/blank/bin/build_schema.rs
  • templates/full/bin/build_schema.rs
  • templates/workspace/flapper/bin/build_schema.rs
  • templates/workspace/flipper/bin/build_schema.rs
Additional comments: 3
examples/bin/build_schema.rs (3)
  • 8-8: The introduction of casper_contract_schema() aligns with the PR objectives to enhance schema generation. Ensure that the function is thoroughly tested, especially since it's marked as unsafe.
  • 13-34: Refactoring in the main function to use casper_contract_schema() and module_schema() is clear and logical. However, consider handling potential errors from std::env::var("ODRA_MODULE") more gracefully than just panicking. Providing a more informative error message or a fallback mechanism could improve the developer experience.
  • 36-45: The write_schema_file function is well-implemented with proper error handling. However, consider adding logging for successful operations or potential points of failure to aid in debugging and monitoring.

Comment on lines +47 to +69
fn to_snake_case(s: &str) -> String {
let mut result = String::with_capacity(s.len());
let mut chars = s.chars().peekable();
let mut is_first = true;

while let Some(c) = chars.next() {
if c.is_uppercase() {
if !is_first {
if let Some(next) = chars.peek() {
if next.is_lowercase() {
result.push('_');
}
}
}
result.push(c.to_lowercase().next().unwrap());
} else {
result.push(c);
}
is_first = false;
}

result
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The to_snake_case function is correctly implemented for converting strings to snake case. However, consider adding unit tests to cover various edge cases, such as strings with consecutive uppercase letters or numbers.

Would you like me to help with adding unit tests for this function?

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 0655a07 and 4fe0052.
Files selected for processing (1)
  • odra-macros/src/ir/config.rs (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • odra-macros/src/ir/config.rs

odra-schema/src/ty.rs Show resolved Hide resolved
* revert changes in old schema
* Add odra-schema documentation
* Update CHANGELOG.md
* add tests
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.

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 4fe0052 and 743151e.
Files ignored due to path filters (3)
  • Cargo.toml is excluded by !**/*.toml
  • core/Cargo.toml is excluded by !**/*.toml
  • odra-schema/Cargo.toml is excluded by !**/*.toml
Files selected for processing (12)
  • CHANGELOG.md (1 hunks)
  • core/src/args.rs (1 hunks)
  • core/src/contract_def.rs (4 hunks)
  • examples/src/features/collecting_events.rs (2 hunks)
  • odra-macros/src/ast/entrypoints_item.rs (4 hunks)
  • odra-macros/src/ast/schema/custom_item.rs (1 hunks)
  • odra-macros/src/ast/schema/errors.rs (1 hunks)
  • odra-macros/src/ir/mod.rs (3 hunks)
  • odra-macros/src/utils/syn.rs (3 hunks)
  • odra-schema/build.rs (1 hunks)
  • odra-schema/src/lib.rs (1 hunks)
  • odra-schema/src/ty.rs (1 hunks)
Files skipped from review as they are similar to previous changes (8)
  • core/src/args.rs
  • examples/src/features/collecting_events.rs
  • odra-macros/src/ast/schema/custom_item.rs
  • odra-macros/src/ast/schema/errors.rs
  • odra-macros/src/ir/mod.rs
  • odra-schema/build.rs
  • odra-schema/src/lib.rs
  • odra-schema/src/ty.rs
Additional comments (14)
core/src/contract_def.rs (5)
  • 17-17: Renaming ident to name in the Entrypoint struct improves clarity and consistency with common naming conventions.
  • 21-21: Changing is_mut to is_mutable enhances readability by being more descriptive.
  • 23-23: Renaming ret to return_ty in the Entrypoint struct is a good practice for clarity, making the purpose of the field more explicit.
  • 35-35: The renaming of ident to name in the Argument struct aligns with the changes in the Entrypoint struct, maintaining consistency across the codebase.
  • 51-51: Similarly, renaming ident to name in the Event struct is consistent with the changes in other structs, which is beneficial for overall code readability.
odra-macros/src/utils/syn.rs (5)
  • 141-147: The docs_attrs function correctly filters attributes to include only those with the doc identifier, which is essential for extracting documentation comments. Ensure that this function is used wherever documentation comments need to be processed.
  • 149-165: The string_docs function effectively converts documentation attributes into a vector of strings. This is a useful utility for schema generation and documentation extraction. Consider adding error handling for unexpected attribute formats to enhance robustness.
  • 214-229: The extract_named_field function is designed to extract named fields from a struct. It's important to ensure that this function is used in contexts where only named fields are expected, as it will not handle unnamed fields (e.g., in tuple structs).
  • 231-247: The extract_unit_variants function correctly identifies and extracts unit variants from an enum. This utility is particularly useful for schema generation where only unit variants are considered. Ensure that enums processed by this function are expected to have only unit variants to avoid unexpected errors.
  • 249-268: The transform_variants function provides a flexible way to transform enum variants into a token stream, which can be particularly useful in macro expansions. The use of a closure to define the transformation logic provides good flexibility. Ensure that the discriminant handling and increment logic align with the intended use cases.
odra-macros/src/ast/entrypoints_item.rs (2)
  • 85-88: Renaming fields in the Entrypoint struct creation within the struct_entrypoints_expr function aligns with the changes in the core/src/contract_def.rs file. This consistency is crucial for maintaining the integrity of the schema generation process.
  • 126-170: The test cases have been updated to reflect the renamed fields (ident to name, is_mut to is_mutable, and ret to return_ty). This is a good practice to ensure that the changes are correctly applied and functional. It's important to verify that all relevant test cases across the project have been updated accordingly.
CHANGELOG.md (2)
  • 9-20: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [3-17]

The changelog for version 0.8.2 is well-documented, clearly listing new additions and changes. However, it would enhance readability and maintain consistency if each bullet point started with a capital letter. Additionally, ensure the release date is updated from "2024-03-xx" to the actual release date before finalizing the changelog.

## [0.8.2] - 2024-03-xx
### Added
- `Maybe<T>` - A type that represents an entrypoint arg that may or may not be present.
- `EntrypointArgument` - A trait for types that can be used as entrypoint arguments.
- An example of using `Maybe<T>` in `odra-examples` crate.
- `get_opt_named_arg_bytes(&str)` in `ContractEnv`
- `odra::contract_def::Argument` has a new `is_required` field.
- `odra-schema` crate for generating contract schema that aligns with Casper Contract Schema.
- `odra::event` proc macro that combines Casper Event Standard and Casper Contract Schema boilerplate code.
- `odra::module` accepts `error` attribute to generate custom error in the schema.
  
### Changed
- Update modules and examples to reflect the changes.
  • 9-20: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [3-331]

Overall, the changelog is well-structured and follows a consistent format across different versions. It's important to ensure that all future entries maintain this level of clarity and consistency. Additionally, consider adding a brief introduction or summary at the beginning of the changelog to provide context for the changes listed.

core/src/contract_def.rs Show resolved Hide resolved
@kpob kpob merged commit 1609e23 into release/0.8.2 Mar 28, 2024
7 checks passed
@kpob kpob deleted the feature/contract-schema branch March 28, 2024 07:53
@kpob kpob mentioned this pull request Apr 2, 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