Repository navigation
feat(rs-sdk): expose transition hash from state transition methods - #3092
Closed
thepastaclaw wants to merge 7 commits into
Closed
thepastaclaw wants to merge 7 commits into
thepastaclaw wants to merge 7 commits into
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue being fixed or feature implemented
State transition methods in the Rust SDK (
broadcast_and_wait,put_to_platform_and_wait_for_response, etc.) discard the transition hash (transaction ID) after broadcast. Downstream consumers (WASM SDK, evo-sdk) cannot access it without re-computing or restructuring their calls.This is the Rust SDK foundation for the work started in #2953, restructured per review feedback to implement the logic in the Rust SDK first (rather than only in the WASM SDK).
What was done?
Added
StateTransitionResult<T>— a thin wrapper that bundles a proof resultTwith the 32-byte transition hash (transaction ID).Core changes:
StateTransitionResult<T>inpackages/rs-sdk/src/platform/transition/state_transition_result.rstransition_hash() -> [u8; 32]— get the hashinto_parts() -> (T, [u8; 32])— destructureinto_inner() -> T— unwrap (backward compat)Deref<Target=T>— transparent access to inner resultBroadcastStateTransition::broadcast_and_waitreturnsStateTransitionResult<T>instead ofT*_with_transition_hashhelpers now wrap wait failures asWaitForStateTransitionResultFailedAfterBroadcast { transition_hash, source }after broadcast succeeds, so callers can recover the txid even when waiting failsWasmSdkErrorexposestransitionHashas aUint8Arrayfor post-broadcast wait failures, matching the successfulBroadcastAndWaitResultWasm.transitionHashpathBroadcastStateTransitionexcerpt andbroadcast_and_waitdescription forStateTransitionResult<T>Race condition avoidance
The transition hash is computed deterministically from the
StateTransitionstruct before broadcast viaStateTransition::transaction_id()(SHA-256 of serialized transition). It does not depend on blockchain state — no race condition possible. This addresses the concern raised in #2953.WASM ergonomic API follow-up
The low-level WASM
broadcastAndWaitsuccess path and post-broadcast wait-failure error path now expose the transition hash structurally. Higher-level ergonomic WASM helpers that currently return domain objects directly are intentionally left to the existing #2953 follow-up so those JS return shapes can be redesigned together instead of piecemeal in this PR.Files modified (30+ files)
broadcast.rs— core trait change and post-broadcast wait error wrapperstate_transition_result.rs— new wrapper typepackages/wasm-sdk/src/error.rs— structuredtransitionHashgetter for wait failures after broadcastbook/src/sdk/put-operations.md— updatedbroadcast_and_waitdocsHow Has This Been Tested?
cargo fmt --all— passescargo test -p dash-sdk platform::transition::broadcast --lib— passes (3 tests)cargo test -p wasm-sdk error --lib— passes (2 tests)cargo check -p wasm-sdk— passescargo check -p dash-sdk— passescargo check -p wasm-sdk --target wasm32-unknown-unknown— attempted, blocked by local clang/sysroot issue:unable to create target: 'No available targets are compatible with triple "wasm32-unknown-unknown"'Validation
Build verification
cargo check -p dash-sdk— confirms the newStateTransitionResult<T>type and all updated method signatures compile correctlycargo check -p wasm-sdk— confirms the WASM SDK consumer compiles against the updatedbroadcast_and_waitreturn type and structured error fieldType-level correctness
broadcast_and_waitreturnsStateTransitionResult<T>instead ofT, and the wrapper implementsDeref<Target=T>, so callers can inspect the hash while existing method access remains ergonomicStateTransitionResult<T>throughput_to_platform_and_wait_for_response→ callers that need onlyTuse.into_inner()wasm-sdkbroadcast layer correctly unwraps via.into_inner()forbroadcast_and_waitwhile leavingwait_for_response(which already returnsTdirectly) unchangedWaitForStateTransitionResultFailedAfterBroadcastBackward compatibility
into_inner()provides a zero-cost migration path for callers that don't need the transition hashDerefimpl means existing code that calls methods on the result works transparently without changesManual review
transaction_id()is called before broadcast (no race condition with blockchain state)Breaking Changes
broadcast_and_waitnow returnsStateTransitionResult<T>instead ofT. Callers that need justTcan use.into_inner()or rely onDeref.Checklist: