Skip to content

Conversation

@PastaPastaPasta
Copy link
Member

@PastaPastaPasta PastaPastaPasta commented Jan 6, 2026

Issue being fixed or feature implemented

State transition functions in the WASM SDK compute transaction hashes internally but never expose them to users. This makes it impossible to:

  1. Reference or track transactions after broadcast
  2. Create documents that reference prior transactions (e.g., linking a document to a credit transfer)
  3. Verify transaction status using waitForStateTransitionResult

Additionally, the StateTransitionProofResult contains verified data (like new balances after transfers) that was being discarded instead of returned to users.

What was done?

Added transitionHash (hex-encoded SHA256 transaction ID) to the return value of all 22 state transition functions in the WASM SDK.

Functions Updated:

Identity (5 functions):

  • identityCreate - Refactored to use put_to_platform + wait_for_response to access StateTransition
  • identityTopUp - Refactored to use IdentityTopUpTransition::try_from_identity + broadcast_and_wait
  • identityCreditTransfer - Also extracts senderNewBalance and recipientNewBalance from proof
  • identityCreditWithdrawal - Refactored to use IdentityCreditWithdrawalTransition::try_from_identity
  • identityUpdate - Added transitionHash to result

Tokens (10 functions):

  • Modified format_token_result helper to accept and include transaction_id_hex
  • Updated all callers: tokenMint, tokenBurn, tokenTransfer, tokenFreeze, tokenUnfreeze, tokenDestroyFrozen, tokenSetPriceForDirectPurchase, tokenDirectPurchase, tokenClaim, tokenConfigUpdate

Contracts (2 functions):

  • contractCreate - Refactored to use put_to_platform + wait_for_response pattern
  • contractUpdate - Added transitionHash computation after broadcast

Documents (6 functions):

  • documentCreate - Added transitionHash to all result paths
  • documentReplace - Added transitionHash computation and to all result paths
  • documentDelete - Added transitionHash via additional_fields
  • documentTransfer - Added transitionHash via additional_fields
  • documentPurchase - Added transitionHash to both match arms
  • documentSetPrice - Added transitionHash via additional_fields

Implementation Pattern:

For functions using broadcast_and_wait (borrows &self):

  let proof_result = state_transition
      .broadcast_and_wait::<StateTransitionProofResult>(&sdk, None)
      .await?;

  // Get transaction hash after broadcast (no clone needed)
  let st: StateTransition = state_transition.into();
  let transaction_id_hex = st.transaction_id().map(hex::encode)?;

For functions using broadcast:

  state_transition.broadcast(&sdk, None).await?;
  let transaction_id_hex = state_transition.transaction_id().map(hex::encode)?;

Example Return Value (identityCreditTransfer):

  {
    status: "success",
    senderId: "base58...",
    recipientId: "base58...",
    amount: 100000000,
    transitionHash: "abc123...",      // NEW
    senderNewBalance: 900000000,       // NEW - from proof
    recipientNewBalance: 1100000000    // NEW - from proof
  }

How Has This Been Tested?

  • Verified compilation with cargo check -p wasm-sdk
  • Code follows existing patterns used throughout the WASM SDK
  • Pattern validated against SDK internals (e.g., withdraw_from_identity.rs, top_up_identity.rs)

Breaking Changes

None. All changes are additive - existing return fields remain unchanged, new fields are added.

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

Release Notes

  • New Features
    • Contract operations now include transitionHash in results
    • Document operations now include transitionHash for creation, deletion, replacement, transfer, purchase, and pricing updates
    • Identity operations now include transitionHash for creation, top-up, transfer, withdrawal, and updates
    • Token operations now include transitionHash for mint, burn, transfer, freeze, unfreeze, and related actions

✏️ Tip: You can customize this high-level summary in your review settings.

Add hex-encoded transaction ID (transitionHash) to the return value of
all state transition functions in the WASM SDK. This allows users to
reference and track transactions after broadcast.

Functions updated:
- Identity: identityCreate, identityTopUp, identityCreditTransfer,
  identityCreditWithdrawal, identityUpdate
- Tokens: all 10 token functions via format_token_result helper
- Contracts: contractCreate, contractUpdate
- Documents: documentCreate, documentReplace, documentDelete,
  documentTransfer, documentPurchase, documentSetPrice

Also extracts proof data where available:
- identityCreditTransfer: senderNewBalance, recipientNewBalance

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@PastaPastaPasta PastaPastaPasta added this to the v3.0.0 milestone Jan 6, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 6, 2026

📝 Walkthrough

Walkthrough

