Skip to content

RWA: Val for country data instead assoc type#623

Open
brozorec wants to merge 4 commits intomainfrom
rwa-irs-country-data
Open

RWA: Val for country data instead assoc type#623
brozorec wants to merge 4 commits intomainfrom
rwa-irs-country-data

Conversation

@brozorec
Copy link
Collaborator

@brozorec brozorec commented Mar 18, 2026

PR Checklist

  • Tests
  • Documentation

Summary by CodeRabbit

  • Refactor
    • Updated identity verification storage API to use a flexible value-based representation for country data management, replacing strongly-typed structures.
    • Simplified trait signatures for country data retrieval, addition, modification, and deletion operations.
    • Streamlined identity registry storage client integration by consolidating trait declarations.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 18, 2026

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 136024ec-5afb-49d6-8dd0-b908e11f2585

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Walkthrough

This PR refactors the identity registry storage module to use Soroban SDK's Val type instead of strongly-typed CountryData in public trait signatures, event structures, and client interactions. Three files are updated: trait definitions, event emission implementation, and client usage patterns.

Changes

Cohort / File(s) Summary
Trait and Event Definitions
packages/tokens/src/rwa/identity_verification/identity_registry_storage/mod.rs
Removed CountryData associated type from IdentityRegistryStorage and CountryDataManager traits. Updated all trait method signatures to accept/return Vec<Val> and Val instead of strongly-typed CountryData. Changed event structs (CountryDataAdded, CountryDataRemoved, CountryDataModified) to use Val for country_data field. Added #[contracttrait] decorator and updated imports to include IntoVal and Val.
Event Emission Implementation
packages/tokens/src/rwa/identity_verification/identity_registry_storage/storage.rs
Updated emit_country_data_event call sites to convert CountryData to Val using into_val(e) in methods: add_identity, remove_identity, add_country_data_entries, modify_country_data, and delete_country_data. Added IntoVal import and updated documentation to reflect Val-based event payloads.
Client Usage
packages/tokens/src/rwa/identity_verification/storage.rs
Removed local IdentityRegistryStorage trait declaration that used contractclient. Updated code to import and use IdentityRegistryStorageClient directly instead of the local trait definition, maintaining same client interaction patterns.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • Rwa reorg #620: Shares modifications to identity_registry_storage including emit_country_data_event and storage call sites, directly related at code level.

Suggested reviewers

  • pasevin

Poem

🐰 Hop along the Val's bright way,
Where types once bound now freely play,
CountryData transforms with grace,
Val's flexibility fills the space!
Signatures shine, events take flight,
Our contracts now feel just right!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description only contains an unchecked checklist with no substantive explanation of changes, objectives, or context required by the template. Add a description section explaining what changes were made, why they were made, and any relevant context. Fill in the issue number and complete or remove the checklist items appropriately.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: replacing an associated type with Val for country data representation in the RWA module.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch rwa-irs-country-data
📝 Coding Plan
  • Generate coding plan for human review comments

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

CodeRabbit can use TruffleHog to scan for secrets in your code with verification capabilities.

Add a TruffleHog config file (e.g. trufflehog-config.yml, trufflehog.yml) to your project to customize detectors and scanning behavior. The tool runs only when a config file is present.

@brozorec brozorec requested a review from ozgunozerk March 18, 2026 14:04
@codecov
Copy link

codecov bot commented Mar 18, 2026

Codecov Report

❌ Patch coverage is 88.88889% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 96.37%. Comparing base (20981b1) to head (d7abd30).

Files with missing lines Patch % Lines
..._verification/identity_registry_storage/storage.rs 88.88% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #623   +/-   ##
=======================================
  Coverage   96.37%   96.37%           
=======================================
  Files          58       58           
  Lines        5960     5964    +4     
=======================================
+ Hits         5744     5748    +4     
  Misses        216      216           

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
packages/tokens/src/rwa/identity_verification/identity_registry_storage/mod.rs (1)

507-523: ⚠️ Potential issue | 🟠 Major

These default getters still lock the trait to the reference CountryData storage.

The whole point of the Val refactor is to let implementers use a custom country-data shape, but both default read paths still deserialize through storage::get_country_data[_entries], which is hard-wired to the reference IdentityProfile/CountryData layout. That means a contract with custom Val country data will compile yet return the wrong thing unless it remembers to override both methods.

I’d make these required trait methods, or move the current bodies into explicit “reference implementation” helpers so the abstraction can’t be accidentally violated.

