Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
480 changes: 461 additions & 19 deletions bindings/go/iota_sdk_ffi/iota_sdk_ffi.go

Large diffs are not rendered by default.

373 changes: 349 additions & 24 deletions bindings/go/iota_sdk_ffi/iota_sdk_ffi.h

Large diffs are not rendered by default.

608 changes: 588 additions & 20 deletions bindings/kotlin/lib/iota_sdk/iota_sdk_ffi.kt

Large diffs are not rendered by default.

558 changes: 530 additions & 28 deletions bindings/python/lib/iota_sdk_ffi.py

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions crates/iota-graphql-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ impl Client {
type_: Some(
coin_type
.into()
.map(StructTag::coin)
.map(StructTag::new_coin)
.unwrap_or_else(|| StructTag {
address: Address::FRAMEWORK,
module: IdentifierRef::const_new("coin").into(),
Expand Down Expand Up @@ -668,7 +668,7 @@ impl Client {
owner: Address,
pagination_filter: PaginationFilter,
) -> Result<Page<Coin>> {
self.coins(owner, StructTag::iota(), pagination_filter)
self.coins(owner, StructTag::new_iota_coin_name(), pagination_filter)
.await
}

Expand Down
98 changes: 88 additions & 10 deletions crates/iota-sdk-ffi/src/types/struct_tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,42 @@ impl Identifier {
}
}

macro_rules! export_struct_tag_ctors {
($($name:ident),+ $(,)?) => { paste::paste! {
#[uniffi::export]
impl StructTag {$(
#[uniffi::constructor]
pub fn [< new_ $name:snake >]() -> Self {
Self(iota_types::StructTag::[< new_ $name:snake >]())
}
)+}
} }
}

macro_rules! export_struct_tag_from_type_tag_ctors {
($($name:ident),+ $(,)?) => { paste::paste! {
#[uniffi::export]
impl StructTag {$(
#[uniffi::constructor]
pub fn [< new_ $name:snake >](type_tag: &TypeTag) -> Self {
Self(iota_types::StructTag::[< new_ $name:snake >](type_tag.0.clone()))
}
)+}
} }
}

macro_rules! export_struct_tag_from_struct_tag_ctors {
($($name:ident),+ $(,)?) => { paste::paste! {
#[uniffi::export]
impl StructTag {$(
#[uniffi::constructor]
pub fn [< new_ $name:snake >](struct_tag: &StructTag) -> Self {
Self(iota_types::StructTag::[< new_ $name:snake >](struct_tag.0.clone()))
}
)+}
} }
}

/// Type information for a move struct
///
/// # BCS
Expand Down Expand Up @@ -74,8 +110,8 @@ impl StructTag {
}

#[uniffi::constructor]
pub fn coin(type_tag: &TypeTag) -> Self {
Self(iota_types::StructTag::coin(type_tag.0.clone()))
pub fn new_name(address: &Address) -> Self {
Self(iota_types::StructTag::new_name(address.0))
}

/// Checks if this is a Coin type
Expand All @@ -92,19 +128,61 @@ impl StructTag {
self.0.coin_type().clone().into()
}

#[uniffi::constructor]
pub fn gas_coin() -> Self {
Self(iota_types::StructTag::gas_coin())
/// Returns the address part of a `StructTag`
pub fn address(&self) -> Address {
self.0.address().into()
}

#[uniffi::constructor]
pub fn staked_iota() -> Self {
Self(iota_types::StructTag::staked_iota())
/// Returns the module part of a `StructTag`
pub fn module(&self) -> Identifier {
self.0.module().clone().into()
}

pub fn address(&self) -> Address {
self.0.address().into()
/// Returns the name part of a `StructTag`
pub fn name(&self) -> Identifier {
self.0.name().clone().into()
}

/// Returns the type params part of a `StructTag`
pub fn type_args(&self) -> Vec<Arc<TypeTag>> {
self.0
.type_params()
.iter()
.cloned()
.map(TypeTag::from)
.map(Arc::new)
.collect()
}
}

export_struct_tag_ctors!(
AddressKey,
AsciiString,
Clock,
Config,
ConfigKey,
GasCoin,
GlobalPauseKey,
Id,
IotaCoinName,
IotaSystemAdminCap,
IotaSystemState,
IotaTreasuryCap,
UpgradeCap,
UpgradeTicket,
UpgradeReceipt,
StakedIota,
String,
TimelockedStakedIota,
Uid,
);
export_struct_tag_from_type_tag_ctors!(Balance, Coin, TimeLock);
export_struct_tag_from_struct_tag_ctors!(
CoinManager,
CoinMetadata,
DisplayCreated,
TreasuryCap,
VersionUpdated,
);

crate::export_iota_types_objects_bcs_conversion!(Identifier, StructTag);
6 changes: 3 additions & 3 deletions crates/iota-sdk-types/src/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -597,9 +597,9 @@ mod serialization {
fn into_struct_tag(self) -> StructTag {
match self {
MoveStructType::Other(tag) => tag,
MoveStructType::GasCoin => StructTag::gas_coin(),
MoveStructType::StakedIota => StructTag::staked_iota(),
MoveStructType::Coin(type_tag) => StructTag::coin(type_tag),
MoveStructType::GasCoin => StructTag::new_gas_coin(),
MoveStructType::StakedIota => StructTag::new_staked_iota(),
MoveStructType::Coin(type_tag) => StructTag::new_coin(type_tag),
}
}
}
Expand Down
189 changes: 156 additions & 33 deletions crates/iota-sdk-types/src/type_tag/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,9 @@ impl IdentifierRef {
// already guarantees the transmute is safe (RefCast checks that
// IdentStr(str) is #[repr(transparent)]).
// (3) both in and out lifetimes are 'static, so we're not widening the
// lifetime. (4) we've just asserted that the IdentStr passes the
// is_valid check.
// lifetime.
// (4) we've just asserted that the IdentStr passes the
// is_valid check.
unsafe { std::mem::transmute::<&'static str, &'static Self>(s) }
}

Expand Down Expand Up @@ -379,6 +380,87 @@ impl ToOwned for IdentifierRef {
}
}

macro_rules! add_struct_tag_ctor {
($address:ident, $module:literal, $name:literal) => {
paste::paste! {
pub fn [< new_ $name:snake >]() -> Self {
Self {
address: Address::$address,
module: IdentifierRef::const_new($module).into(),
name: IdentifierRef::const_new($name).into(),
type_params: vec![],
}
}
}
};
($address:ident, $module:literal, $name:literal, "with-module") => {
paste::paste! {
pub fn [< new_ $module:snake _ $name:snake >]() -> Self {
Self {
address: Address::$address,
module: IdentifierRef::const_new($module).into(),
name: IdentifierRef::const_new($name).into(),
type_params: vec![],
}
}
}
};
}

macro_rules! add_struct_tag_ctor_from_struct_tag {
($address:ident, $module:literal, $name:literal) => {
paste::paste! {
pub fn [< new_ $name:snake >](struct_tag: impl Into<StructTag>) -> Self {
Self {
address: Address::$address,
module: IdentifierRef::const_new($module).into(),
name: IdentifierRef::const_new($name).into(),
type_params: vec![TypeTag::Struct(Box::new(struct_tag.into()))],
}
}
}
};
($address:ident, $module:literal, $name:literal, "with-module") => {
paste::paste! {
pub fn [< new_ $module:snake _ $name:snake >](struct_tag: impl Into<StructTag>) -> Self {
Self {
address: Address::$address,
module: IdentifierRef::const_new($module).into(),
name: IdentifierRef::const_new($name).into(),
type_params: vec![TypeTag::Struct(Box::new(struct_tag.into()))],
}
}
}
};
}

macro_rules! add_struct_tag_ctor_from_type_tag {
($address:ident, $module:literal, $name:literal) => {
paste::paste! {
pub fn [< new_ $name:snake >](type_tag: impl Into<TypeTag>) -> Self {
Self {
address: Address::$address,
module: IdentifierRef::const_new($module).into(),
name: IdentifierRef::const_new($name).into(),
type_params: vec![type_tag.into()],
}
}
}
};
($address:ident, $module:literal, $name:literal, "with-module") => {
paste::paste! {
pub fn [< new_ $module:snake _ $name:snake >](type_tag: impl Into<TypeTag>) -> Self {
Self {
address: Address::$address,
module: IdentifierRef::const_new($module).into(),
name: IdentifierRef::const_new($name).into(),
type_params: vec![type_tag.into()],
}
}
}
};
}

/// Type information for a move struct
///
/// # BCS
Expand All @@ -402,15 +484,71 @@ pub struct StructTag {
}

impl StructTag {
pub fn coin(type_tag: impl Into<TypeTag>) -> Self {
pub fn new_iota_coin_name() -> Self {
Self {
address: Address::FRAMEWORK,
module: IdentifierRef::const_new("iota").into(),
name: IdentifierRef::const_new("IOTA").into(),
type_params: vec![],
}
}

pub fn new_gas_coin() -> Self {
Self::new_coin(Self::new_iota_coin_name())
}

pub fn new_id() -> Self {
Self {
address: Address::FRAMEWORK,
module: IdentifierRef::const_new("coin").into(),
name: IdentifierRef::const_new("Coin").into(),
type_params: vec![type_tag.into()],
module: IdentifierRef::const_new("object").into(),
name: IdentifierRef::const_new("ID").into(),
type_params: vec![],
}
}

pub fn new_uid() -> Self {
Self {
address: Address::FRAMEWORK,
module: IdentifierRef::const_new("object").into(),
name: IdentifierRef::const_new("UID").into(),
type_params: vec![],
}
}

pub fn new_name(address: Address) -> Self {
Self {
address,
module: IdentifierRef::const_new("name").into(),
name: IdentifierRef::const_new("Name").into(),
type_params: vec![],
}
}

add_struct_tag_ctor!(FRAMEWORK, "clock", "Clock");
add_struct_tag_ctor!(FRAMEWORK, "config", "Config");
add_struct_tag_ctor!(FRAMEWORK, "deny_list", "ConfigKey");
add_struct_tag_ctor!(FRAMEWORK, "deny_list", "AddressKey");
add_struct_tag_ctor!(FRAMEWORK, "deny_list", "GlobalPauseKey");
add_struct_tag_ctor!(FRAMEWORK, "iota", "IotaTreasuryCap");
add_struct_tag_ctor!(FRAMEWORK, "package", "UpgradeCap");
add_struct_tag_ctor!(FRAMEWORK, "package", "UpgradeTicket");
add_struct_tag_ctor!(FRAMEWORK, "package", "UpgradeReceipt");
add_struct_tag_ctor!(FRAMEWORK, "system_admin_cap", "IotaSystemAdminCap");
add_struct_tag_ctor!(SYSTEM, "iota_system", "IotaSystemState");
add_struct_tag_ctor!(SYSTEM, "staking_pool", "StakedIota");
add_struct_tag_ctor!(SYSTEM, "timelocked_staking", "TimelockedStakedIota");
add_struct_tag_ctor!(STD_LIB, "ascii", "String", "with-module");
add_struct_tag_ctor!(STD_LIB, "string", "String");
add_struct_tag_ctor_from_struct_tag!(FRAMEWORK, "coin", "CoinMetadata");
add_struct_tag_ctor_from_struct_tag!(FRAMEWORK, "coin", "TreasuryCap");
add_struct_tag_ctor_from_struct_tag!(FRAMEWORK, "coin_manager", "CoinManager");
add_struct_tag_ctor_from_struct_tag!(FRAMEWORK, "display", "VersionUpdated");
add_struct_tag_ctor_from_struct_tag!(FRAMEWORK, "display", "DisplayCreated");
add_struct_tag_ctor_from_type_tag!(FRAMEWORK, "coin", "Coin");
add_struct_tag_ctor_from_type_tag!(FRAMEWORK, "balance", "Balance");
add_struct_tag_ctor_from_type_tag!(FRAMEWORK, "timelock", "TimeLock");
add_struct_tag_ctor_from_type_tag!(FRAMEWORK, "config", "Setting");

/// Checks if this is a Coin type
pub fn coin_type_opt(&self) -> Option<&crate::TypeTag> {
let Self {
Expand All @@ -436,39 +574,24 @@ impl StructTag {
self.coin_type_opt().expect("not a coin")
}

pub fn iota() -> Self {
Self {
address: Address::FRAMEWORK,
module: IdentifierRef::const_new("iota").into(),
name: IdentifierRef::const_new("IOTA").into(),
type_params: vec![],
}
}

pub fn gas_coin() -> Self {
Self::coin(Self::iota())
/// Returns the address part of a `StructTag`
pub fn address(&self) -> Address {
self.address
}

pub fn staked_iota() -> Self {
Self {
address: Address::SYSTEM,
module: IdentifierRef::const_new("staking_pool").into(),
name: IdentifierRef::const_new("StakedIota").into(),
type_params: vec![],
}
/// Returns the module part of a `StructTag`
pub fn module(&self) -> &Identifier {
&self.module
}

pub fn timelocked_staked_iota() -> Self {
Self {
address: Address::SYSTEM,
module: IdentifierRef::const_new("timelocked_staking").into(),
name: IdentifierRef::const_new("TimelockedStakedIota").into(),
type_params: vec![],
}
/// Returns the name part of a `StructTag`
pub fn name(&self) -> &Identifier {
&self.name
}

pub fn address(&self) -> Address {
self.address
/// Returns the type params part of a `StructTag`
pub fn type_params(&self) -> &[TypeTag] {
&self.type_params
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/iota-transaction-builder/src/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,7 @@ impl<L> TransactionBuilder<Client, L> {
.client
.objects(
ObjectFilter {
type_: Some(StructTag::gas_coin().to_string()),
type_: Some(StructTag::new_gas_coin().to_string()),
owner: Some(self.data.sender),
..Default::default()
},
Expand Down
Loading