Four state transition modules (contracts, documents, identity, tokens) were modified to compute and expose transaction hashes within result payloads. The new flow derives the transaction hash from state transitions after broadcasting and includes it as transitionHash in JavaScript results across all affected operations. One helper function signature in the tokens module was updated to accept a transaction hash parameter.

Changes

Cohort / File(s) Summary
Contract State Transitions
packages/wasm-sdk/src/state_transitions/contracts/mod.rs
Modified creation and update flows to compute transaction hash from state transitions; added transitionHash to response payloads alongside existing fields; introduced two-step flow using put_to_platform followed by broadcast-and-wait.
Document State Transitions
packages/wasm-sdk/src/state_transitions/documents/mod.rs
Extended six document operation flows (create, replace, delete, transfer, purchase, price set) to derive and expose transitionHash in results; hash extracted by consuming state transition objects in both success and fallback scenarios.
Identity State Transitions
packages/wasm-sdk/src/state_transitions/identity/mod.rs
Overhauled five identity operation flows (creation, top-up, credit transfer, withdrawal, update) to construct specific transition types, compute transaction hash, and expose transitionHash in results; added balance/state field exposure alongside hashes where applicable.
Token State Transitions
packages/wasm-sdk/src/state_transitions/tokens/mod.rs
Refactored format_token_result helper to accept transaction_id_hex parameter; updated all call sites to compute and pass transaction hash from state transitions; ensures transitionHash appears in all token operation result outputs (mint, burn, transfer, freeze, unfreeze, destroy, purchase, claim, configure).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 With hash and proof, our transitions shine,
Each operation now draws the line,
From contract to token, identity's way,
The transaction trail lights the day!
In bytes of hex, the story's told,
A ledger of actions, cryptographically bold. 🥕

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat(wasm-sdk): add transitionHash to all state transition functions' clearly and directly summarizes the main change across all modified files (contracts, documents, identity, and tokens).
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ 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

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

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: 0

🧹 Nitpick comments (4)
packages/wasm-sdk/src/state_transitions/tokens/mod.rs (1)

246-251: Consider a small helper for the repeated transaction_id_hex pattern (optional)

Each token operation now repeats:

let st: StateTransition = state_transition.into();
let transaction_id_hex = st.transaction_id().map(hex::encode).map_err(|e| {
    WasmSdkError::generic(format!("Failed to compute transaction ID: {}", e))
})?;

This is correct, but quite duplicated across the token methods (and similar patterns exist in other modules). If this pattern continues to spread, you might consider a tiny helper (e.g. on WasmSdk or a local free function) that takes ownership of a transition and returns Result<String, WasmSdkError> to reduce repetition and keep error text in one place. This is purely a maintainability win, not a correctness fix.

Also applies to: 337-342, 440-445, 541-546, 645-650, 749-754, 906-911, 933-935, 963-965, 967-968, 1114-1119, 1223-1228, 1467-1472

packages/wasm-sdk/src/state_transitions/identity/mod.rs (2)

765-775: identityTopUp: proof‑based balances are good; confirm proof_result variant is stable

  • Building the top‑up transition via IdentityTopUpTransition::try_from_identity and then using .broadcast_and_wait::<StateTransitionProofResult> is a nice consolidation of the logic into the DPP helpers.
  • Deriving new_balance from StateTransitionProofResult::VerifiedPartialIdentity and computing topped_up_amount as new_balance.saturating_sub(initial_balance) gives you consensus-verified values and avoids underflow.
  • However, identity_top_up now hard‑fails if the proof result is not VerifiedPartialIdentity or if balance is None, where previous code may have ignored the proof and simply reported success. Please double‑check that the platform always returns VerifiedPartialIdentity with a populated balance for top‑up transitions; if not guaranteed, you may want a fallback path (e.g., treat other success variants as success and skip the balance fields instead of erroring).

Also applies to: 776-781, 782-787, 788-800, 813-818


1208-1213: identityCreditWithdrawal: new transition + remainingBalance from proof; verify proof expectations

  • The new flow—fetch nonce, build a CoreScript from toAddress, create IdentityCreditWithdrawalTransition::try_from_identity, and call .broadcast_and_wait::<StateTransitionProofResult>—is in line with the rest of the state‑transition usage.
  • Deriving transaction_id_hex from the consumed transition and surfacing it as transitionHash is consistent with other identity operations.
  • You now require the proof result to be VerifiedPartialIdentity with a non‑None balance and treat all other variants as an error "Unexpected proof result type for withdrawal". That gives a strong guarantee on remainingBalance, but also introduces a new hard failure mode if the platform ever returns a different success variant for withdrawals.

I’d suggest confirming that withdrawal transitions are guaranteed to return VerifiedPartialIdentity in all supported environments; if not, consider falling back to a success response without remainingBalance rather than turning those cases into errors.

