Support Stellar token IDs with 'issuer::code'#993
Conversation
Allow Stellar token IDs to be either a 56-char issuer or an issuer::symbol pair when formatting token IDs. Update mapping to build Stellar asset IDs via AssetId::sub_token_id instead of the previous "{code}-{issuer}" string, and update the USDC constant to include the ::USDC suffix. Remove the now-unused map_token_balances_by_ids helper and add tests for the new Stellar format. Files changed: chain_primitives/src/token_id.rs, gem_stellar/src/provider/balances_mapper.rs, primitives/src/asset_constants.rs.
Changed Files
|
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request refines the handling of Stellar token identifiers by introducing support for a more explicit Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request adds support for Stellar token IDs in the issuer::code format, in addition to the existing issuer-only format. The changes correctly update the token ID formatting logic, the asset constant for Stellar USDC, and the balance mapping to use the new format. The removal of the unused map_token_balances_by_ids function is a good cleanup. I've added one suggestion to improve performance in the balance mapping logic.
| // Token balances | ||
| if let (Some(asset_issuer), Some(asset_code)) = (&balance.asset_issuer, &balance.asset_code) { | ||
| let token_id = format!("{}-{}", asset_code, asset_issuer); | ||
| let token_id = AssetId::sub_token_id(&[asset_issuer.clone(), asset_code.clone()]); |
There was a problem hiding this comment.
For improved performance and conciseness, consider using format! directly. This avoids cloning strings and allocating an intermediate array. While this hardcodes the :: separator, it's more efficient for this two-part token ID construction.
| let token_id = AssetId::sub_token_id(&[asset_issuer.clone(), asset_code.clone()]); | |
| let token_id = format!("{}::{}", asset_issuer, asset_code); |
Tighten Stellar token validation in format_token_id by removing the fallback that accepted bare Stellar account IDs (56 chars starting with 'G'). Now only the issuer::symbol form is considered valid. Updated unit test to reflect that a standalone Stellar public key is no longer accepted.
Uh oh!
There was an error while loading. Please reload this page.