Skip to content

feat(dpp): export more token transition fields#2655

Merged
QuantumExplorer merged 5 commits into
v2.0-devfrom
feat/wasm-dpp-token-transition-fields
Jun 3, 2025
Merged

feat(dpp): export more token transition fields#2655
QuantumExplorer merged 5 commits into
v2.0-devfrom
feat/wasm-dpp-token-transition-fields

Conversation

@pshenmic
Copy link
Copy Markdown
Collaborator

@pshenmic pshenmic commented Jun 3, 2025

Issue being fixed or feature implemented

This PR implements exports more getter functions in the WASM DPP for Token Transitions. This is necessary to be able to read token transition field data from the JS.

What was done?

Added more getters for Token transition fields, specifically:

TokenBurnTransition

  • getPublicNote()
  • getBurnAmount()

TokenClaimTransition

  • getPublicNote()
  • getDistributionType()

TokenConfigUpdateTransition

  • getPublicNote()

TokenDestroyFrozenFundsTransition

  • getPublicNote()

TokenSetPriceForDirectPurchaseTransition

  • getPublicNote()
  • getAmount()

TokenDirectPurchaseTransition

  • getTokenCount()
  • getTotalAgreedPrice()

TokenFreezeTransition

  • getPublicNote()

TokenMintTransition

  • getPublicNote()
  • getIssuedToIdentityId()
  • getAmount()

TokenEmergencyActionTransition

  • getPublicNote()
  • getEmergencyAction()

TokenTransferTransition

  • getPublicNote()
  • getAmount()

TokenUnfreezeTransition:

  • getPublicNote()

How Has This Been Tested?

On the Platform Explorer backend

Breaking Changes

No

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have added "!" to the title and described breaking changes in the corresponding section if my code contains any
  • I have made corresponding changes to the documentation if needed

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

Summary by CodeRabbit

  • New Features
    • Added new JavaScript-accessible methods to various token transition objects, including getters for public notes, amounts, token counts, total agreed prices, distribution types, emergency actions, recipient identities, and pricing.
    • Enhanced the ability to retrieve detailed information about token transitions through the WebAssembly interface.

@pshenmic pshenmic added this to the v2.0.0 milestone Jun 3, 2025
@pshenmic pshenmic requested a review from QuantumExplorer as a code owner June 3, 2025 07:50
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 3, 2025

"""

Walkthrough

This change adds new JavaScript-accessible methods to various WebAssembly wrapper structs for token-related state transitions in the WASM DPP package. The new methods provide direct access to fields such as public_note, amounts, types, and actions, exposing them via wasm-bindgen for use in JavaScript environments.

Changes

File(s) Change Summary
.../token_transition/burn.rs
.../token_transition/claim.rs
.../token_transition/config.rs
.../token_transition/destroy.rs
.../token_transition/direct_purchase.rs
.../token_transition/emergency_action.rs
.../token_transition/freeze.rs
.../token_transition/mint.rs
.../token_transition/set_price_for_direct_purchase.rs
.../token_transition/transfer.rs
.../token_transition/unfreeze.rs
Added new wasm-bindgen JS-accessible methods to WASM wrapper structs for token transitions, exposing fields like public_note, amount, distribution_type, emergency_action, token_count, total_agreed_price, price, and identity IDs.

Sequence Diagram(s)

sequenceDiagram
    participant JS as JavaScript
    participant WASM as WASM Wrapper
    participant Rust as Rust TokenTransition

    JS->>WASM: Call getPublicNote()
    WASM->>Rust: Call public_note()
    Rust-->>WASM: Option<String>
    WASM-->>JS: Option<String>

    JS->>WASM: Call getAmount()/getBurnAmount()/getTokenCount()/getTotalAgreedPrice()
    WASM->>Rust: Call respective getter
    Rust-->>WASM: Value (u64, Credits, etc.)
    WASM-->>JS: Value

    JS->>WASM: Call getDistributionType()/getEmergencyAction()
    WASM->>Rust: Call respective enum getter
    Rust-->>WASM: Enum value (u8)
    WASM-->>JS: u8
Loading

Possibly related PRs

  • feat(sdk): token config update transition #2554: Adds wasm-bindgen JS accessor methods for public_note and other fields on the TokenConfigUpdateTransitionWasm struct, related to token config update transitions but focusing on WASM interface extensions.

Suggested labels

js-sdk

Suggested reviewers

  • QuantumExplorer

Poem

A hop, a leap, a bound in code,
New fields revealed along the road.
From notes to sums and actions bright,
Now JavaScript can see the light!
With every getter, bunnies cheer,
For clearer tokens, far and near.
🐇✨
"""