Also applies to: 1215-1233, 1235-1238, 1240-1258, 1270-1274

packages/wasm-sdk/src/state_transitions/documents/mod.rs (1)

323-328: Document create/replace/purchase: transitionHash propagation is thorough and consistent

  • For document_create and document_replace, you now compute transaction_id_hex from the consumed StateTransition after broadcast_and_wait, and inject "transitionHash" into every result path (document returned, document entry without body, no documents in result, and non‑VerifiedDocuments fallback). That guarantees callers always see the hash when the function resolves successfully.
  • document_purchase follows the same pattern: it derives transaction_id_hex from the transition and threads it through both the VerifiedDocuments branch and the generic success branch that just reports status/message.
  • The new transitionHash fields are additive; existing fields (type, documentId, status, message, etc.) are unchanged.

If you ever decide to reduce duplication, you could potentially factor out the repeated "transitionHash" insertion in these manual Reflect::set sequences into a small helper, but that’s purely a style/maintainability improvement.

Also applies to: 329-335, 370-375, 486-492, 520-526, 555-561, 701-706, 707-712, 728-734, 844-850, 878-884, 913-919, 1351-1356, 1357-1362, 1368-1376, 1397-1401

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b5000ab and 52131d2.

📒 Files selected for processing (4)
  • packages/wasm-sdk/src/state_transitions/contracts/mod.rs
  • packages/wasm-sdk/src/state_transitions/documents/mod.rs
  • packages/wasm-sdk/src/state_transitions/identity/mod.rs
  • packages/wasm-sdk/src/state_transitions/tokens/mod.rs
🧰 Additional context used
📓 Path-based instructions (1)
**/*.rs

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.rs: Rust code must pass cargo clippy --workspace linter checks
Rust code must be formatted using cargo fmt --all

**/*.rs: Use 4-space indent for Rust files
Follow rustfmt defaults and keep code clippy-clean for Rust modules
Use snake_case for Rust module names
Use PascalCase for Rust type names
Use SCREAMING_SNAKE_CASE for Rust constants

Files:

  • packages/wasm-sdk/src/state_transitions/contracts/mod.rs
  • packages/wasm-sdk/src/state_transitions/tokens/mod.rs
  • packages/wasm-sdk/src/state_transitions/identity/mod.rs
  • packages/wasm-sdk/src/state_transitions/documents/mod.rs
🧠 Learnings (24)
📓 Common learnings
Learnt from: lklimek
Repo: dashpay/platform PR: 2716
File: packages/rs-dapi/src/services/platform_service/broadcast_state_transition.rs:181-187
Timestamp: 2025-10-09T15:59:28.329Z
Learning: In `packages/rs-dapi/src/services/platform_service/broadcast_state_transition.rs`, the maintainer requires logging full state transition bytes (`tx_bytes = hex::encode(st_bytes)`) at debug level when a state transition passes CheckTx but is removed from the block by the proposer, to facilitate debugging of this rare edge case.
Learnt from: shumkov
Repo: dashpay/platform PR: 2270
File: packages/dapi/lib/grpcServer/handlers/platform/broadcastStateTransitionHandlerFactory.js:75-77
Timestamp: 2024-10-24T04:59:20.436Z
Learning: Tenderdash's `tx` RPC method accepts transaction hashes in base64 encoding, or in hex encoding if prefixed with `0x`. Therefore, in `packages/dapi/lib/grpcServer/handlers/platform/broadcastStateTransitionHandlerFactory.js`, it's acceptable to use `stHash.toString('base64')` when calling `requestTenderRpc('tx', { hash: stHash.toString('base64') })`.
Learnt from: thephez
Repo: dashpay/platform PR: 2754
File: packages/wasm-sdk/api-definitions.json:1285-1285
Timestamp: 2025-09-03T19:33:21.688Z
Learning: In packages/wasm-sdk/api-definitions.json, thephez prefers to keep the existing "ripemd160hash20bytes1234" placeholder for ECDSA_HASH160 data field in documentation examples rather than using a valid base64-encoded format, maintaining consistency with the previous documentation approach.
Learnt from: shumkov
Repo: dashpay/platform PR: 2270
File: packages/dapi/lib/grpcServer/handlers/platform/broadcastStateTransitionHandlerFactory.js:90-96
Timestamp: 2024-10-24T05:01:51.097Z
Learning: In `broadcastStateTransitionHandlerFactory.js`, error handling when querying transaction status is handled in the API script.
Learnt from: CR
Repo: dashpay/platform PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-25T13:10:23.481Z
Learning: Use state transitions for updates in documents and data contracts
Learnt from: shumkov
Repo: dashpay/platform PR: 2270
File: packages/dapi/lib/grpcServer/handlers/platform/broadcastStateTransitionHandlerFactory.js:83-85
Timestamp: 2024-10-24T05:00:56.657Z
Learning: An upcoming filter will be introduced to the `unconfirmed_txs` endpoint in `broadcastStateTransitionHandlerFactory.js`, as noted in the TODO comment. Therefore, optimizing transaction existence checks may not be necessary at this time.
Learnt from: shumkov
Repo: dashpay/platform PR: 2270
File: packages/dapi/lib/grpcServer/handlers/platform/broadcastStateTransitionHandlerFactory.js:81-85
Timestamp: 2024-10-24T04:59:50.270Z
Learning: In `packages/dapi/lib/grpcServer/handlers/platform/broadcastStateTransitionHandlerFactory.js`, the code fetching unconfirmed transactions with a limit of 100 is temporary and will be replaced when a filter for transactions is available.
📚 Learning: 2025-10-09T15:59:28.329Z
Learnt from: lklimek
Repo: dashpay/platform PR: 2716
File: packages/rs-dapi/src/services/platform_service/broadcast_state_transition.rs:181-187
Timestamp: 2025-10-09T15:59:28.329Z
Learning: In `packages/rs-dapi/src/services/platform_service/broadcast_state_transition.rs`, the maintainer requires logging full state transition bytes (`tx_bytes = hex::encode(st_bytes)`) at debug level when a state transition passes CheckTx but is removed from the block by the proposer, to facilitate debugging of this rare edge case.

