-
Notifications
You must be signed in to change notification settings - Fork 53
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
Draft
thepastaclaw
wants to merge
4
commits into
dashpay:v3.1-dev
Choose a base branch
from
thepastaclaw:feat/sdk-transition-hash
base: v3.1-dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
493f306
feat(rs-sdk): expose transition hash from broadcast_and_wait
thepastaclaw 133e9b6
fix: correct module ordering and update wasm-sdk for StateTransitionR…
thepastaclaw cb08e5e
fix(wasm-sdk): only unwrap StateTransitionResult for broadcast_and_wait
thepastaclaw ffa5609
test(wasm-sdk): cover transition hash wrapper follow-up
thepastaclaw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
packages/rs-sdk/src/platform/transition/state_transition_result.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| use std::ops::Deref; | ||
|
thepastaclaw marked this conversation as resolved.
|
||
|
|
||
| /// 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> { | ||
|
thepastaclaw marked this conversation as resolved.
|
||
| inner: T, | ||
| transition_hash: [u8; 32], | ||
|
thepastaclaw marked this conversation as resolved.
|
||
| } | ||
|
|
||
| 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 | ||
| } | ||
| } | ||
|
thepastaclaw marked this conversation as resolved.
thepastaclaw marked this conversation as resolved.
|
||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::StateTransitionResult; | ||
|
|
||
| fn sample_hash() -> [u8; 32] { | ||
| [7; 32] | ||
| } | ||
|
|
||
| #[test] | ||
| fn new_exposes_transition_hash() { | ||
| let result = StateTransitionResult::new("value", sample_hash()); | ||
|
|
||
| assert_eq!(result.transition_hash(), sample_hash()); | ||
| } | ||
|
|
||
| #[test] | ||
| fn into_parts_returns_inner_and_hash() { | ||
| let result = StateTransitionResult::new(42_u8, sample_hash()); | ||
|
|
||
| assert_eq!(result.into_parts(), (42_u8, sample_hash())); | ||
| } | ||
|
|
||
| #[test] | ||
| fn into_inner_returns_inner_value() { | ||
| let result = StateTransitionResult::new(String::from("value"), sample_hash()); | ||
|
|
||
| assert_eq!(result.into_inner(), "value"); | ||
| } | ||
|
|
||
| #[test] | ||
| fn map_preserves_transition_hash() { | ||
| let result = StateTransitionResult::new(21_u8, sample_hash()); | ||
|
|
||
| let mapped = result.map(|value| value * 2); | ||
|
|
||
| assert_eq!(mapped.into_parts(), (42_u8, sample_hash())); | ||
| } | ||
|
|
||
| #[test] | ||
| fn deref_exposes_inner_value() { | ||
| let result = StateTransitionResult::new(vec![1_u8, 2, 3], sample_hash()); | ||
|
|
||
| assert_eq!(result.len(), 3); | ||
| assert_eq!(result[1], 2); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.