📜 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 e9db452 and 6b6a4db.

📒 Files selected for processing (11)
  • packages/wasm-dpp/src/document/state_transition/batch_transition/token_transition/burn.rs (2 hunks)
  • packages/wasm-dpp/src/document/state_transition/batch_transition/token_transition/claim.rs (2 hunks)
  • packages/wasm-dpp/src/document/state_transition/batch_transition/token_transition/config.rs (2 hunks)
  • packages/wasm-dpp/src/document/state_transition/batch_transition/token_transition/destroy.rs (1 hunks)
  • packages/wasm-dpp/src/document/state_transition/batch_transition/token_transition/direct_purchase.rs (2 hunks)
  • packages/wasm-dpp/src/document/state_transition/batch_transition/token_transition/emergency_action.rs (2 hunks)
  • packages/wasm-dpp/src/document/state_transition/batch_transition/token_transition/freeze.rs (1 hunks)
  • packages/wasm-dpp/src/document/state_transition/batch_transition/token_transition/mint.rs (1 hunks)
  • packages/wasm-dpp/src/document/state_transition/batch_transition/token_transition/set_price_for_direct_purchase.rs (2 hunks)
  • packages/wasm-dpp/src/document/state_transition/batch_transition/token_transition/transfer.rs (1 hunks)
  • packages/wasm-dpp/src/document/state_transition/batch_transition/token_transition/unfreeze.rs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (11)
  • packages/wasm-dpp/src/document/state_transition/batch_transition/token_transition/freeze.rs
  • packages/wasm-dpp/src/document/state_transition/batch_transition/token_transition/destroy.rs
  • packages/wasm-dpp/src/document/state_transition/batch_transition/token_transition/unfreeze.rs
  • packages/wasm-dpp/src/document/state_transition/batch_transition/token_transition/config.rs
  • packages/wasm-dpp/src/document/state_transition/batch_transition/token_transition/set_price_for_direct_purchase.rs
  • packages/wasm-dpp/src/document/state_transition/batch_transition/token_transition/emergency_action.rs
  • packages/wasm-dpp/src/document/state_transition/batch_transition/token_transition/claim.rs
  • packages/wasm-dpp/src/document/state_transition/batch_transition/token_transition/transfer.rs
  • packages/wasm-dpp/src/document/state_transition/batch_transition/token_transition/mint.rs
  • packages/wasm-dpp/src/document/state_transition/batch_transition/token_transition/direct_purchase.rs
  • packages/wasm-dpp/src/document/state_transition/batch_transition/token_transition/burn.rs
✨ 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.

@pshenmic pshenmic changed the title feat(wasm-dpp): export more token transition fields feat(dpp): export more token transition fields Jun 3, 2025
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: 1

♻️ Duplicate comments (3)
packages/wasm-dpp/src/document/state_transition/batch_transition/token_transition/unfreeze.rs (1)

23-29: Simplify the Option handling for better readability.

The implementation is correct, but the match statement can be simplified using Option::cloned() since String implements Clone.

 #[wasm_bindgen(js_name=getPublicNote)]
 pub fn public_note(&self) -> Option<String> {
-    match self.0.public_note() {
-        Some(note) => Some(note.clone()),
-        None => None,
-    }
+    self.0.public_note().cloned()
 }
packages/wasm-dpp/src/document/state_transition/batch_transition/token_transition/destroy.rs (1)

23-29: Simplify the Option handling for better readability.

The implementation is correct, but the match statement can be simplified using Option::cloned() since String implements Clone.

 #[wasm_bindgen(js_name=getPublicNote)]
 pub fn public_note(&self) -> Option<String> {
-    match self.0.public_note() {
-        Some(note) => Some(note.clone()),
-        None => None,
-    }
+    self.0.public_note().cloned()
 }
packages/wasm-dpp/src/document/state_transition/batch_transition/token_transition/config.rs (1)

17-23: Simplify the Option handling for better readability.

The implementation is correct, but the match statement can be simplified using Option::cloned() since String implements Clone.

 #[wasm_bindgen(js_name=getPublicNote)]
 pub fn public_note(&self) -> Option<String> {
-    match self.0.public_note() {
-        Some(note) => Some(note.clone()),
-        None => None,
-    }
+    self.0.public_note().cloned()
 }
🧹 Nitpick comments (2)
packages/wasm-dpp/src/document/state_transition/batch_transition/token_transition/freeze.rs (1)

23-29: Simplify the Option handling for better readability.