Applied to files:

  • packages/wasm-sdk/src/state_transitions/contracts/mod.rs
  • packages/wasm-sdk/src/state_transitions/tokens/mod.rs
  • packages/wasm-sdk/src/state_transitions/identity/mod.rs
  • packages/wasm-sdk/src/state_transitions/documents/mod.rs
📚 Learning: 2024-10-08T13:28:03.529Z
Learnt from: QuantumExplorer
Repo: dashpay/platform PR: 2227
File: packages/rs-drive-abci/src/platform_types/platform_state/mod.rs:141-141
Timestamp: 2024-10-08T13:28:03.529Z
Learning: When converting `PlatformStateV0` to `PlatformStateForSavingV1` in `packages/rs-drive-abci/src/platform_types/platform_state/mod.rs`, only version `0` needs to be handled in the match on `platform_state_for_saving_structure_default` because the changes are retroactive.

Applied to files:

  • packages/wasm-sdk/src/state_transitions/contracts/mod.rs
📚 Learning: 2024-10-03T11:51:06.980Z
Learnt from: shumkov
Repo: dashpay/platform PR: 2201
File: packages/rs-platform-version/src/version/v2.rs:1186-1188
Timestamp: 2024-10-03T11:51:06.980Z
Learning: In the `IdentityTransitionVersions` structure within `packages/rs-platform-version/src/version/v2.rs`, the field `credit_withdrawal` does not need the `identity_` prefix since it is already encompassed within identity state transitions.

Applied to files:

  • packages/wasm-sdk/src/state_transitions/contracts/mod.rs
  • packages/wasm-sdk/src/state_transitions/tokens/mod.rs
  • packages/wasm-sdk/src/state_transitions/identity/mod.rs
  • packages/wasm-sdk/src/state_transitions/documents/mod.rs
📚 Learning: 2025-09-02T13:30:17.703Z
Learnt from: thephez
Repo: dashpay/platform PR: 2739
File: packages/wasm-sdk/test/ui-automation/tests/state-transitions.spec.js:1-171
Timestamp: 2025-09-02T13:30:17.703Z
Learning: In packages/wasm-sdk/index.html, state transition definitions are loaded dynamically from api-definitions.json rather than being hardcoded in the HTML file. The UI loads transition categories, types, inputs, and labels from this JSON configuration file.

Applied to files:

  • packages/wasm-sdk/src/state_transitions/contracts/mod.rs
  • packages/wasm-sdk/src/state_transitions/tokens/mod.rs
  • packages/wasm-sdk/src/state_transitions/identity/mod.rs
  • packages/wasm-sdk/src/state_transitions/documents/mod.rs
📚 Learning: 2025-09-02T13:30:17.703Z
Learnt from: thephez
Repo: dashpay/platform PR: 2739
File: packages/wasm-sdk/test/ui-automation/tests/state-transitions.spec.js:1-171
Timestamp: 2025-09-02T13:30:17.703Z
Learning: In packages/wasm-sdk/index.html, state transition definitions are loaded dynamically from api-definitions.json via the loadApiDefinitions() function that fetches './api-definitions.json'. The UI doesn't have hardcoded transition definitions - instead it populates categories, types, inputs, and labels from this JSON configuration file at runtime.

