feat(dpp): export more token transition fields#2655
Conversation
|
""" WalkthroughThis 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 Changes
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
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (11)
🚧 Files skipped from review as they are similar to previous changes (11)
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
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()sinceStringimplementsClone.#[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()sinceStringimplementsClone.#[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()sinceStringimplementsClone.#[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()sinceStringimplementsClone.#[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 returnsNoneforSetPricesvariant, which might be confusing to JavaScript consumers. Consider adding documentation or a comment explaining why onlySinglePricereturns 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
📒 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
TokenConfigUpdateTransitionV0Methodstrait import is correctly added to enable callingpublic_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
Pauseto 0 andResumeto 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
PreProgrammedto 0 andPerpetualto 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()andtotal_agreed_price())- Appropriate return types (
TokenAmountandCredits)- 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 inclaim.rs,mint.rs,transfer.rs)- Proper
Option<String>handling with cloning for JavaScript interopamount()method correctly delegates toburn_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 handlesOption<IdentifierWrapper>conversionpublic_note()follows the established cloning pattern consistent with other token transitionsamount()provides straightforward delegation to the underlying implementation- All methods maintain proper type safety for Rust-to-JavaScript interop
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
TokenClaimTransition
TokenConfigUpdateTransition
TokenDestroyFrozenFundsTransition
TokenSetPriceForDirectPurchaseTransition
TokenDirectPurchaseTransition
TokenFreezeTransition
TokenMintTransition
TokenEmergencyActionTransition
TokenTransferTransition
TokenUnfreezeTransition:
How Has This Been Tested?
On the Platform Explorer backend
Breaking Changes
No
Checklist:
For repository code-owners and collaborators only
Summary by CodeRabbit