The implementation is correct, but the match statement can be simplified using Option::cloned() since String implements Clone.

 #[wasm_bindgen(js_name=getPublicNote)]
 pub fn public_note(&self) -> Option<String> {
-    match self.0.public_note() {
-        Some(note) => Some(note.clone()),
-        None => None,
-    }
+    self.0.public_note().cloned()
 }
packages/wasm-dpp/src/document/state_transition/batch_transition/token_transition/set_price_for_direct_purchase.rs (1)

29-38: Consider documenting the price method behavior.

The price() method intentionally returns None for SetPrices variant, which might be confusing to JavaScript consumers. Consider adding documentation or a comment explaining why only SinglePrice returns a value.

+    /// Returns the price if it's a single price, None for set prices or when price is not set
     #[wasm_bindgen(js_name=getPrice)]
     pub fn price(&self) -> Option<Credits> {
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5008b6d and e9db452.

📒 Files selected for processing (11)
  • packages/wasm-dpp/src/document/state_transition/batch_transition/token_transition/burn.rs (2 hunks)
  • packages/wasm-dpp/src/document/state_transition/batch_transition/token_transition/claim.rs (2 hunks)
  • packages/wasm-dpp/src/document/state_transition/batch_transition/token_transition/config.rs (2 hunks)
  • packages/wasm-dpp/src/document/state_transition/batch_transition/token_transition/destroy.rs (1 hunks)
  • packages/wasm-dpp/src/document/state_transition/batch_transition/token_transition/direct_purchase.rs (2 hunks)
  • packages/wasm-dpp/src/document/state_transition/batch_transition/token_transition/emergency_action.rs (2 hunks)
  • packages/wasm-dpp/src/document/state_transition/batch_transition/token_transition/freeze.rs (1 hunks)
  • packages/wasm-dpp/src/document/state_transition/batch_transition/token_transition/mint.rs (1 hunks)
  • packages/wasm-dpp/src/document/state_transition/batch_transition/token_transition/set_price_for_direct_purchase.rs (2 hunks)
  • packages/wasm-dpp/src/document/state_transition/batch_transition/token_transition/transfer.rs (1 hunks)
  • packages/wasm-dpp/src/document/state_transition/batch_transition/token_transition/unfreeze.rs (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (4)
packages/wasm-dpp/src/document/state_transition/batch_transition/token_transition/set_price_for_direct_purchase.rs (1)
packages/wasm-dpp/src/document/state_transition/batch_transition/token_transition/claim.rs (1)
  • public_note (21-26)
packages/wasm-dpp/src/document/state_transition/batch_transition/token_transition/emergency_action.rs (4)
packages/wasm-dpp/src/document/state_transition/batch_transition/token_transition/claim.rs (1)
  • public_note (21-26)
packages/wasm-dpp/src/document/state_transition/batch_transition/token_transition/set_price_for_direct_purchase.rs (1)
  • public_note (22-27)
packages/rs-dpp/src/tokens/token_event.rs (1)
  • public_note (229-243)
packages/rs-dpp/src/state_transition/state_transitions/document/batch_transition/batched_transition/token_transfer_transition/v0/v0_methods.rs (2)
  • public_note (39-39)
  • public_note (122-124)
packages/wasm-dpp/src/document/state_transition/batch_transition/token_transition/transfer.rs (5)
packages/wasm-dpp/src/document/state_transition/batch_transition/token_transition/burn.rs (2)
  • public_note (18-23)
  • amount (26-28)
packages/wasm-dpp/src/document/state_transition/batch_transition/token_transition/mint.rs (2)
  • public_note (41-46)
  • amount (49-51)
packages/rs-dpp/src/tokens/token_event.rs (1)
  • public_note (229-243)
packages/rs-dpp/src/state_transition/state_transitions/document/batch_transition/batched_transition/token_transfer_transition/v0_methods.rs (2)
  • public_note (61-65)
  • amount (30-34)
packages/rs-drive/src/state_transition_action/batch/batched_transition/token_transition/token_transfer_transition_action/mod.rs (2)
  • public_note (47-51)
  • amount (35-39)
packages/wasm-dpp/src/document/state_transition/batch_transition/token_transition/burn.rs (5)
packages/wasm-dpp/src/document/state_transition/batch_transition/token_transition/claim.rs (1)
  • public_note (21-26)
packages/wasm-dpp/src/document/state_transition/batch_transition/token_transition/mint.rs (2)
  • public_note (41-46)
  • amount (49-51)
packages/wasm-dpp/src/document/state_transition/batch_transition/token_transition/transfer.rs (2)
  • public_note (24-29)
  • amount (32-34)
packages/rs-dpp/src/tokens/token_event.rs (1)
  • public_note (229-243)
packages/rs-dpp/src/state_transition/state_transitions/document/batch_transition/batched_transition/token_transfer_transition/v0/v0_methods.rs (4)
  • public_note (39-39)
  • public_note (122-124)
  • amount (24-24)
  • amount (103-105)
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: Rust packages (wasm-dpp) / Tests
  • GitHub Check: Rust packages (wasm-dpp) / Linting
  • GitHub Check: Build Docker images (Dashmate helper, dashmate-helper, dashmate-helper) / Build Dashmate helper image
  • GitHub Check: Build Docker images (DAPI, dapi, dapi) / Build DAPI image
  • GitHub Check: Build Docker images (Drive, drive, drive-abci) / Build Drive image
  • GitHub Check: Build JS packages / Build JS
🔇 Additional comments (13)
packages/wasm-dpp/src/document/state_transition/batch_transition/token_transition/config.rs (1)

1-1: Good addition of necessary trait import.

The TokenConfigUpdateTransitionV0Methods trait import is correctly added to enable calling public_note() on the inner type.

packages/wasm-dpp/src/document/state_transition/batch_transition/token_transition/set_price_for_direct_purchase.rs (2)

3-5: LGTM: Import additions are appropriate.

The new imports are correctly added and used in the implementation below.


21-27: LGTM: Standard public_note implementation.

The public_note() method follows the established pattern seen across other token transition WASM wrappers, correctly cloning the optional string for JavaScript consumption.

packages/wasm-dpp/src/document/state_transition/batch_transition/token_transition/emergency_action.rs (3)

1-3: LGTM: Import additions are correct.

The new imports are properly added and used in the implementation.


18-24: LGTM: Consistent public_note implementation.

The public_note() method follows the same pattern as other token transition WASM wrappers.


26-32: LGTM: Clear enum mapping for emergency actions.

The mapping of Pause to 0 and Resume to 1 is logical and follows a simple enumeration pattern.

packages/wasm-dpp/src/document/state_transition/batch_transition/token_transition/transfer.rs (2)

23-29: LGTM: Standard public_note implementation.

The public_note() method correctly follows the established pattern for cloning optional strings.


31-34: LGTM: Direct amount accessor.

The amount() method provides straightforward access to the transfer amount.

packages/wasm-dpp/src/document/state_transition/batch_transition/token_transition/claim.rs (2)

20-26: LGTM: Consistent public_note implementation.

The public_note() method follows the established pattern used across other token transition WASM wrappers.


28-34: LGTM: Clear distribution type mapping.

The mapping of PreProgrammed to 0 and Perpetual to 1 provides a simple enumeration for JavaScript consumers.

packages/wasm-dpp/src/document/state_transition/batch_transition/token_transition/direct_purchase.rs (1)

1-6: LGTM! Well-implemented WASM bindings.

The implementation correctly exposes token direct purchase fields to JavaScript:

  • Proper delegation to underlying Rust methods (token_count() and total_agreed_price())
  • Appropriate return types (TokenAmount and Credits)
  • Consistent naming convention with camelCase for JavaScript methods
  • Follows established WASM binding patterns

Also applies to: 17-29

packages/wasm-dpp/src/document/state_transition/batch_transition/token_transition/burn.rs (1)

1-1: LGTM! Consistent implementation with proper Option handling.

The WASM bindings correctly expose burn transition fields:

  • public_note() implementation matches the established pattern from other token transitions (as seen in claim.rs, mint.rs, transfer.rs)
  • Proper Option<String> handling with cloning for JavaScript interop
  • amount() method correctly delegates to burn_amount() from the underlying implementation
  • JavaScript naming conventions properly applied

Also applies to: 15-29

packages/wasm-dpp/src/document/state_transition/batch_transition/token_transition/mint.rs (1)

32-51: LGTM! Comprehensive and well-structured WASM interface.

The three new getter methods properly expose mint transition fields to JavaScript:

  • issued_to_identity_id() correctly handles Option<IdentifierWrapper> conversion
  • public_note() follows the established cloning pattern consistent with other token transitions
  • amount() provides straightforward delegation to the underlying implementation
  • All methods maintain proper type safety for Rust-to-JavaScript interop

@QuantumExplorer QuantumExplorer merged commit a714980 into v2.0-dev Jun 3, 2025
40 checks passed
@QuantumExplorer QuantumExplorer deleted the feat/wasm-dpp-token-transition-fields branch June 3, 2025 16:52
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