Skip to content

feat(rs-sdk): expose transition hash from state transition methods - #3092

Closed
thepastaclaw wants to merge 7 commits into
dashpay:v4.1-devfrom
thepastaclaw:feat/sdk-transition-hash
Closed

thepastaclaw wants to merge 7 commits into
dashpay:v4.1-devfrom
thepastaclaw:feat/sdk-transition-hash

Conversation

@thepastaclaw

@thepastaclaw thepastaclaw commented Feb 17, 2026 •

Copy link
Copy Markdown
Collaborator

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 result T with the 32-byte transition hash (transaction ID).

Core changes:

  • New type: StateTransitionResult<T> in packages/rs-sdk/src/platform/transition/state_transition_result.rs
    • transition_hash() -> [u8; 32] — get the hash
    • into_parts() -> (T, [u8; 32]) — destructure
    • into_inner() -> T — unwrap (backward compat)
    • Deref<Target=T> — transparent access to inner result
  • Modified: BroadcastStateTransition::broadcast_and_wait returns StateTransitionResult<T> instead of T
  • Updated all 28 downstream methods across documents, tokens, identity, and transfer operations
  • Preserved post-broadcast wait failures: *_with_transition_hash helpers now wrap wait failures as WaitForStateTransitionResultFailedAfterBroadcast { transition_hash, source } after broadcast succeeds, so callers can recover the txid even when waiting fails
  • WASM structured error field: WasmSdkError exposes transitionHash as a Uint8Array for post-broadcast wait failures, matching the successful BroadcastAndWaitResultWasm.transitionHash path
  • Documentation: updated the SDK book BroadcastStateTransition excerpt and broadcast_and_wait description for StateTransitionResult<T>

Race condition avoidance

The transition hash is computed deterministically from the StateTransition struct before broadcast via StateTransition::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 broadcastAndWait success 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 wrapper
  • state_transition_result.rs — new wrapper type
  • 6 document transitions (create, delete, purchase, replace, set_price, transfer)
  • 11 token transitions (burn, claim, config_update, destroy_frozen_funds, direct_purchase, emergency_action, freeze, mint, set_price_for_direct_purchase, transfer, unfreeze)
  • 9 identity/transfer operations
  • packages/wasm-sdk/src/error.rs — structured transitionHash getter for wait failures after broadcast
  • book/src/sdk/put-operations.md — updated broadcast_and_wait docs

How Has This Been Tested?

  • cargo fmt --all — passes
  • cargo 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 — passes
  • cargo check -p dash-sdk — passes
  • cargo 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 new StateTransitionResult<T> type and all updated method signatures compile correctly
  • cargo check -p wasm-sdk — confirms the WASM SDK consumer compiles against the updated broadcast_and_wait return type and structured error field

Type-level correctness

  • broadcast_and_wait returns StateTransitionResult<T> instead of T, and the wrapper implements Deref<Target=T>, so callers can inspect the hash while existing method access remains ergonomic
  • Downstream callers updated to propagate StateTransitionResult<T> through put_to_platform_and_wait_for_response → callers that need only T use .into_inner()
  • The wasm-sdk broadcast layer correctly unwraps via .into_inner() for broadcast_and_wait while leaving wait_for_response (which already returns T directly) unchanged
  • Post-broadcast wait failures preserve the same transaction id hash through WaitForStateTransitionResultFailedAfterBroadcast

Backward compatibility

  • No existing public API is removed — into_inner() provides a zero-cost migration path for callers that don't need the transition hash
  • Deref impl means existing code that calls methods on the result works transparently without changes

Manual review

  • Verified each changed transition helper to confirm only post-broadcast wait errors are wrapped with the precomputed transition hash; signing, nonce, validation, and broadcast errors still return unchanged
  • Confirmed transaction_id() is called before broadcast (no race condition with blockchain state)

Breaking Changes

broadcast_and_wait now returns StateTransitionResult<T> instead of T. Callers that need just T can use .into_inner() or rely on Deref.

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

Loading
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.

5 participants