Applied to files:

  • packages/wasm-sdk/src/state_transitions/contracts/mod.rs
  • packages/wasm-sdk/src/state_transitions/tokens/mod.rs
  • packages/wasm-sdk/src/state_transitions/identity/mod.rs
  • packages/wasm-sdk/src/state_transitions/documents/mod.rs
📚 Learning: 2025-11-25T13:10:23.481Z
Learnt from: CR
Repo: dashpay/platform PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-25T13:10:23.481Z
Learning: Use state transitions for updates in documents and data contracts

Applied to files:

  • packages/wasm-sdk/src/state_transitions/contracts/mod.rs
  • packages/wasm-sdk/src/state_transitions/tokens/mod.rs
  • packages/wasm-sdk/src/state_transitions/documents/mod.rs
📚 Learning: 2024-11-22T08:19:14.448Z
Learnt from: shumkov
Repo: dashpay/platform PR: 2345
File: packages/rs-drive-abci/src/execution/platform_events/protocol_upgrade/perform_events_on_first_block_of_protocol_change/v0/mod.rs:93-99
Timestamp: 2024-11-22T08:19:14.448Z
Learning: In `packages/rs-drive-abci/src/execution/platform_events/protocol_upgrade/perform_events_on_first_block_of_protocol_change/v0/mod.rs`, the `insert_contract` method requires an owned `BlockInfo`, so cloning `block_info` is necessary when calling it.

Applied to files:

  • packages/wasm-sdk/src/state_transitions/contracts/mod.rs
📚 Learning: 2024-10-06T16:18:07.994Z
Learnt from: QuantumExplorer
Repo: dashpay/platform PR: 2215
File: packages/rs-drive-abci/src/execution/engine/run_block_proposal/mod.rs:119-120
Timestamp: 2024-10-06T16:18:07.994Z
Learning: In the `run_block_proposal` function in `packages/rs-drive-abci/src/execution/engine/run_block_proposal/mod.rs`, it's acceptable to pass `platform_state` to `perform_events_on_first_block_of_protocol_change`, even if `block_platform_state` has been updated.

Applied to files:

  • packages/wasm-sdk/src/state_transitions/contracts/mod.rs
📚 Learning: 2024-10-24T04:59:20.436Z
Learnt from: shumkov
Repo: dashpay/platform PR: 2270
File: packages/dapi/lib/grpcServer/handlers/platform/broadcastStateTransitionHandlerFactory.js:75-77
Timestamp: 2024-10-24T04:59:20.436Z
Learning: Tenderdash's `tx` RPC method accepts transaction hashes in base64 encoding, or in hex encoding if prefixed with `0x`. Therefore, in `packages/dapi/lib/grpcServer/handlers/platform/broadcastStateTransitionHandlerFactory.js`, it's acceptable to use `stHash.toString('base64')` when calling `requestTenderRpc('tx', { hash: stHash.toString('base64') })`.

Applied to files:

  • packages/wasm-sdk/src/state_transitions/tokens/mod.rs
  • packages/wasm-sdk/src/state_transitions/documents/mod.rs
📚 Learning: 2024-10-29T14:16:00.141Z
Learnt from: lklimek
Repo: dashpay/platform PR: 2277
File: packages/dapi-grpc/src/mock.rs:125-145
Timestamp: 2024-10-29T14:16:00.141Z
Learning: Using `serde_json` encoding produces deterministic output required to identify requests and responses by hash, therefore `serde_json` is used as the basic serialization algorithm for mocking.

Applied to files:

  • packages/wasm-sdk/src/state_transitions/tokens/mod.rs
📚 Learning: 2025-07-28T20:00:08.502Z
Learnt from: QuantumExplorer
Repo: dashpay/platform PR: 2711
File: packages/wasm-sdk/AI_REFERENCE.md:771-783
Timestamp: 2025-07-28T20:00:08.502Z
Learning: In packages/wasm-sdk/AI_REFERENCE.md, the documentation correctly shows the actual SDK method signatures (including identityCreate and identityTopUp with their full parameter lists), which may differ from the UI inputs shown in fixed_definitions.json. The UI may collect fewer parameters from users while handling additional requirements internally.

Applied to files:

  • packages/wasm-sdk/src/state_transitions/identity/mod.rs
📚 Learning: 2024-09-30T12:11:35.148Z
Learnt from: shumkov
Repo: dashpay/platform PR: 2186
File: packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/identity_credit_withdrawal/mod.rs:48-54
Timestamp: 2024-09-30T12:11:35.148Z
Learning: In the identity credit withdrawal transition code, the field `platform_version.drive_abci.validation_and_processing.state_transitions.identity_credit_withdrawal_state_transition.transform_into_action` is not an `Option` type, so handling `None` cases is unnecessary.

