Skip to content

convert tuple parameters correctly for dyn-abi #24

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 31, 2025
Merged

Conversation

d4mr
Copy link
Member

@d4mr d4mr commented Jul 31, 2025

Summary by CodeRabbit

  • Bug Fixes
    • Improved validation and error messages when submitting contract call parameters, including better handling of complex parameter types.
  • Refactor
    • Enhanced the reliability and consistency of contract call parameter parsing, ensuring more robust support for nested and tuple types.

Copy link

coderabbitai bot commented Jul 31, 2025

Walkthrough

A new private helper function, json_to_sol, was introduced in the ContractCall implementation to handle recursive conversion of JSON values to Solidity values (DynSolValue) based on ABI parameter definitions. The parameter parsing logic in encode_parameters now delegates to this new function, with error handling updated accordingly.

Changes

Cohort / File(s) Change Summary
ContractCall JSON Parameter Parsing Refactor
server/src/http/dyn_contract.rs
Added the private json_to_sol function for recursive JSON-to-Solidity value conversion; refactored encode_parameters to use this helper and updated error handling.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch pb/tuple-abi-encoding

🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this 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.

CodeRabbit Configuration File (.coderabbit.yaml)

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

Documentation and Community

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

coderabbitai bot added a commit that referenced this pull request Jul 31, 2025
Docstrings generation was requested by @d4mr.

* #24 (comment)

The following files were modified:

* `server/src/http/dyn_contract.rs`
Copy link

coderabbitai bot commented Jul 31, 2025

Note

Generated docstrings for this pull request at #25

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

🧹 Nitpick comments (1)
server/src/http/dyn_contract.rs (1)

217-263: Well-structured recursive parameter conversion with comprehensive validation.

The function correctly handles both simple and complex parameter types with proper error handling. The recursive approach for complex types is appropriate for nested tuple structures.

Consider these minor improvements:

  1. The complex type check assumes all complex types are tuples, but ABI could have other complex types like arrays
  2. Error messages could include parameter index/name for easier debugging

Optional enhancement for better error context:

-        for (json_value, json_abi_param) in json_values.iter().zip(json_abi_params.iter()) {
+        for (i, (json_value, json_abi_param)) in json_values.iter().zip(json_abi_params.iter()).enumerate() {
             if json_abi_param.is_complex_type() {
                 let json_value = json_value
                     .as_array()
-                    .ok_or_else(|| "Expected array for complex type".to_string())?;
+                    .ok_or_else(|| format!("Expected array for complex type at parameter {}", i))?;
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2a74fd2 and e3e0047.

📒 Files selected for processing (1)
  • server/src/http/dyn_contract.rs (3 hunks)
🔇 Additional comments (2)
server/src/http/dyn_contract.rs (2)

2-2: LGTM!

The import addition is necessary for the new json_to_sol function and is correctly placed.


283-285: LGTM! Clean delegation to the new helper function.

The refactoring improves maintainability by centralizing parameter conversion logic while maintaining proper error handling and context.

@d4mr d4mr merged commit f53fbd9 into main Jul 31, 2025
3 checks passed
@d4mr d4mr deleted the pb/tuple-abi-encoding branch July 31, 2025 07:18
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.

1 participant