-
Notifications
You must be signed in to change notification settings - Fork 3
feat(ffi): TypeTag and StructTag #83
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 2 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
15875ce
feat(ffi): TypeTag and StructTag
thibault-martinez e2b64ed
Merge branch 'sdk-bindings' into type-tag-struct-tag
thibault-martinez bc065f8
remove TODOs
thibault-martinez a303b3e
remove duplicate methods
thibault-martinez c16f8f7
remove into_
thibault-martinez a81bba8
vector/struct constructors
thibault-martinez d2f3a8b
remove unused import
thibault-martinez 265ba3d
Add StructTag::new
thibault-martinez dd42fbb
import StructTag
thibault-martinez 9323578
Merge branch 'sdk-bindings' into type-tag-struct-tag
thibault-martinez 62379d0
clippy
thibault-martinez 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,55 @@ | ||
| // Copyright (c) 2025 IOTA Stiftung | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| use std::sync::Arc; | ||
|
|
||
| /// Type information for a move struct | ||
| /// | ||
| /// # BCS | ||
| /// | ||
| /// The BCS serialized form for this type is defined by the following ABNF: | ||
| /// | ||
| /// ```text | ||
| /// struct-tag = address ; address of the package | ||
| /// identifier ; name of the module | ||
| /// identifier ; name of the type | ||
| /// (vector type-tag) ; type parameters | ||
| /// ``` | ||
| #[derive(Clone, Debug, derive_more::From, uniffi::Object)] | ||
| pub struct StructTag(pub iota_types::StructTag); | ||
|
|
||
| #[uniffi::export] | ||
| impl StructTag { | ||
| #[uniffi::constructor] | ||
| pub fn coin(type_tag: &super::type_tag::TypeTag) -> Self { | ||
| Self(iota_types::StructTag::coin(type_tag.0.clone())) | ||
| } | ||
|
|
||
| /// Checks if this is a Coin type | ||
| pub fn coin_type_opt(&self) -> Option<Arc<super::type_tag::TypeTag>> { | ||
| self.0 | ||
| .coin_type_opt() | ||
| .cloned() | ||
| .map(Into::into) | ||
| .map(Arc::new) | ||
| } | ||
|
|
||
| /// Checks if this is a Coin type | ||
| pub fn coin_type(&self) -> super::type_tag::TypeTag { | ||
| self.0.coin_type().clone().into() | ||
| } | ||
|
|
||
| #[uniffi::constructor] | ||
| pub fn gas_coin() -> Self { | ||
| Self(iota_types::StructTag::gas_coin()) | ||
| } | ||
|
|
||
| #[uniffi::constructor] | ||
| pub fn staked_iota() -> Self { | ||
| Self(iota_types::StructTag::staked_iota()) | ||
| } | ||
|
|
||
| pub fn address(&self) -> super::address::Address { | ||
| self.0.address().into() | ||
| } | ||
| } | ||
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 |
|---|---|---|
| @@ -1,5 +1,202 @@ | ||
| // Copyright (c) 2025 IOTA Stiftung | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| use std::sync::Arc; | ||
|
|
||
| /// Type of a move value | ||
| /// | ||
| /// # BCS | ||
| /// | ||
| /// The BCS serialized form for this type is defined by the following ABNF: | ||
| /// | ||
| /// ```text | ||
| /// type-tag = type-tag-u8 \ | ||
| /// type-tag-u16 \ | ||
| /// type-tag-u32 \ | ||
| /// type-tag-u64 \ | ||
| /// type-tag-u128 \ | ||
| /// type-tag-u256 \ | ||
| /// type-tag-bool \ | ||
| /// type-tag-address \ | ||
| /// type-tag-signer \ | ||
| /// type-tag-vector \ | ||
| /// type-tag-struct | ||
| /// | ||
| /// type-tag-u8 = %x01 | ||
| /// type-tag-u16 = %x08 | ||
| /// type-tag-u32 = %x09 | ||
| /// type-tag-u64 = %x02 | ||
| /// type-tag-u128 = %x03 | ||
| /// type-tag-u256 = %x0a | ||
| /// type-tag-bool = %x00 | ||
| /// type-tag-address = %x04 | ||
| /// type-tag-signer = %x05 | ||
| /// type-tag-vector = %x06 type-tag | ||
| /// type-tag-struct = %x07 struct-tag | ||
| /// ``` | ||
| #[derive(Clone, Debug, derive_more::From, uniffi::Object)] | ||
| pub struct TypeTag(pub iota_types::TypeTag); | ||
|
|
||
| #[uniffi::export] | ||
| impl TypeTag { | ||
| #[inline] | ||
| pub fn is_u8(&self) -> bool { | ||
| self.0.is_u8() | ||
| } | ||
|
|
||
| #[inline] | ||
| pub fn is_u16(&self) -> bool { | ||
| self.0.is_u16() | ||
| } | ||
|
|
||
| #[inline] | ||
| pub fn is_u32(&self) -> bool { | ||
| self.0.is_u32() | ||
| } | ||
|
|
||
| #[inline] | ||
| pub fn is_u64(&self) -> bool { | ||
| self.0.is_u64() | ||
| } | ||
|
|
||
| #[inline] | ||
| pub fn is_u128(&self) -> bool { | ||
| self.0.is_u128() | ||
| } | ||
|
|
||
| #[inline] | ||
| pub fn is_u256(&self) -> bool { | ||
| self.0.is_u256() | ||
| } | ||
|
|
||
| #[inline] | ||
| pub fn is_bool(&self) -> bool { | ||
| self.0.is_bool() | ||
| } | ||
|
|
||
| #[inline] | ||
| pub fn is_address(&self) -> bool { | ||
| self.0.is_address() | ||
| } | ||
|
|
||
| #[inline] | ||
| pub fn is_signer(&self) -> bool { | ||
| self.0.is_signer() | ||
| } | ||
|
|
||
| #[inline] | ||
| pub fn is_vector(&self) -> bool { | ||
| self.0.is_vector() | ||
| } | ||
|
|
||
| #[inline] | ||
| pub fn as_vector_type_tag_opt(&self) -> Option<Arc<TypeTag>> { | ||
| self.0 | ||
| .as_vector_type_tag_opt() | ||
| .cloned() | ||
| .map(Into::into) | ||
| .map(Arc::new) | ||
| } | ||
|
|
||
| #[inline] | ||
| pub fn as_vector_type_tag(&self) -> TypeTag { | ||
| self.0.as_vector_type_tag().clone().into() | ||
| } | ||
|
|
||
| // TODO cannot take self? | ||
Thoralf-M marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| #[inline] | ||
| pub fn into_vector_type_tag_opt(&self) -> Option<Arc<TypeTag>> { | ||
DaughterOfMars marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| self.clone() | ||
| .0 | ||
| .into_vector_type_tag_opt() | ||
| .map(Into::into) | ||
| .map(Arc::new) | ||
| } | ||
|
|
||
| // TODO cannot take self? | ||
| #[inline] | ||
| pub fn into_vector_type_tag(&self) -> TypeTag { | ||
DaughterOfMars marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| self.clone().0.into_vector_type_tag().into() | ||
| } | ||
|
|
||
| #[inline] | ||
| pub fn is_struct(&self) -> bool { | ||
| self.0.is_struct() | ||
| } | ||
|
|
||
| #[inline] | ||
| pub fn as_struct_tag_opt(&self) -> Option<Arc<super::struct_tag::StructTag>> { | ||
| self.0 | ||
| .as_struct_tag_opt() | ||
| .cloned() | ||
| .map(Into::into) | ||
| .map(Arc::new) | ||
| } | ||
|
|
||
| #[inline] | ||
| pub fn as_struct_tag(&self) -> super::struct_tag::StructTag { | ||
| self.0.as_struct_tag().clone().into() | ||
| } | ||
|
|
||
| // TODO cannot take self? | ||
| #[inline] | ||
| pub fn into_struct_tag_opt(&self) -> Option<Arc<super::struct_tag::StructTag>> { | ||
| self.clone() | ||
| .0 | ||
| .into_struct_tag_opt() | ||
| .clone() | ||
| .map(Into::into) | ||
| .map(Arc::new) | ||
| } | ||
|
|
||
| // TODO cannot take self? | ||
| #[inline] | ||
| pub fn into_struct_tag(&self) -> super::struct_tag::StructTag { | ||
| self.clone().0.into_struct_tag().into() | ||
| } | ||
|
|
||
| #[uniffi::constructor] | ||
| pub fn u8() -> Self { | ||
| Self(iota_types::TypeTag::U8) | ||
| } | ||
|
|
||
| #[uniffi::constructor] | ||
| pub fn u16() -> Self { | ||
| Self(iota_types::TypeTag::U16) | ||
| } | ||
|
|
||
| #[uniffi::constructor] | ||
| pub fn u32() -> Self { | ||
| Self(iota_types::TypeTag::U32) | ||
| } | ||
|
|
||
| #[uniffi::constructor] | ||
| pub fn u64() -> Self { | ||
| Self(iota_types::TypeTag::U64) | ||
| } | ||
|
|
||
| #[uniffi::constructor] | ||
| pub fn u128() -> Self { | ||
| Self(iota_types::TypeTag::U128) | ||
| } | ||
|
|
||
| #[uniffi::constructor] | ||
| pub fn u256() -> Self { | ||
| Self(iota_types::TypeTag::U256) | ||
| } | ||
|
|
||
| #[uniffi::constructor] | ||
| pub fn bool() -> Self { | ||
| Self(iota_types::TypeTag::Bool) | ||
| } | ||
|
|
||
| #[uniffi::constructor] | ||
| pub fn address() -> Self { | ||
| Self(iota_types::TypeTag::Address) | ||
| } | ||
|
|
||
| #[uniffi::constructor] | ||
| pub fn signer() -> Self { | ||
DaughterOfMars marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Self(iota_types::TypeTag::Signer) | ||
| } | ||
Thoralf-M marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
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
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.