Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
390 changes: 371 additions & 19 deletions bindings/go/iota_sdk_ffi/iota_sdk_ffi.go

Large diffs are not rendered by default.

302 changes: 278 additions & 24 deletions bindings/go/iota_sdk_ffi/iota_sdk_ffi.h

Large diffs are not rendered by default.

494 changes: 474 additions & 20 deletions bindings/kotlin/lib/iota_sdk/iota_sdk_ffi.kt

Large diffs are not rendered by default.

464 changes: 436 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(), pagination_filter)
.await
}

Expand Down
96 changes: 83 additions & 13 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 @@ -73,11 +109,6 @@ impl StructTag {
})
}

#[uniffi::constructor]
pub fn coin(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<TypeTag>> {
self.0
Expand All @@ -92,17 +123,56 @@ 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!(
GasCoin,
Clock,
Config,
ConfigKey,
AddressKey,
GlobalPauseKey,
IotaTreasuryCap,
UpgradeCap,
UpgradeTicket,
UpgradeReceipt,
IotaSystemAdminCap,
IotaSystemState,
StakedIota,
TimelockedStakedIota
);

export_struct_tag_from_type_tag_ctors!(Coin, Balance, TimeLock);

export_struct_tag_from_struct_tag_ctors!(
CoinMetadata,
TreasuryCap,
CoinManager,
VersionUpdated,
DisplayCreated
);
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
144 changes: 111 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,45 @@ 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, "from_struct_tag") => {
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, "from_type_tag") => {
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()],
}
}
}
};
}

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

impl StructTag {
pub fn coin(type_tag: impl Into<TypeTag>) -> Self {
pub fn new_iota() -> 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("iota").into(),
name: IdentifierRef::const_new("IOTA").into(),
type_params: vec![],
}
}

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

pub fn new_id() -> Self {
Self {
address: Address::FRAMEWORK,
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, "coin", "Coin", "from_type_tag");
add_struct_tag_ctor!(FRAMEWORK, "coin", "CoinMetadata", "from_struct_tag");
add_struct_tag_ctor!(FRAMEWORK, "coin", "TreasuryCap", "from_struct_tag");
add_struct_tag_ctor!(FRAMEWORK, "coin_manager", "CoinManager", "from_struct_tag");
add_struct_tag_ctor!(FRAMEWORK, "clock", "Clock");
add_struct_tag_ctor!(FRAMEWORK, "balance", "Balance", "from_type_tag");
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, "display", "VersionUpdated", "from_struct_tag");
add_struct_tag_ctor!(FRAMEWORK, "display", "DisplayCreated", "from_struct_tag");
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!(FRAMEWORK, "timelock", "TimeLock", "from_type_tag");
add_struct_tag_ctor!(SYSTEM, "iota_system", "IotaSystemState");
add_struct_tag_ctor!(SYSTEM, "staking_pool", "StakedIota");
add_struct_tag_ctor!(SYSTEM, "timelocked_staking", "TimelockedStakedIota");

/// Checks if this is a Coin type
pub fn coin_type_opt(&self) -> Option<&crate::TypeTag> {
let Self {
Expand All @@ -436,39 +529,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 @@ -712,7 +712,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