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

Handling optional entry point argument #380

Merged
merged 5 commits into from
Mar 21, 2024
Merged

Conversation

kpob
Copy link
Contributor

@kpob kpob commented Mar 11, 2024

Summary by CodeRabbit

  • New Features

    • Introduced new types for handling optional values and entrypoint arguments, enhancing contract development flexibility.
    • Added support for optional named arguments in contracts, allowing for more dynamic contract interactions.
    • Enhanced error handling with the introduction of conditional logic based on argument requirements.
  • Refactor

    • Streamlined the entrypoint argument declarations, improving the developer experience.
    • Refactored argument handling across various components, ensuring consistency and efficiency.
  • Bug Fixes

    • Fixed issues related to argument serialization and deserialization, ensuring robust contract execution.
  • Documentation

    • Updated the changelog to reflect new features and improvements in recent versions.

Copy link
Contributor

coderabbitai bot commented Mar 11, 2024

Walkthrough

This update introduces significant enhancements focused on argument handling in contracts, including the introduction of Maybe<T> for optional values, and EntrypointArgument for streamlined argument processing. Changes span across adding new types and methods, refining trait implementations, and improving serialization/deserialization processes. These modifications aim to simplify and make argument handling more flexible and error-tolerant within the contract development ecosystem.

Changes

Files Change Summary
CHANGELOG.md Documented updates in versions 0.8.0 to 0.8.2, introducing new types and functions.
core/src/args.rs Introduced Maybe<T>, entrypoint argument traits, and serialization/deserialization methods.
core/src/contract_container.rs Simplified entrypoint argument declarations.
core/src/contract_context.rs, odra-vm/src/odra_vm_contract_env.rs,
odra-casper/livenet-env/src/livenet_contract_env.rs,
odra-casper/wasm-env/src/wasm_contract_env.rs
Added get_opt_named_arg_bytes method for optional argument handling.
core/src/contract_def.rs, examples/src/features/collecting_events.rs Added is_required field to Argument and EventField structs.
core/src/contract_env.rs, odra-casper/wasm-env/src/host_functions.rs Enhanced argument handling with EntrypointArgument trait.
core/src/entry_point_callback.rs, odra-macros/src/ast/contract_ref_item.rs,
odra-macros/src/ast/deployer_item.rs, odra-macros/src/ast/external_contract_item.rs,
odra-macros/src/ast/host_ref_item.rs, odra-macros/src/ast/test_parts.rs,
odra-macros/src/ast/wasm_parts.rs
Improved flexibility in argument type definitions and handling.
core/src/lib.rs, odra/src/lib.rs Added args module as a public entity.
examples/src/features/optional_args.rs Demonstrated usage of optional arguments in a contract structure.
odra-macros/src/... (Various files) Refactored to utilize new argument handling traits and methods.
odra-vm/src/vm/odra_vm.rs Adjusted get_named_arg function to return Option<Vec<u8>>.

Poem

In the realm of code where contracts thrive,
A change was made, making flexibility arrive.
🐇 With Maybe<T> and args so sleek,
The rabbit hopped, a solution to seek.
Through bytes and types, it danced with glee,
"For better contracts, follow me!" 🌟

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

Benchmark report

Action Details Gas diff
Wasm Deploy Filename: Benchmark.wasm 🔴 +0.35460597 CSPR (0.48%)
Contract Call Entry point: set_variable 🔴 +0.00000304 CSPR (0.00%)
Contract Call Entry point: set_struct_variable 🔴 +0.00000304 CSPR (0.00%)
Contract Call Entry point: set_mapping 🔴 +0.00000608 CSPR (0.00%)
Contract Call Entry point: get_mapping 🔴 +0.00000304 CSPR (0.00%)
Contract Call Entry point: push_list 🔴 +0.00000304 CSPR (0.00%)
Contract Call Entry point: get_list 🔴 +0.00000304 CSPR (0.00%)
Contract Call Entry point: transfer_back 🔴 +0.00000304 CSPR (0.00%)

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 88f1e89 and 4e5540b.
Files selected for processing (3)
  • CHANGELOG.md (1 hunks)
  • odra-macros/src/utils/expr.rs (2 hunks)
  • odra-macros/src/utils/ty.rs (3 hunks)
Files skipped from review as they are similar to previous changes (3)
  • CHANGELOG.md
  • odra-macros/src/utils/expr.rs
  • odra-macros/src/utils/ty.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 4e5540b and d6c2c59.
Files selected for processing (1)
  • examples/src/features/mod.rs (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • examples/src/features/mod.rs

Copy link

Benchmark report

Action Details Gas diff
Wasm Deploy Filename: Benchmark.wasm 🔴 +0.35460597 CSPR (0.48%)
Contract Call Entry point: set_variable 🔴 +0.00000304 CSPR (0.00%)
Contract Call Entry point: set_struct_variable 🔴 +0.00000304 CSPR (0.00%)
Contract Call Entry point: set_mapping 🔴 +0.00000608 CSPR (0.00%)
Contract Call Entry point: get_mapping 🔴 +0.00000304 CSPR (0.00%)
Contract Call Entry point: push_list 🔴 +0.00000304 CSPR (0.00%)
Contract Call Entry point: get_list 🔴 +0.00000304 CSPR (0.00%)
Contract Call Entry point: transfer_back 🔴 +0.00000304 CSPR (0.00%)

Copy link

codecov bot commented Mar 11, 2024

Codecov Report

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

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

Files Patch % Lines
core/src/args.rs 83.87% 20 Missing ⚠️
Additional details and impacted files
@@               Coverage Diff                @@
##             release/0.8.2     #380   +/-   ##
================================================
  Coverage                 ?   84.98%           
================================================
  Files                    ?      126           
  Lines                    ?    13740           
  Branches                 ?        0           
================================================
  Hits                     ?    11677           
  Misses                   ?     2063           
  Partials                 ?        0           

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

core/src/args.rs Show resolved Hide resolved
odra-casper/wasm-env/src/wasm_contract_env.rs Show resolved Hide resolved
odra-macros/src/ast/wasm_parts.rs Show resolved Hide resolved
@kpob kpob merged commit ee1ca6e into release/0.8.2 Mar 21, 2024
5 of 6 checks passed
@kpob kpob deleted the feature/maybe-arg branch March 21, 2024 12:25
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