-
Notifications
You must be signed in to change notification settings - Fork 48
feat(rs-sdk): expose transition hash from state transition methods #3092
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.1-dev
Are you sure you want to change the base?
Changes from all commits
bf57a91
8d596be
261c79f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| use std::ops::Deref; | ||
|
|
||
| /// 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)] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 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 The struct only derives 🛠️ Proposed fix-#[derive(Debug, Clone)]
+#[derive(Debug, Clone, PartialEq, Eq)]
pub struct StateTransitionResult<T> {🤖 Prompt for AI Agents |
||
| pub struct StateTransitionResult<T> { | ||
|
Comment on lines
3
to
12
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. claw; would it make more sense for the T to just include the transition hash? is that possible? |
||
| inner: T, | ||
| transition_hash: [u8; 32], | ||
| } | ||
|
|
||
| impl<T> StateTransitionResult<T> { | ||
| /// Creates a new result bundling the proof result with the transition hash. | ||
| pub fn new(inner: T, transition_hash: [u8; 32]) -> Self { | ||
| Self { | ||
| inner, | ||
| transition_hash, | ||
| } | ||
| } | ||
|
|
||
| /// Returns the transition hash (transaction ID) as a 32-byte array. | ||
| pub fn transition_hash(&self) -> [u8; 32] { | ||
| self.transition_hash | ||
| } | ||
|
|
||
| /// Consumes this wrapper, returning the inner result and the transition hash. | ||
| pub fn into_parts(self) -> (T, [u8; 32]) { | ||
| (self.inner, self.transition_hash) | ||
| } | ||
|
|
||
| /// Consumes this wrapper, returning just the inner result. | ||
| pub fn into_inner(self) -> T { | ||
| self.inner | ||
| } | ||
|
|
||
| /// Maps the inner value, preserving the transition hash. | ||
| pub fn map<U, F: FnOnce(T) -> U>(self, f: F) -> StateTransitionResult<U> { | ||
| StateTransitionResult { | ||
| inner: f(self.inner), | ||
| transition_hash: self.transition_hash, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl<T> Deref for StateTransitionResult<T> { | ||
| type Target = T; | ||
|
|
||
| fn deref(&self) -> &T { | ||
| &self.inner | ||
| } | ||
| } | ||
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.
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: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 atransition_hashfield 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?