-
Notifications
You must be signed in to change notification settings - Fork 45
feat(wasm-sdk): add transitionHash to all state transition functions #2953
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: v3.0-dev
Are you sure you want to change the base?
Conversation
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]>
📝 WalkthroughWalkthroughFour 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 Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ 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. Comment |
There was a problem hiding this 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
WasmSdkor a local free function) that takes ownership of a transition and returnsResult<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_identityand then using.broadcast_and_wait::<StateTransitionProofResult>is a nice consolidation of the logic into the DPP helpers.- Deriving
new_balancefromStateTransitionProofResult::VerifiedPartialIdentityand computingtopped_up_amountasnew_balance.saturating_sub(initial_balance)gives you consensus-verified values and avoids underflow.- However,
identity_top_upnow hard‑fails if the proof result is notVerifiedPartialIdentityor ifbalanceisNone, where previous code may have ignored the proof and simply reported success. Please double‑check that the platform always returnsVerifiedPartialIdentitywith a populatedbalancefor 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
CoreScriptfromtoAddress, createIdentityCreditWithdrawalTransition::try_from_identity, and call.broadcast_and_wait::<StateTransitionProofResult>—is in line with the rest of the state‑transition usage.- Deriving
transaction_id_hexfrom the consumed transition and surfacing it astransitionHashis consistent with other identity operations.- You now require the proof result to be
VerifiedPartialIdentitywith a non‑Nonebalanceand treat all other variants as an error"Unexpected proof result type for withdrawal". That gives a strong guarantee onremainingBalance, 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
VerifiedPartialIdentityin all supported environments; if not, consider falling back to a success response withoutremainingBalancerather 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_createanddocument_replace, you now computetransaction_id_hexfrom the consumedStateTransitionafterbroadcast_and_wait, and inject"transitionHash"into every result path (document returned, document entry without body, no documents in result, and non‑VerifiedDocumentsfallback). That guarantees callers always see the hash when the function resolves successfully.document_purchasefollows the same pattern: it derivestransaction_id_hexfrom the transition and threads it through both theVerifiedDocumentsbranch and the generic success branch that just reports status/message.- The new
transitionHashfields 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 manualReflect::setsequences 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
📒 Files selected for processing (4)
packages/wasm-sdk/src/state_transitions/contracts/mod.rspackages/wasm-sdk/src/state_transitions/documents/mod.rspackages/wasm-sdk/src/state_transitions/identity/mod.rspackages/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 passcargo clippy --workspacelinter checks
Rust code must be formatted usingcargo 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.rspackages/wasm-sdk/src/state_transitions/tokens/mod.rspackages/wasm-sdk/src/state_transitions/identity/mod.rspackages/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.rspackages/wasm-sdk/src/state_transitions/tokens/mod.rspackages/wasm-sdk/src/state_transitions/identity/mod.rspackages/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.rspackages/wasm-sdk/src/state_transitions/tokens/mod.rspackages/wasm-sdk/src/state_transitions/identity/mod.rspackages/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.rspackages/wasm-sdk/src/state_transitions/tokens/mod.rspackages/wasm-sdk/src/state_transitions/identity/mod.rspackages/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.rspackages/wasm-sdk/src/state_transitions/tokens/mod.rspackages/wasm-sdk/src/state_transitions/identity/mod.rspackages/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.rspackages/wasm-sdk/src/state_transitions/tokens/mod.rspackages/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.rspackages/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_createnow builds the transition viaput_to_platform, derivestransaction_id_hexonce from that transition, and then usesDataContract::wait_for_responsewith the same transition. That guarantees the exposedtransitionHashmatches what was broadcast, without extra cloning or recomputation.contract_updatesimilarly derivestransaction_id_hexfrom the consumedStateTransitionafterbroadcast_and_wait, and always addstransitionHashalongside 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 transitionHashThe updated
format_token_resultsignature and JSON payloads look coherent:
- The added
transaction_id_hex: &strparameter is threaded into every handledStateTransitionProofResultvariant 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 computingtransaction_id_hexfrom that transition, and finally callingIdentity::wait_for_response(&sdk, state_transition, None)cleanly separates construction, hashing, and confirmation.- The error mapping in the
matchonput_to_platformpreserves detailed diagnostics while still returning a unifiedWasmSdkError.- 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_resultfrombroadcast_and_waitand then derivingtransaction_id_hexfrom the consumed transition ensures the returnedtransitionHashmatches the broadcast transaction.- Matching
StateTransitionProofResult::VerifiedBalanceTransferto populatesenderNewBalance/recipientNewBalanceand 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 aStateTransitionand computingtransaction_id_hexis a clean way to expose the transaction hash without extra cloning.- The revision logic still prefers
VerifiedIdentity/VerifiedPartialIdentitywhen present, and only then falls back tocurrent_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, anddocument_set_price, you broadcast the already‑signedStateTransitiononce, then calltransaction_id()on the same instance and pass the resulting hex string intobuild_js_result_objectas"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_objecthere keeps error handling for the JS object construction centralized and avoids the more verbose manualReflect::setpattern 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
shumkov
left a comment
There was a problem hiding this 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.
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. |
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:
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):
Tokens (10 functions):
Contracts (2 functions):
Documents (6 functions):
Implementation Pattern:
For functions using broadcast_and_wait (borrows &self):
For functions using broadcast:
Example Return Value (identityCreditTransfer):
How Has This Been Tested?
Breaking Changes
None. All changes are additive - existing return fields remain unchanged, new fields are added.
Checklist:
For repository code-owners and collaborators only
Summary by CodeRabbit
Release Notes
✏️ Tip: You can customize this high-level summary in your review settings.