Applied to files:

  • packages/wasm-sdk/src/state_transitions/identity/mod.rs
📚 Learning: 2024-10-09T00:22:57.778Z
Learnt from: QuantumExplorer
Repo: dashpay/platform PR: 2215
File: packages/rs-drive-abci/src/execution/platform_events/core_based_updates/update_masternode_identities/create_owner_identity/v1/mod.rs:19-30
Timestamp: 2024-10-09T00:22:57.778Z
Learning: In the Rust file `packages/rs-drive-abci/src/execution/platform_events/core_based_updates/update_masternode_identities/create_owner_identity/v1/mod.rs`, within the `create_owner_identity_v1` function, the `add_public_keys` method of the `Identity` struct cannot fail and does not require explicit error handling.

Applied to files:

  • packages/wasm-sdk/src/state_transitions/identity/mod.rs
📚 Learning: 2025-11-25T13:10:23.481Z
Learnt from: CR
Repo: dashpay/platform PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-25T13:10:23.481Z
Learning: Use WASM bindings to connect Rust and JavaScript code

Applied to files:

  • packages/wasm-sdk/src/state_transitions/identity/mod.rs
📚 Learning: 2025-08-05T13:55:39.147Z
Learnt from: thephez
Repo: dashpay/platform PR: 2718
File: packages/wasm-sdk/index.html:0-0
Timestamp: 2025-08-05T13:55:39.147Z
Learning: The get_identity_keys_with_proof_info function in the Rust WASM bindings does not support the "search" key request type and lacks the searchPurposeMap parameter. When proof mode is enabled with keyRequestType === 'search', the implementation falls back to the non-proof version (get_identity_keys) to maintain functionality.

Applied to files:

  • packages/wasm-sdk/src/state_transitions/identity/mod.rs
📚 Learning: 2024-10-10T05:10:50.059Z
Learnt from: QuantumExplorer
Repo: dashpay/platform PR: 2235
File: packages/rs-dpp/src/identity/identity_public_key/v0/methods/mod.rs:8-9
Timestamp: 2024-10-10T05:10:50.059Z
Learning: In the codebase, importing `Secp256k1` from `dashcore::key::Secp256k1` is acceptable.

Applied to files:

  • packages/wasm-sdk/src/state_transitions/identity/mod.rs
📚 Learning: 2025-11-25T13:10:23.481Z
Learnt from: CR
Repo: dashpay/platform PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-25T13:10:23.481Z
Learning: Applies to **/swift-sdk/**/*.{swift,h,m,c} : iOS SDK must combine both Core (SPV wallet) and Platform (identity/documents) functionality in the unified SDK with proper function naming: `dash_core_sdk_*` prefix for Core functions, `dash_sdk_*` prefix for Platform functions, and `dash_unified_sdk_*` prefix for unified functions

Applied to files:

  • packages/wasm-sdk/src/state_transitions/identity/mod.rs
📚 Learning: 2025-07-28T20:00:24.323Z
Learnt from: QuantumExplorer
Repo: dashpay/platform PR: 2711
File: packages/wasm-sdk/docs.html:2359-2383
Timestamp: 2025-07-28T20:00:24.323Z
Learning: In packages/wasm-sdk/docs.html, QuantumExplorer confirmed that placeholder private keys in documentation examples are acceptable as they are not real keys, though field name accuracy for the SDK API should still be maintained.

Applied to files:

  • packages/wasm-sdk/src/state_transitions/identity/mod.rs
📚 Learning: 2024-10-30T11:19:59.163Z
Learnt from: lklimek
Repo: dashpay/platform PR: 2277
File: packages/rs-sdk/tests/fetch/config.rs:233-233
Timestamp: 2024-10-30T11:19:59.163Z
Learning: In the Rust SDK's `rs-sdk/tests` integration tests (e.g., in `packages/rs-sdk/tests/fetch/config.rs`), we cannot create objects during tests because there is no support for object creation in this context. Therefore, hardcoded values for test identities must be used.

Applied to files:

  • packages/wasm-sdk/src/state_transitions/identity/mod.rs
📚 Learning: 2025-10-01T08:37:27.687Z
Learnt from: QuantumExplorer
Repo: dashpay/platform PR: 2790
File: packages/rs-drive/src/drive/document/index_uniqueness/validate_document_transfer_transition_action_uniqueness/mod.rs:64-0
Timestamp: 2025-10-01T08:37:27.687Z
Learning: In v1 validators for document transitions that change ownership (transfer, purchase), the owner_id parameter should be omitted from the method signature and extracted internally from the transition's document() accessor, since the owner_id is being changed by the transition itself.

