Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 1 addition & 3 deletions crates/iota-graphql-rpc/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -2561,12 +2561,10 @@ type MoveType {
signature: MoveTypeSignature!
"""
Structured representation of the "shape" of values that match this type.
May return MoveTypeLayout::InvalidType for malformed types.
"""
layout: MoveTypeLayout!
"""
The abilities this concrete type has. Returns no abilities if the type
is invalid.
The abilities this concrete type has.
"""
abilities: [MoveAbility!]!
}
Expand Down
2 changes: 1 addition & 1 deletion crates/iota-graphql-rpc/src/types/move_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ impl MoveObjectImpl<'_> {
pub(crate) async fn has_public_transfer(&self, ctx: &Context<'_>) -> Result<bool> {
let type_: MoveType = self.0.native.struct_tag().clone().into();
let set = type_.abilities_impl(ctx.data_unchecked()).await.extend()?;
Ok(set.is_some_and(|s| s.has_key() && s.has_store()))
Ok(set.has_key() && set.has_store())
}
}

Expand Down
50 changes: 20 additions & 30 deletions crates/iota-graphql-rpc/src/types/move_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,31 +144,25 @@ impl MoveType {
}

/// Structured representation of the "shape" of values that match this type.
/// May return MoveTypeLayout::InvalidType for malformed types.
async fn layout(&self, ctx: &Context<'_>) -> Result<MoveTypeLayout> {
let resolver: &PackageResolver = ctx
.data()
.map_err(|_| Error::Internal("Unable to fetch Package Cache.".to_string()))
.extend()?;

let Some(layout) = self.layout_impl(resolver).await.extend()? else {
return Ok(MoveTypeLayout::InvalidType);
};
let layout = self.layout_impl(resolver).await.extend()?;

MoveTypeLayout::try_from(layout).extend()
}

/// The abilities this concrete type has. Returns no abilities if the type
/// is invalid.
/// The abilities this concrete type has.
async fn abilities(&self, ctx: &Context<'_>) -> Result<Vec<MoveAbility>> {
let resolver: &PackageResolver = ctx
.data()
.map_err(|_| Error::Internal("Unable to fetch Package Cache.".to_string()))
.extend()?;

let Some(abilities) = self.abilities_impl(resolver).await.extend()? else {
return Ok(vec![]);
};
let abilities = self.abilities_impl(resolver).await.extend()?;

Ok(abilities.into_iter().map(MoveAbility::from).collect())
}
Expand All @@ -182,32 +176,28 @@ impl MoveType {
pub(crate) async fn layout_impl(
&self,
resolver: &PackageResolver,
) -> Result<Option<A::MoveTypeLayout>, Error> {
Ok(Some(
resolver
.type_layout(self.native.clone())
.await
.map_err(|e| {
Error::Internal(format!(
"Error calculating layout for {}: {e}",
self.native.to_canonical_string(/* with_prefix */ true),
))
})?,
))
) -> Result<A::MoveTypeLayout, Error> {
resolver
.type_layout(self.native.clone())
.await
.map_err(|e| {
Error::Internal(format!(
"Error calculating layout for {}: {e}",
self.native.to_canonical_string(/* with_prefix */ true),
))
})
}

pub(crate) async fn abilities_impl(
&self,
resolver: &PackageResolver,
) -> Result<Option<AbilitySet>, Error> {
Ok(Some(
resolver.abilities(self.native.clone()).await.map_err(|e| {
Error::Internal(format!(
"Error calculating abilities for {}: {e}",
self.native.to_canonical_string(/* with_prefix */ true),
))
})?,
))
) -> Result<AbilitySet, Error> {
resolver.abilities(self.native.clone()).await.map_err(|e| {
Error::Internal(format!(
"Error calculating abilities for {}: {e}",
self.native.to_canonical_string(/* with_prefix */ true),
))
})
}
}

Expand Down
14 changes: 2 additions & 12 deletions crates/iota-graphql-rpc/src/types/move_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,7 @@ impl MoveValue {
.map_err(|_| Error::Internal("Unable to fetch Package Cache.".to_string()))
.extend()?;

let Some(layout) = self.type_.layout_impl(resolver).await.extend()? else {
return Err(Error::Internal(
"Move value must have valid layout".to_string(),
))
.extend();
};
let layout = self.type_.layout_impl(resolver).await.extend()?;

// Factor out into its own non-GraphQL, non-async function for better
// testability
Expand All @@ -143,12 +138,7 @@ impl MoveValue {
.map_err(|_| Error::Internal("Unable to fetch Package Cache.".to_string()))
.extend()?;

let Some(layout) = self.type_.layout_impl(resolver).await.extend()? else {
return Err(Error::Internal(
"Move value must have valid layout".to_string(),
))
.extend();
};
let layout = self.type_.layout_impl(resolver).await.extend()?;

// Factor out into its own non-GraphQL, non-async function for better
// testability
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2565,12 +2565,10 @@ type MoveType {
signature: MoveTypeSignature!
"""
Structured representation of the "shape" of values that match this type.
May return MoveTypeLayout::InvalidType for malformed types.
"""
layout: MoveTypeLayout!
"""
The abilities this concrete type has. Returns no abilities if the type
is invalid.
The abilities this concrete type has.
"""
abilities: [MoveAbility!]!
}
Expand Down
Loading