-
Notifications
You must be signed in to change notification settings - Fork 1
feat(general): Small assorted improvements #183
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
Merged
Merged
Changes from 17 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
6eb47b4
Add the purpose getter function to Cip509
stanislav-tkach b477fd5
Implement SerializeValue and DeserializeValue for UUIDs
stanislav-tkach 9383106
Merge branch 'main' into cip509-purpose-getter
stanislav-tkach 4fa68e7
Export Cip509RbacMetadata type
stanislav-tkach 5fb0602
Merge remote-tracking branch 'origin/cip509-purpose-getter' into cip5…
stanislav-tkach 35b42e5
Implement SerializeValue and DeserializeValue for Blake2bHash
stanislav-tkach 26d8a74
Fix Clippy
stanislav-tkach 84a3e02
Merge branch 'main' into cip509-purpose-getter
stanislav-tkach 328733c
Add TransactionHash and PubKeyHash types
stanislav-tkach 33ba72a
Merge remote-tracking branch 'origin/cip509-purpose-getter' into cip5…
stanislav-tkach 4f7cae2
Merge branch 'main' into cip509-purpose-getter
stanislav-tkach 6c26210
Fix spellcheck
stanislav-tkach d74e1bb
Merge remote-tracking branch 'origin/cip509-purpose-getter' into cip5…
stanislav-tkach d0f4924
Fix spellcheck 2
stanislav-tkach 344f3dc
Remove unused dependencies
stanislav-tkach 5ed07ab
Document the macro
stanislav-tkach b697f71
Use 'meta' instead of 'tt' for docs
stanislav-tkach eab11ac
Remove cspell exception
stanislav-tkach c853ce7
Remove -scylla dependency
stanislav-tkach 20c169d
Merge branch 'main' into cip509-purpose-getter
stanislav-tkach 3629032
Move define_hashes to catalyst-types
stanislav-tkach b6bed0e
Remove import
stanislav-tkach 0b832b3
cleanup
stanislav-tkach 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| //! A bunch of specific hashes. | ||
| // cspell: words attrss | ||
|
|
||
| use std::str::FromStr; | ||
|
|
||
| use catalyst_types::hashes::{Blake2b224Hash, Blake2b256Hash, Blake2bHashError}; | ||
| use pallas_crypto::hash::Hash; | ||
|
|
||
| /// Defines a new type wrapper for the given hash type. | ||
| macro_rules! define_hashes { | ||
stanislav-tkach marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ($($(#[$docs:meta])* ($name:ident, $inner:ty)),+) => { | ||
| $( | ||
| $(#[$docs])* | ||
| #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] | ||
| pub struct $name($inner); | ||
|
|
||
| impl $name { | ||
| /// Creates a new instance from the given bytes by hashing them. | ||
| #[must_use] | ||
| pub fn new(input_bytes: &[u8]) -> Self { | ||
| Self(<$inner>::new(input_bytes)) | ||
| } | ||
| } | ||
|
|
||
| impl From<$name> for Vec<u8> { | ||
| fn from(value: $name) -> Self { | ||
| value.0.into() | ||
| } | ||
| } | ||
|
|
||
| impl From<$inner> for $name { | ||
| fn from(value: $inner) -> Self { | ||
| Self(value) | ||
| } | ||
| } | ||
|
|
||
| impl TryFrom<&[u8]> for $name { | ||
| type Error = Blake2bHashError; | ||
|
|
||
| fn try_from(value: &[u8]) -> Result<Self, Self::Error> { | ||
| Ok(Self(<$inner>::try_from(value)?)) | ||
| } | ||
| } | ||
|
|
||
| impl TryFrom<Vec<u8>> for $name { | ||
| type Error = Blake2bHashError; | ||
|
|
||
| fn try_from(value: Vec<u8>) -> Result<Self, Self::Error> { | ||
| value.as_slice().try_into() | ||
| } | ||
| } | ||
|
|
||
| impl FromStr for $name { | ||
| type Err = Blake2bHashError; | ||
|
|
||
| fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
| let hash: $inner = s.parse().map_err(Blake2bHashError::from)?; | ||
| Ok(Self(hash)) | ||
| } | ||
| } | ||
|
|
||
| impl<C> minicbor::Encode<C> for $name { | ||
| fn encode<W: minicbor::encode::Write>( | ||
| &self, e: &mut minicbor::Encoder<W>, ctx: &mut C, | ||
| ) -> Result<(), minicbor::encode::Error<W::Error>> { | ||
| self.0.encode(e, ctx) | ||
| } | ||
| } | ||
|
|
||
| impl<'a, C> minicbor::Decode<'a, C> for $name { | ||
| fn decode( | ||
| d: &mut minicbor::Decoder<'a>, ctx: &mut C, | ||
| ) -> Result<Self, minicbor::decode::Error> { | ||
| let hash = <$inner>::decode(d, ctx)?; | ||
| Ok(Self(hash)) | ||
| } | ||
| } | ||
|
|
||
| // TODO: Uncomment when the changes to Blake2bHash are merged. | ||
| // impl SerializeValue for $name { | ||
| // fn serialize<'b>( | ||
| // &self, typ: &ColumnType, writer: CellWriter<'b>, | ||
| // ) -> Result<WrittenCellProof<'b>, SerializationError> { | ||
| // self.0.serialize(typ, writer) | ||
| // } | ||
| // } | ||
| // | ||
| // impl<'frame, 'metadata> DeserializeValue<'frame, 'metadata> for $name | ||
| // { | ||
| // fn type_check(typ: &ColumnType) -> Result<(), TypeCheckError> { | ||
| // <$inner>::type_check(typ) | ||
| // } | ||
| // | ||
| // fn deserialize( | ||
| // typ: &'metadata ColumnType<'metadata>, v: Option<FrameSlice<'frame>>, | ||
| // ) -> Result<Self, DeserializationError> { | ||
| // let hash = <$inner>::deserialize(typ, v)?; | ||
| // Ok(Self(hash)) | ||
| // } | ||
| // } | ||
| )+ | ||
| }; | ||
| } | ||
|
|
||
| define_hashes!( | ||
| /// A transaction hash - Blake2b-256 hash of a transaction. | ||
| (TransactionHash, Blake2b256Hash), | ||
| /// A public key hash - raw Blake2b-224 hash of an Ed25519 public key (has no discriminator, just the hash). | ||
| (PubKeyHash, Blake2b224Hash) | ||
| ); | ||
|
|
||
| impl From<Hash<32>> for TransactionHash { | ||
| fn from(hash: Hash<32>) -> Self { | ||
| Self(Blake2b256Hash::from(hash)) | ||
| } | ||
| } | ||
|
|
||
| impl From<Hash<28>> for PubKeyHash { | ||
| fn from(hash: Hash<28>) -> Self { | ||
| Self(Blake2b224Hash::from(hash)) | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
| // There is little reason to check the conversion itself, it is mostly a demonstration | ||
| // that the methods defined by the macro are working. | ||
| #[test] | ||
| fn roundtrip() { | ||
| let hash = TransactionHash::new(&[]); | ||
|
|
||
| let v = Vec::from(hash); | ||
| let from_slice = TransactionHash::try_from(v.as_slice()).unwrap(); | ||
| assert_eq!(hash, from_slice); | ||
|
|
||
| let from_vec = TransactionHash::try_from(v).unwrap(); | ||
| assert_eq!(hash, from_vec); | ||
| } | ||
| } | ||
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
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.