Skip to content

fix: ffi tari address from emoji#7114

Merged
SWvheerden merged 5 commits intotari-project:developmentfrom
SWvheerden:sw_fix_tari_address
May 28, 2025
Merged

fix: ffi tari address from emoji#7114
SWvheerden merged 5 commits intotari-project:developmentfrom
SWvheerden:sw_fix_tari_address

Conversation

@SWvheerden
Copy link
Copy Markdown
Collaborator

@SWvheerden SWvheerden commented May 27, 2025

Description

Fixes the the tari address get address from emoji id

Summary by CodeRabbit

  • Bug Fixes

    • Improved error handling and validation for emoji string address conversion, enhancing stability and error feedback.
  • Tests

    • Added a test to verify emoji string conversion to addresses without errors.
    • Temporarily disabled specific synchronization tests due to incomplete prune mode functionality.
  • Chores

    • Updated test attributes to ignore prune mode-related tests pending feature completion.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented May 27, 2025

Walkthrough

The changes update internal logic for emoji string handling in address conversion. The size validation in the emoji-to-bytes helper is simplified, and error reporting is improved in the FFI conversion function. A new test is added to verify emoji string conversion via FFI. Additionally, three horizon sync tests are marked to be ignored due to incomplete prune mode functionality.

Changes

File(s) Change Summary
.../common_types/src/tari_address/mod.rs Simplified emoji string size validation in the private emoji_to_bytes helper function; updated tests with new emoji strings and error expectations.
.../wallet_ffi/src/lib.rs Refactored FFI emoji-to-address conversion for clearer error handling; removed unused error import; added a new test for emoji string conversion via FFI.
.../core/tests/tests/horizon_sync.rs Added #[ignore = "prune mode not yet working"] attribute to three async horizon sync tests.

Sequence Diagram(s)

sequenceDiagram
    participant C_App as C Application
    participant FFI as emoji_id_to_tari_address (FFI)
    participant Rust as TariAddress

    C_App->>FFI: Pass emoji C string pointer
    FFI->>FFI: Convert C string pointer to Rust str
    FFI->>Rust: TariAddress::from_emoji_string(str)
    alt Success
        Rust-->>FFI: TariAddress instance
        FFI-->>C_App: Return pointer to address
    else Error
        Rust-->>FFI: Error
        FFI->>FFI: Print error (dbg!)
        FFI-->>C_App: Return null pointer, set error code
    end
Loading

Possibly related PRs

  • fix: payment id tari address usage #7002: Modifies internal size validation logic in emoji_to_bytes of TariAddress related to payment ID handling; both PRs touch emoji and size validation logic but differ in focus.

Poem

In fields of code where emojis bloom,
Rabbits hop and bugs make room.
With tests and tweaks, the bytes align,
Addresses parse, the errors shine.
A hop, a fix, a cheerful cheer—
More robust code is growing here! 🐇✨


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1af614a and 011941d.

📒 Files selected for processing (1)
  • base_layer/common_types/src/tari_address/mod.rs (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • base_layer/common_types/src/tari_address/mod.rs
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: test (nextnet, nextnet)
  • GitHub Check: test (testnet, esmeralda)
  • GitHub Check: test (mainnet, stagenet)
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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>, 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 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.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
base_layer/wallet_ffi/src/lib.rs (1)

10928-10942: Strengthen the test by checking pointer validity and cleaning up memory.

The new test_emoji_string leaks both the CString and the heap-allocated TariAddress pointer returned by the FFI call. It also only asserts the error code, not that the returned pointer is non-null. Consider:

  • Asserting result_ptr is not null.
  • Reclaiming and dropping the raw CString via CString::from_raw.
  • Reclaiming and dropping the TariAddress via Box::from_raw.

Example patch:

     let _result = emoji_id_to_tari_address(cstring_ptr, error_ptr);
     assert_eq!(*error_ptr, 0, "No error expected");
+    assert!(!_result.is_null(), "Expected a valid TariAddress pointer");
+
+    // Clean up allocations
+    unsafe {
+        // reclaim and drop the input CString
+        CString::from_raw(cstring_ptr as *mut c_char);
+        // reclaim and drop the returned TariAddress
+        Box::from_raw(_result);
+    }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d292cec and a21b571.

📒 Files selected for processing (3)
  • base_layer/common_types/src/tari_address/dual_address.rs (1 hunks)
  • base_layer/common_types/src/tari_address/mod.rs (0 hunks)
  • base_layer/wallet_ffi/src/lib.rs (2 hunks)
💤 Files with no reviewable changes (1)
  • base_layer/common_types/src/tari_address/mod.rs
🧰 Additional context used
🧬 Code Graph Analysis (1)
base_layer/common_types/src/tari_address/dual_address.rs (2)
base_layer/common_types/src/tari_address/mod.rs (1)
  • from_emoji_string (270-274)
base_layer/common_types/src/tari_address/single_address.rs (1)
  • from_emoji_string (93-96)
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: Cucumber tests / Base Layer
  • GitHub Check: test (mainnet, stagenet)
  • GitHub Check: Cucumber tests / FFI
  • GitHub Check: test (testnet, esmeralda)
  • GitHub Check: test (nextnet, nextnet)
  • GitHub Check: cargo check with stable

@github-actions
Copy link
Copy Markdown

github-actions bot commented May 27, 2025

Test Results (CI)

363 tests   361 ✅  8m 0s ⏱️
 20 suites    0 💤
  1 files      2 ❌

For more details on these failures, see this check.

Results for commit 011941d.

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Copy Markdown

github-actions bot commented May 27, 2025

Test Results (Integration tests)

0 tests   0 ✅  0s ⏱️
0 suites  0 💤
0 files    0 ❌

Results for commit cff9b1c.

♻️ This comment has been updated with latest results.

@SWvheerden SWvheerden force-pushed the sw_fix_tari_address branch from dd46dad to 87a8d43 Compare May 27, 2025 16:00
Copy link
Copy Markdown
Contributor

@hansieodendaal hansieodendaal left a comment

Choose a reason for hiding this comment

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

Just one comment

@SWvheerden SWvheerden merged commit 8c97103 into tari-project:development May 28, 2025
18 of 24 checks passed
@SWvheerden SWvheerden deleted the sw_fix_tari_address branch May 28, 2025 15:38
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