Possible fix
 pub trait CountryDataManager: IdentityRegistryStorage {
@@
-    fn get_country_data_entries(e: &Env, account: Address) -> Vec<Val> {
-        Vec::from_iter(
-            e,
-            get_country_data_entries(e, &account).iter().map(|entry| entry.into_val(e)),
-        )
-    }
+    fn get_country_data_entries(e: &Env, account: Address) -> Vec<Val>;
@@
-    fn get_country_data(e: &Env, account: Address, index: u32) -> Val {
-        storage::get_country_data(e, &account, index).into_val(e)
-    }
+    fn get_country_data(e: &Env, account: Address, index: u32) -> Val;
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@packages/tokens/src/rwa/identity_verification/identity_registry_storage/mod.rs`
around lines 507 - 523, The default getters get_country_data_entries and
get_country_data currently hard-wire deserialization via
storage::get_country_data and storage::get_country_data_entries (tied to the
reference IdentityProfile/CountryData), which breaks custom Val implementations;
change the trait so these methods are required (remove default bodies) or
instead extract the current bodies into explicit helper functions (e.g.,
reference_get_country_data_entries and reference_get_country_data) and keep the
trait methods abstract; update references to get_country_data_entries and
get_country_data to call the new helpers only when the implementer wants the
reference behavior.
packages/tokens/src/rwa/identity_verification/identity_registry_storage/storage.rs (1)

83-109: ⚠️ Potential issue | 🟡 Minor

Update the CountryDataManager example to the new Val signature.

This example still implements add_country_data_entries with Vec<CountryData>, but the trait now takes Vec<Val>. As written, the snippet no longer matches the public API and will fail for anyone copy-pasting it. The example should accept Vec<Val> and convert each entry to CountryData before running the duplicate check and calling the reference helpers.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@packages/tokens/src/rwa/identity_verification/identity_registry_storage/storage.rs`
around lines 83 - 109, The example implements
CountryDataManager::add_country_data_entries with the old Vec<CountryData>
signature; update the function to accept Vec<Val> (matching the trait) and
convert each Val into CountryData before duplicate-checking and forwarding to
the helper. Specifically, change the parameter type to Vec<Val>, map or iterate
over those Vals converting with the appropriate conversion helper (e.g.,
CountryData::try_from_val or Val::try_into::<CountryData>() / from_val pattern
used in this crate), handle conversion failures by returning or panicking with
the crate's error macro (e.g., panic_with_error!(e, Error::InvalidInput)),
perform the existing duplicate country checks on the converted CountryData
items, and pass a reference to the converted Vec<CountryData> into
rwa::identity_verification::identity_registry_storage::add_country_data_entries.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@packages/tokens/src/rwa/identity_verification/identity_registry_storage/mod.rs`:
- Around line 329-331: Update the event docs to correctly reflect the ABI: for
the contract events CountryDataAdded, CountryDataRemoved, and
CountryDataModified, only the account field is emitted as a topic (it is tagged
with #[topic]); the country_data field is emitted in the event data payload (as
a map under the default #[contractevent] data_format = "map"), not as a topic,
so change the documentation at the affected comment blocks to list topics as
["country_removed", account: Address] (or the appropriate event name + account)
and place country_data under the data payload description rather than topics.

---

Outside diff comments:
In
`@packages/tokens/src/rwa/identity_verification/identity_registry_storage/mod.rs`:
- Around line 507-523: The default getters get_country_data_entries and
get_country_data currently hard-wire deserialization via
storage::get_country_data and storage::get_country_data_entries (tied to the
reference IdentityProfile/CountryData), which breaks custom Val implementations;
change the trait so these methods are required (remove default bodies) or
instead extract the current bodies into explicit helper functions (e.g.,
reference_get_country_data_entries and reference_get_country_data) and keep the
trait methods abstract; update references to get_country_data_entries and
get_country_data to call the new helpers only when the implementer wants the
reference behavior.

In
`@packages/tokens/src/rwa/identity_verification/identity_registry_storage/storage.rs`:
- Around line 83-109: The example implements
CountryDataManager::add_country_data_entries with the old Vec<CountryData>
signature; update the function to accept Vec<Val> (matching the trait) and
convert each Val into CountryData before duplicate-checking and forwarding to
the helper. Specifically, change the parameter type to Vec<Val>, map or iterate
over those Vals converting with the appropriate conversion helper (e.g.,
CountryData::try_from_val or Val::try_into::<CountryData>() / from_val pattern
used in this crate), handle conversion failures by returning or panicking with
the crate's error macro (e.g., panic_with_error!(e, Error::InvalidInput)),
perform the existing duplicate country checks on the converted CountryData
items, and pass a reference to the converted Vec<CountryData> into
rwa::identity_verification::identity_registry_storage::add_country_data_entries.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 157dd887-382c-49e9-aa46-561e7da05e91

📥 Commits

Reviewing files that changed from the base of the PR and between 20981b1 and 6cc4e74.

📒 Files selected for processing (3)
  • packages/tokens/src/rwa/identity_verification/identity_registry_storage/mod.rs
  • packages/tokens/src/rwa/identity_verification/identity_registry_storage/storage.rs
  • packages/tokens/src/rwa/identity_verification/storage.rs

Copy link

@pasevin pasevin left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks!

Comment on lines +193 to +195
//! Because the trait accepts `Val` for country data, implementors can define
//! their own privacy-preserving types while keeping the same contract
//! interface. Below are examples of alternative country data types:
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we can expand the examples below. They are defining some struct with #[contracttype], and nothing else is shown on the examples. We should explain/show how this defined struct is getting connected to the trait.

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.

3 participants