Applied to files:

  • packages/wasm-sdk/src/state_transitions/documents/mod.rs
📚 Learning: 2025-10-01T08:37:32.168Z
Learnt from: QuantumExplorer
Repo: dashpay/platform PR: 2790
File: packages/rs-drive/src/drive/document/index_uniqueness/validate_document_purchase_transition_action_uniqueness/v1/mod.rs:65-0
Timestamp: 2025-10-01T08:37:32.168Z
Learning: In purchase document transitions (packages/rs-drive/src/drive/document/index_uniqueness/validate_document_purchase_transition_action_uniqueness/v1/mod.rs), the `changed_data_values` field in `UniquenessOfDataRequestUpdateType::ChangedDocument` should be set to an empty BTreeSet (`Cow::Owned(BTreeSet::new())`) because purchase transitions do not modify document data properties (like "price"), only ownership and transfer metadata. An empty set signals the uniqueness validation logic to skip checking unique indexes on data properties.

Applied to files:

  • packages/wasm-sdk/src/state_transitions/documents/mod.rs
📚 Learning: 2025-09-03T19:33:21.688Z
Learnt from: thephez
Repo: dashpay/platform PR: 2754
File: packages/wasm-sdk/api-definitions.json:1285-1285
Timestamp: 2025-09-03T19:33:21.688Z
Learning: In packages/wasm-sdk/api-definitions.json, thephez prefers to keep the existing "ripemd160hash20bytes1234" placeholder for ECDSA_HASH160 data field in documentation examples rather than using a valid base64-encoded format, maintaining consistency with the previous documentation approach.

Applied to files:

  • packages/wasm-sdk/src/state_transitions/documents/mod.rs
📚 Learning: 2024-10-24T05:01:51.097Z
Learnt from: shumkov
Repo: dashpay/platform PR: 2270
File: packages/dapi/lib/grpcServer/handlers/platform/broadcastStateTransitionHandlerFactory.js:90-96
Timestamp: 2024-10-24T05:01:51.097Z
Learning: In `broadcastStateTransitionHandlerFactory.js`, error handling when querying transaction status is handled in the API script.

Applied to files:

  • packages/wasm-sdk/src/state_transitions/documents/mod.rs
🧬 Code graph analysis (1)
packages/wasm-sdk/src/state_transitions/identity/mod.rs (5)
packages/wasm-sdk/src/state_transitions/contracts/mod.rs (1)
  • state_transition (380-381)
packages/wasm-sdk/src/state_transitions/tokens/mod.rs (10)
  • state_transition (242-243)
  • state_transition (333-334)
  • state_transition (436-437)
  • state_transition (537-538)
  • state_transition (641-642)
  • state_transition (745-746)
  • state_transition (902-903)
  • state_transition (1109-1110)
  • state_transition (1219-1220)
  • state_transition (1463-1464)
packages/rs-sdk/src/platform/transition/put_identity.rs (1)
  • state_transition (212-213)
packages/simple-signer/src/single_key_signer.rs (1)
  • private_key (76-78)
packages/wasm-sdk/src/queries/identity.rs (1)
  • balance (133-135)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
  • GitHub Check: Rust packages (wasm-sdk) / Unused dependencies
  • GitHub Check: Rust packages (wasm-sdk) / Linting
  • GitHub Check: Rust packages (wasm-sdk) / Tests
  • GitHub Check: Build JS packages / Build JS
  • GitHub Check: Build Docker images (Drive, drive, drive-abci, SDK_TEST_DATA=true
    ) / Build Drive image
  • GitHub Check: Build Docker images (RS-DAPI, rs-dapi, rs-dapi) / Build RS-DAPI image
  • GitHub Check: Build Docker images (Dashmate helper, dashmate-helper, dashmate-helper) / Build Dashmate helper image
  • GitHub Check: Rust crates security audit
🔇 Additional comments (6)
packages/wasm-sdk/src/state_transitions/contracts/mod.rs (1)

13-18: Contract create/update transitionHash wiring looks correct and consistent

  • contract_create now builds the transition via put_to_platform, derives transaction_id_hex once from that transition, and then uses DataContract::wait_for_response with the same transition. That guarantees the exposed transitionHash matches what was broadcast, without extra cloning or recomputation.
  • contract_update similarly derives transaction_id_hex from the consumed StateTransition after broadcast_and_wait, and always adds transitionHash alongside the updated version in the JS result.
  • Error paths for computing the transaction ID correctly propagate as WasmSdkError::generic(...) instead of silently dropping the hash.

