feat(rs-sdk): expose transition hash from state transition methods#3092
feat(rs-sdk): expose transition hash from state transition methods#3092thepastaclaw wants to merge 3 commits intodashpay:v3.1-devfrom
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughA new Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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.
Actionable comments posted: 1
🧹 Nitpick comments (2)
packages/rs-sdk/src/platform/transition/state_transition_result.rs (1)
11-15: Consider derivingPartialEqandEqfor testability.Adding
PartialEqandEq(bounded onT: PartialEq/T: Eq) would make it straightforward to assert equality in tests without having to decompose into parts.Suggested change
-#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq, Eq)]🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/rs-sdk/src/platform/transition/state_transition_result.rs` around lines 11 - 15, The StateTransitionResult struct should derive PartialEq and Eq for easier testing: add PartialEq and Eq to the derive list on StateTransitionResult and constrain implementations so these derives require T: PartialEq (and T: Eq for Eq). Update the derive macro on the struct (StateTransitionResult) to include PartialEq and Eq so tests can directly compare instances without manual decomposition.packages/rs-sdk/src/platform/documents/transitions/create.rs (1)
174-179: Consider propagating the transition hash through the result enums.All document transition methods (create, delete, replace, purchase, set_price) currently discard the transition hash via
into_inner(). To fully surface the hash to SDK consumers — which is the goal of this PR — these per-operation result enums (e.g.,DocumentCreateResult) could carry the[u8; 32]alongside the payload, or the methods could returnStateTransitionResult<DocumentCreateResult>directly. This can be a follow-up.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/rs-sdk/src/platform/documents/transitions/create.rs` around lines 174 - 179, The DocumentCreateResult enum currently drops the transition hash (via into_inner()), so update the API to propagate the transition hash: either add a hash field to the enum (e.g., change DocumentCreateResult::Document(Document) to carry (Document, [u8; 32]) or similar) and adjust all callers that construct/consume DocumentCreateResult, or instead change the create method(s) to return StateTransitionResult<DocumentCreateResult> directly so the hash is preserved; apply the same pattern for the other per-operation enums/methods (delete, replace, purchase, set_price) and ensure functions that call into_inner() are updated to handle the preserved hash accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/rs-sdk/src/platform/tokens/transitions/unfreeze.rs`:
- Around line 69-70: The broadcast call hardcodes None for settings causing
caller-provided settings to be ignored; change the unfreeze transition to
extract settings from the builder (use
unfreeze_tokens_transition_builder.settings or the builder’s with_settings()
value) and pass that into
state_transition.broadcast_and_wait::<StateTransitionProofResult>(self,
put_settings) instead of None; apply the same fix pattern used in
destroy_frozen_funds (and replicate for mint.rs, freeze.rs,
set_price_for_direct_purchase.rs) so user_fee_increase and retry configuration
are honored.
---
Nitpick comments:
In `@packages/rs-sdk/src/platform/documents/transitions/create.rs`:
- Around line 174-179: The DocumentCreateResult enum currently drops the
transition hash (via into_inner()), so update the API to propagate the
transition hash: either add a hash field to the enum (e.g., change
DocumentCreateResult::Document(Document) to carry (Document, [u8; 32]) or
similar) and adjust all callers that construct/consume DocumentCreateResult, or
instead change the create method(s) to return
StateTransitionResult<DocumentCreateResult> directly so the hash is preserved;
apply the same pattern for the other per-operation enums/methods (delete,
replace, purchase, set_price) and ensure functions that call into_inner() are
updated to handle the preserved hash accordingly.
In `@packages/rs-sdk/src/platform/transition/state_transition_result.rs`:
- Around line 11-15: The StateTransitionResult struct should derive PartialEq
and Eq for easier testing: add PartialEq and Eq to the derive list on
StateTransitionResult and constrain implementations so these derives require T:
PartialEq (and T: Eq for Eq). Update the derive macro on the struct
(StateTransitionResult) to include PartialEq and Eq so tests can directly
compare instances without manual decomposition.
|
Addressed the CodeRabbit review in 22fc89c: Fixed:
Deferred:
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/rs-sdk/src/platform/transition/state_transition_result.rs (1)
27-29: Nit: consider returning&[u8; 32]fromtransition_hash().Currently returns by value (copy). Since
[u8; 32]isCopythis is fine and arguably simpler, but returning a reference would be more conventional for accessor methods on fixed-size data and avoids a 32-byte copy on non-optimized builds. Totally optional.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/rs-sdk/src/platform/transition/state_transition_result.rs` around lines 27 - 29, The accessor transition_hash() currently returns [u8; 32] by value which copies the array; change its signature to return a reference -> &[u8; 32] and return &self.transition_hash to avoid the copy (update the method in the impl for the relevant struct). After changing the signature, update any call sites that rely on ownership (e.g., places that expect a copied array should explicitly clone/copy if needed) and run tests to ensure no API breakages.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/rs-sdk/src/platform/transition/state_transition_result.rs`:
- Around line 27-29: The accessor transition_hash() currently returns [u8; 32]
by value which copies the array; change its signature to return a reference ->
&[u8; 32] and return &self.transition_hash to avoid the copy (update the method
in the impl for the relevant struct). After changing the signature, update any
call sites that rely on ownership (e.g., places that expect a copied array
should explicitly clone/copy if needed) and run tests to ensure no API
breakages.
shumkov
left a comment
There was a problem hiding this comment.
It doesn't make sense to me. You have already state transition around so you can store hash into varibable and reuse it. @PastaPastaPasta please review your friend's PRs first.
|
Thanks for the review @shumkov. You make a fair point — if the caller already has the state transition, they can compute the hash themselves via The motivation was convenience for the WASM SDK layer (where thephez reported needing the txid from Happy to close this if the consensus is that it's unnecessary overhead. @PastaPastaPasta thoughts? |
|
Shumkov and claw most times you use the SDK you don't actually have the transition? It gets built internally I think. I see no reason to not return txid. |
|
@shumkov — I want to respectfully push back on this. You're right that inside the SDK, the state transition exists as a local variable. But that's exactly the point — it's local to the SDK internals. The caller never sees it. Look at pub async fn document_create(...) -> Result<DocumentCreateResult, Error> {
let state_transition = builder.sign(...).await?; // built internally
let proof_result = state_transition.broadcast_and_wait(self, settings).await?;
match proof_result { ... } // consumed internally — only proof result returned
}The So "you already have the state transition around" is true for someone modifying the SDK, but false for SDK consumers (WASM SDK, js-evo-sdk, application code). Without this PR (or similar), there's no way for WASM SDK callers to get the transaction ID after a The As Pasta noted: "most times you use the SDK you don't actually have the transition. It gets built internally." This PR fixes that gap. |
| let put_settings = freeze_tokens_transition_builder.settings; | ||
|
|
||
| let state_transition = freeze_tokens_transition_builder | ||
| .sign(self, signing_key, signer, platform_version) | ||
| .await?; | ||
|
|
||
| let proof_result = state_transition | ||
| .broadcast_and_wait::<StateTransitionProofResult>(self, None) | ||
| .await?; | ||
| .broadcast_and_wait::<StateTransitionProofResult>(self, put_settings) | ||
| .await? | ||
| .into_inner(); |
There was a problem hiding this comment.
claw is this let put_settings = freeze_tokens_transition_builder.settings a seperate bug fix that should live in it's own PR? or an unintended change here maybe?
same question for other adding of let put_settings = mint_tokens_transition_builder.settings;
| /// Wrapper that bundles a state transition proof result with the transition hash. | ||
| /// | ||
| /// The transition hash (also known as the transaction ID) is computed deterministically | ||
| /// from the serialized `StateTransition` before broadcast, so it does not depend on | ||
| /// blockchain state and there is no race condition. | ||
| /// | ||
| /// `StateTransitionResult<T>` implements `Deref<Target = T>`, so existing code that | ||
| /// only needs the inner result can use it transparently. | ||
| #[derive(Debug, Clone, PartialEq, Eq)] | ||
| pub struct StateTransitionResult<T> { |
There was a problem hiding this comment.
claw; would it make more sense for the T to just include the transition hash? is that possible?
|
Good catch — the Re: T including transition hash: That's a good idea. The challenge is that |
|
Re: @PastaPastaPasta's inline comments: On On including transition hash in |
22fc89c to
3b57def
Compare
|
Done — split into its own PR: #3132 Removed the put_settings changes from this PR. Re: T including transition hash: Looked into this. |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/rs-sdk/src/platform/transition/transfer_to_addresses.rs (1)
23-27:⚠️ Potential issue | 🟡 MinorStale duplicate bullet in the
Returnsdoc-comment.The return type is a 2-tuple
(AddressInfos, Credits)but the doc lists three bullets, repeating "Proof-backed address infos for provided recipients" as both the first and third items.📝 Proposed fix
- /// Returns tuple of: - /// * Proof-backed address infos for provided recipients - /// * Updated identity balance - /// * Proof-backed address infos for provided recipients + /// Returns tuple of: + /// * Proof-backed address infos for provided recipients + /// * Updated identity balance after the transfer🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/rs-sdk/src/platform/transition/transfer_to_addresses.rs` around lines 23 - 27, The Returns doc-comment in transfer_to_addresses.rs currently lists three bullets and repeats "Proof-backed address infos for provided recipients" although the function returns a 2-tuple (AddressInfos, Credits); update the doc-comment for the function (e.g., the transfer_to_addresses function) to list exactly two return bullets matching the actual return types: 1) Proof-backed address infos for provided recipients (AddressInfos) and 2) Updated identity balance (Credits), removing the duplicated third bullet and keeping wording consistent with the return type names.
🧹 Nitpick comments (1)
packages/rs-sdk/src/platform/transition/top_up_identity_from_addresses.rs (1)
84-116: Transition hash is silently discarded — high-level helpers won't propagate it to WASM/JS callers.All five high-level SDK methods updated in this PR (
top_up_from_addresses_with_nonce,token_freeze,document_transfer,transfer_credits_to_addresses,put_with_address_funding) call.into_inner()immediately and throw away the 32-byte transition hash. The hash is only observable from callers who invokebroadcast_and_waitdirectly — but the PR's stated motivation is specifically that "WASM SDK, js-evo-sdk, application code do not have access to the internal StateTransition". Callers using these high-level SDK methods, including the WASM SDK thin layer built on top of them, will still receive no hash.Consider either:
- Returning
(ReturnType, [u8; 32])from each high-level method, or- Defining a higher-level counterpart of
StateTransitionResult<T>that wraps the domain-specific result types (FreezeResult,DocumentTransferResult, etc.)If propagation is intentionally deferred, tracking the gap in a follow-up issue would help ensure it's not forgotten.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/rs-sdk/src/platform/transition/top_up_identity_from_addresses.rs` around lines 84 - 116, The code discards the 32-byte transition hash by calling .into_inner() on broadcast_and_wait results; update top_up_from_addresses_with_nonce (and the other high-level methods) to capture the transition hash before into_inner() and propagate it to callers—either by returning a tuple like (address_infos, balance, transition_hash) from the handler that matches StateTransitionProofResult::VerifiedIdentityWithAddressInfos (use the existing collect_address_infos_from_proof and identity.balance logic) or by introducing a small wrapper type (e.g., StateTransitionResult<T> containing result and [u8;32]) and returning that instead so the transition hash from broadcast_and_wait is not lost.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@packages/rs-sdk/src/platform/transition/transfer_to_addresses.rs`:
- Around line 23-27: The Returns doc-comment in transfer_to_addresses.rs
currently lists three bullets and repeats "Proof-backed address infos for
provided recipients" although the function returns a 2-tuple (AddressInfos,
Credits); update the doc-comment for the function (e.g., the
transfer_to_addresses function) to list exactly two return bullets matching the
actual return types: 1) Proof-backed address infos for provided recipients
(AddressInfos) and 2) Updated identity balance (Credits), removing the
duplicated third bullet and keeping wording consistent with the return type
names.
---
Nitpick comments:
In `@packages/rs-sdk/src/platform/transition/top_up_identity_from_addresses.rs`:
- Around line 84-116: The code discards the 32-byte transition hash by calling
.into_inner() on broadcast_and_wait results; update
top_up_from_addresses_with_nonce (and the other high-level methods) to capture
the transition hash before into_inner() and propagate it to callers—either by
returning a tuple like (address_infos, balance, transition_hash) from the
handler that matches
StateTransitionProofResult::VerifiedIdentityWithAddressInfos (use the existing
collect_address_infos_from_proof and identity.balance logic) or by introducing a
small wrapper type (e.g., StateTransitionResult<T> containing result and
[u8;32]) and returning that instead so the transition hash from
broadcast_and_wait is not lost.
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/wasm-sdk/src/state_transitions/broadcast.rs (1)
94-100:⚠️ Potential issue | 🟠 Major
transition_hashis silently discarded — consider surfacing it to JS callers.
.into_inner()correctly satisfies theconvert_proof_resulttype, but it throws away thetransition_hashthatStateTransitionResult<T>carries. The PR discussion explicitly identifies WASM SDK consumers (js-evo-sdk, browser apps) as the primary beneficiaries of having the transaction hash, yet those callers receive no way to observe it frombroadcastAndWait.A minimal approach would be to return a small two-field JS object that contains both the proof result and the hex-encoded hash, e.g.:
💡 Sketch of a hash-exposing return value
+use wasm_bindgen::JsValue; +use js_sys::Object; pub async fn broadcast_and_wait( &self, #[wasm_bindgen(js_name = "stateTransition")] state_transition: &StateTransitionWasm, settings: Option<PutSettingsJs>, -) -> Result<StateTransitionProofResultTypeJs, WasmSdkError> { +) -> Result<JsValue, WasmSdkError> { let st: StateTransition = state_transition.into(); let put_settings = parse_put_settings(settings)?; let result = st .broadcast_and_wait::<StateTransitionProofResult>(self.as_ref(), put_settings) .await .map_err(|e| WasmSdkError::generic(format!("Failed to broadcast: {}", e)))?; + let (inner, hash) = result.into_parts(); + let proof = convert_proof_result(inner).map_err(WasmSdkError::from)?; + let hash_hex = hex::encode(hash); + let obj = Object::new(); + js_sys::Reflect::set(&obj, &"result".into(), &proof.into())?; + js_sys::Reflect::set(&obj, &"transitionHash".into(), &hash_hex.into())?; + Ok(obj.into()) - convert_proof_result(result.into_inner()).map_err(WasmSdkError::from) }Alternatively, exposing a
broadcastAndWaitWithHashsibling method would avoid a breaking change tobroadcastAndWait's return type for existing callers.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/wasm-sdk/src/state_transitions/broadcast.rs` around lines 94 - 100, The code currently discards the transition_hash by calling result.into_inner() before convert_proof_result; update the broadcast path (the method invoking st.broadcast_and_wait::<StateTransitionProofResult> — the wasm-facing broadcastAndWait wrapper) to extract both the inner proof result and the transition_hash from the returned StateTransitionResult<T> (do not call into_inner() alone), then return both to JS either by changing the return to a small two-field object { proofResult, transitionHashHex } or by adding a sibling method broadcastAndWaitWithHash that returns that object; ensure you hex-encode the transition_hash, keep existing error handling (WasmSdkError) and still call convert_proof_result on the proof payload before packaging the result.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@packages/wasm-sdk/src/state_transitions/broadcast.rs`:
- Around line 94-100: The code currently discards the transition_hash by calling
result.into_inner() before convert_proof_result; update the broadcast path (the
method invoking st.broadcast_and_wait::<StateTransitionProofResult> — the
wasm-facing broadcastAndWait wrapper) to extract both the inner proof result and
the transition_hash from the returned StateTransitionResult<T> (do not call
into_inner() alone), then return both to JS either by changing the return to a
small two-field object { proofResult, transitionHashHex } or by adding a sibling
method broadcastAndWaitWithHash that returns that object; ensure you hex-encode
the transition_hash, keep existing error handling (WasmSdkError) and still call
convert_proof_result on the proof payload before packaging the result.
9aba70e to
07b2e5c
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
packages/rs-sdk/src/platform/transition.rs (1)
19-19: Optional:state_transition_resultmodule declaration is out of alphabetical order.It is placed after
transfer_to_addresses(line 18) rather than betweenput_settingsandtop_up_address, breaking the existing alphabetical grouping. Consider moving it to maintain consistency.♻️ Suggested placement
pub mod put_settings; +pub mod state_transition_result; pub mod top_up_address; ... -pub mod state_transition_result; // remove from line 19🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/rs-sdk/src/platform/transition.rs` at line 19, The module declaration for state_transition_result is out of alphabetical order relative to the other pub mod lines; move the pub mod state_transition_result; declaration so it appears between pub mod put_settings; and pub mod top_up_address; (i.e., place state_transition_result between those two) to restore the alphabetical grouping and consistent ordering with transfer_to_addresses, put_settings, and top_up_address.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/rs-sdk/src/platform/transition/state_transition_result.rs`:
- Line 11: Add PartialEq and Eq to the derive list for the StateTransitionResult
struct so tests can use assert_eq!; update the existing #[derive(Debug, Clone)]
line to #[derive(Debug, Clone, PartialEq, Eq)] (i.e., extend the derive on the
struct defined in state_transition_result.rs) and run cargo test to verify
equality-based assertions now work.
---
Nitpick comments:
In `@packages/rs-sdk/src/platform/transition.rs`:
- Line 19: The module declaration for state_transition_result is out of
alphabetical order relative to the other pub mod lines; move the pub mod
state_transition_result; declaration so it appears between pub mod put_settings;
and pub mod top_up_address; (i.e., place state_transition_result between those
two) to restore the alphabetical grouping and consistent ordering with
transfer_to_addresses, put_settings, and top_up_address.
| /// | ||
| /// `StateTransitionResult<T>` implements `Deref<Target = T>`, so existing code that | ||
| /// only needs the inner result can use it transparently. | ||
| #[derive(Debug, Clone)] |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
find . -type f -name "state_transition_result.rs" | head -5Repository: dashpay/platform
Length of output: 128
🏁 Script executed:
cat -n packages/rs-sdk/src/platform/transition/state_transition_result.rs | head -50Repository: dashpay/platform
Length of output: 2044
🏁 Script executed:
git log --oneline --all | grep -i "22fc89c1c\|state.transition.result" | head -10Repository: dashpay/platform
Length of output: 144
🏁 Script executed:
git show --stat 22fc89c1c 2>/dev/null | head -30Repository: dashpay/platform
Length of output: 42
🏁 Script executed:
git log --all --oneline --decorate | grep -i "state.transition" | head -20Repository: dashpay/platform
Length of output: 1741
🏁 Script executed:
git log --all --grep="PartialEq\|Eq" --oneline | head -10Repository: dashpay/platform
Length of output: 42
🏁 Script executed:
rg "StateTransitionResult" packages/rs-sdk/src/platform/transition/ -A 5 -B 2Repository: dashpay/platform
Length of output: 10366
🏁 Script executed:
git log --all --oneline packages/rs-sdk/src/platform/transition/state_transition_result.rs | head -10Repository: dashpay/platform
Length of output: 130
🏁 Script executed:
git show d6f4eb9ac --stat | head -40Repository: dashpay/platform
Length of output: 2283
🏁 Script executed:
git log --all --oneline --grep="22fc89c1c" | head -5Repository: dashpay/platform
Length of output: 42
🏁 Script executed:
git log --all --oneline | grep -E "22fc89c1c|3077" | head -5Repository: dashpay/platform
Length of output: 135
🏁 Script executed:
git show d6f4eb9ac:packages/rs-sdk/src/platform/transition/state_transition_result.rs 2>/dev/null | head -20Repository: dashpay/platform
Length of output: 42
🏁 Script executed:
git show d6f4eb9ac --format=fuller | head -100Repository: dashpay/platform
Length of output: 4611
🏁 Script executed:
git log --all --oneline -S "PartialEq" -- packages/rs-sdk/src/platform/transition/state_transition_result.rs | head -10Repository: dashpay/platform
Length of output: 42
🏁 Script executed:
git log --all --oneline -S "Eq" -- packages/rs-sdk/src/platform/transition/state_transition_result.rs | head -10Repository: dashpay/platform
Length of output: 42
🏁 Script executed:
git show d6f4eb9ac -- packages/rs-sdk/src/platform/transition/state_transition_result.rs | head -50Repository: dashpay/platform
Length of output: 42
🏁 Script executed:
git show d6f4eb9ac:packages/rs-sdk/src/platform/transition/state_transition_result.rs 2>&1 | catRepository: dashpay/platform
Length of output: 179
🏁 Script executed:
git log --all --pretty=format:"%H %s" | grep "3077"Repository: dashpay/platform
Length of output: 408
🏁 Script executed:
git show --name-status d6f4eb9ac | grep "state_transition_result"Repository: dashpay/platform
Length of output: 42
🏁 Script executed:
git diff d6f4eb9ac~1 d6f4eb9ac -- packages/rs-sdk/src/platform/transition/state_transition_result.rsRepository: dashpay/platform
Length of output: 42
🏁 Script executed:
git log --all --oneline -S "StateTransitionResult" -- "**.rs" | head -20Repository: dashpay/platform
Length of output: 146
🏁 Script executed:
git log --oneline --all packages/rs-sdk/src/platform/transition/ | head -20Repository: dashpay/platform
Length of output: 1669
🏁 Script executed:
git show HEAD:packages/rs-sdk/src/platform/transition/state_transition_result.rs 2>&1 | head -30Repository: dashpay/platform
Length of output: 1067
🏁 Script executed:
rg "PartialEq.*Eq" packages/rs-sdk/src/platform/transition/ -B 2Repository: dashpay/platform
Length of output: 42
🏁 Script executed:
git show 07b2e5cba --format=fuller | head -50Repository: dashpay/platform
Length of output: 2109
🏁 Script executed:
git show 07b2e5cba -- packages/rs-sdk/src/platform/transition/state_transition_result.rs | head -80Repository: dashpay/platform
Length of output: 2982
🏁 Script executed:
git log --all -p -- packages/rs-sdk/src/platform/transition/state_transition_result.rs | grep -A 3 -B 3 "PartialEq\|Eq" | head -40Repository: dashpay/platform
Length of output: 42
🏁 Script executed:
git show 07b2e5cba --stat | grep "state_transition_result"Repository: dashpay/platform
Length of output: 245
🏁 Script executed:
git log --all --oneline --grep="post-review\|22fc89c1c" | head -10Repository: dashpay/platform
Length of output: 42
🏁 Script executed:
rg "StateTransitionResult" packages/rs-sdk/src/platform/transition/broadcast.rs -B 2 -A 2 | head -50Repository: dashpay/platform
Length of output: 1363
Add PartialEq and Eq derives for test assertions.
The struct only derives Debug and Clone, but PartialEq and Eq would enable assert_eq! comparisons in tests. Both should be unconditionally derived.
🛠️ Proposed fix
-#[derive(Debug, Clone)]
+#[derive(Debug, Clone, PartialEq, Eq)]
pub struct StateTransitionResult<T> {🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@packages/rs-sdk/src/platform/transition/state_transition_result.rs` at line
11, Add PartialEq and Eq to the derive list for the StateTransitionResult struct
so tests can use assert_eq!; update the existing #[derive(Debug, Clone)] line to
#[derive(Debug, Clone, PartialEq, Eq)] (i.e., extend the derive on the struct
defined in state_transition_result.rs) and run cargo test to verify
equality-based assertions now work.
07b2e5c to
4e49bd2
Compare
Add StateTransitionResult<T> wrapper type that bundles the proof result with the transition hash (transaction ID). The hash is computed deterministically from the serialized StateTransition BEFORE broadcast, avoiding any race condition with blockchain state. broadcast_and_wait now returns StateTransitionResult<T> instead of T. The wrapper implements Deref<Target=T> for ergonomic access and provides into_inner() for callers that only need the result. All existing callers updated to use .into_inner() to maintain current behavior. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
4e49bd2 to
b2f3b42
Compare
…esult - Move state_transition_result module to alphabetical position in transition.rs - Update wasm-sdk broadcast.rs to unwrap StateTransitionResult with into_inner()
…3092) The into_inner() calls on broadcast results require the StateTransitionResult type from PR dashpay#3092. Since this PR targets v3.1-dev which doesn't have dashpay#3092 merged yet, these calls break compilation. Reverting until dashpay#3092 lands.
wait_for_response returns T directly, not StateTransitionResult<T>, so into_inner() is not needed there.
| @@ -0,0 +1,56 @@ | |||
| use std::ops::Deref; | |||
There was a problem hiding this comment.
Good question. Yes, it would be cleaner to include the transition hash directly in the result types (DocumentCreateResult, MintResult, etc.) rather than using a generic wrapper.
The wrapper approach (StateTransitionResult<T>) was chosen because:
- It avoids modifying 20+ result enums individually
- The hash is a property of the broadcast operation, not the result type itself
But Pasta's right that embedding it in T would be simpler for consumers — no .into_inner() calls, no wrapper to deal with. The downside is every result type needs a transition_hash field added.
I'd lean toward keeping the wrapper for now since it's non-invasive, but happy to refactor if you prefer the embedded approach. What's your preference?
|
Addressing the review comments:
|
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 ofTRace 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.Files modified (30 files)
broadcast.rs— core trait changestate_transition_result.rs— new wrapper typeHow Has This Been Tested?
cargo check -p dash-sdkpassesinto_inner()orDerefworks unchangedBreaking Changes
broadcast_and_waitnow returnsStateTransitionResult<T>instead ofT. Callers that need justTcan use.into_inner()or rely onDeref.Checklist:
Summary by CodeRabbit
New Features
Refactor