No issues from a correctness or API-shape perspective here; behavior is extended but not broken.

Also applies to: 135-152, 140-147, 149-152, 199-205, 384-388, 417-422

packages/wasm-sdk/src/state_transitions/tokens/mod.rs (1)

92-147: Token proof formatting now consistently includes transitionHash

The updated format_token_result signature and JSON payloads look coherent:

  • The added transaction_id_hex: &str parameter is threaded into every handled StateTransitionProofResult variant as "transitionHash", so all token operations that use this helper now expose the transaction hash.
  • Using to_string() for balances when serializing avoids precision issues on the JS side for large values while keeping the JSON schema straightforward.

Given this is an internal helper on WasmSdk, the signature change is contained within this module and should not be externally breaking.

packages/wasm-sdk/src/state_transitions/identity/mod.rs (3)

6-7: identityCreate: two-step transition flow with transitionHash is sound

  • Using identity.put_to_platform(&sdk, ...) to obtain the state transition, then computing transaction_id_hex from that transition, and finally calling Identity::wait_for_response(&sdk, state_transition, None) cleanly separates construction, hashing, and confirmation.
  • The error mapping in the match on put_to_platform preserves detailed diagnostics while still returning a unified WasmSdkError.
  • Adding "transitionHash" to the JS result alongside the usual identity fields keeps this aligned with the contracts/documents/tokens patterns.

No functional issues spotted here.

Also applies to: 20-23, 25-25, 606-620, 622-629, 631-637, 647-652


993-998: identityCreditTransfer: transitionHash + optional balances from proof look correct

  • Capturing proof_result from broadcast_and_wait and then deriving transaction_id_hex from the consumed transition ensures the returned transitionHash matches the broadcast transaction.
  • Matching StateTransitionProofResult::VerifiedBalanceTransfer to populate senderNewBalance / recipientNewBalance and otherwise leaving them absent is a safe pattern that remains compatible when proofs are unavailable or of a different type.

This extension is additive and should not break existing consumers of the transfer result.

Also applies to: 999-1013, 1042-1066


1470-1475: identityUpdate: exposing transitionHash post‑broadcast is aligned with other flows

  • After broadcast_and_wait::<StateTransitionProofResult>, converting the update transition into a StateTransition and computing transaction_id_hex is a clean way to expose the transaction hash without extra cloning.
  • The revision logic still prefers VerifiedIdentity / VerifiedPartialIdentity when present, and only then falls back to current_revision + 1, so adding "transitionHash" does not alter revision semantics.

Looks good and consistent with the rest of the WASM identity APIs.

Also applies to: 1521-1525

packages/wasm-sdk/src/state_transitions/documents/mod.rs (1)

1058-1065: Document delete/transfer/set_price: broadcast‑only flows with transitionHash look correct

  • In document_delete, document_transfer, and document_set_price, you broadcast the already‑signed StateTransition once, then call transaction_id() on the same instance and pass the resulting hex string into build_js_result_object as "transitionHash". This keeps the hash consistent with what was actually sent to the network.
  • The additional boolean flags (deleted, transferred, priceSet) and other existing fields are preserved; only "transitionHash" is new in the payload.
  • Using build_js_result_object here keeps error handling for the JS object construction centralized and avoids the more verbose manual Reflect::set pattern used in create/replace.

These additions are straightforward and non‑breaking from the API consumer’s point of view.

Also applies to: 1071-1074, 1201-1208, 1215-1217, 1531-1538, 1545-1548

Copy link
Collaborator

@shumkov shumkov left a comment

Choose a reason for hiding this comment

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

I don't really understand the reason of these changes. Could you please give me more details why do you need to reference documents to prior transactions (e.g., linking a document to a credit transfer)?

"Verify transaction status using waitForStateTransitionResult" - we already call this method inside SDK methods.

I do think that WASM SDK should mimic and use Rust SDK as much as possible. It's just a binding and should be as thin as possible. If you want to introduce this logic you should look at rust sdk first.

@PastaPastaPasta
Copy link
Member Author

I don't really understand the reason of these changes. Could you please give me more details why do you need to reference documents to prior transactions (e.g., linking a document to a credit transfer)?

"Verify transaction status using waitForStateTransitionResult" - we already call this method inside SDK methods.

I do think that WASM SDK should mimic and use Rust SDK as much as possible. It's just a binding and should be as thin as possible. If you want to introduce this logic you should look at rust sdk first.

The primary idea is for a tip in yappr; this would be a document which links a transaction (sending credits) to a document (a reply)

So it's be a reply which references both the tip transition ID and which references the post we are replying to

Then a user can take the transition ID, fetch it, and see for itself how many credits were tipped.

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