Skip to content
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

[Ts sdk] getNormalizedMoveModulesByPackage doesn't support enums #19538

Open
Sceat opened this issue Sep 25, 2024 · 1 comment
Open

[Ts sdk] getNormalizedMoveModulesByPackage doesn't support enums #19538

Sceat opened this issue Sep 25, 2024 · 1 comment
Assignees

Comments

@Sceat
Copy link
Contributor

Sceat commented Sep 25, 2024

In order to generate bcs types from packages (https://github.com/Sceat/sui-bcs) I'm using getNormalizedMoveModulesByPackage which output any enum as a type.Struct and that fails when using getNormalizedMoveStruct

JsonRpcError: No struct was found with struct name <enum name>

Originally posted by @Sceat in #19512 (comment)

Reproduce

npx sui-bcs gen --package 0xaac2ba277ff9d30fc1ad445a19e59d1e33e3755e5f97e9dc218b709809787686 --file aresrpg-bcs --network testnet
@amnn amnn assigned tzakian and amnn Sep 25, 2024
@amnn
Copy link
Member

amnn commented Sep 25, 2024

Thanks for the report @Sceat -- I've added @tzakian as our enums expert to take a look.

I would also offer a general caution about using the getNormalized* family of JSONRPC methods though, as they are also not upgrade-aware, meaning that you could encounter some strangeness with package IDs as well.

We're still productionising our GraphQL API, so use at your own risk, but it has a much richer set of APIs for querying information about types, and they are both upgrade- and enum-aware.

you can get the full type layout of a fully-instantiated type:

"""
Fetch a structured representation of a concrete type, including its layout information.
Fails if the type is malformed.
"""
type(type: String!): MoveType!

"""
Represents concrete types (no type parameters, no references).
"""
type MoveType {
"""
Flat representation of the type signature, as a displayable string.
"""
repr: String!
"""
Structured representation of the type signature.
"""
signature: MoveTypeSignature!
"""
Structured representation of the "shape" of values that match this type. May return no
layout if the type is invalid.
"""
layout: MoveTypeLayout
"""
The abilities this concrete type has. Returns no abilities if the type is invalid.
"""
abilities: [MoveAbility!]
}
"""
The shape of a concrete Move Type (a type with all its type parameters instantiated with concrete types), corresponding to the following recursive type:
type MoveTypeLayout =
"address"
| "bool"
| "u8" | "u16" | ... | "u256"
| { vector: MoveTypeLayout }
| {
struct: {
type: string,
fields: [{ name: string, layout: MoveTypeLayout }],
}
}
| { enum: [{
type: string,
variants: [{
name: string,
fields: [{ name: string, layout: MoveTypeLayout }],
}]
}]
}
"""
scalar MoveTypeLayout

and you can get information about a specific datatype (struct or enum), going down into its fields etc.

"""
Look-up the definition of a datatype (struct or enum) defined in this module, by its name.
"""
datatype(name: String!): MoveDatatype

"""
Information for a particular field on a Move struct.
"""
type MoveField {
name: String!
type: OpenMoveType
}

"""
Description of a struct type, defined in a Move module.
"""
type MoveStruct implements IMoveDatatype {
"""
The module this struct was originally defined in.
"""
module: MoveModule!
"""
The struct's (unqualified) type name.
"""
name: String!
"""
Abilities this struct has.
"""
abilities: [MoveAbility!]
"""
Constraints on the struct's formal type parameters. Move bytecode does not name type
parameters, so when they are referenced (e.g. in field types) they are identified by their
index in this list.
"""
typeParameters: [MoveStructTypeParameter!]
"""
The names and types of the struct's fields. Field types reference type parameters, by their
index in the defining struct's `typeParameters` list.
"""
fields: [MoveField!]
}

"""
Description of an enum type, defined in a Move module.
"""
type MoveEnum implements IMoveDatatype {
"""
The module this enum was originally defined in.
"""
module: MoveModule!
"""
The enum's (unqualified) type name.
"""
name: String!
"""
The enum's abilities.
"""
abilities: [MoveAbility!]
"""
Constraints on the enum's formal type parameters. Move bytecode does not name type
parameters, so when they are referenced (e.g. in field types) they are identified by their
index in this list.
"""
typeParameters: [MoveStructTypeParameter!]
"""
The names and types of the enum's fields. Field types reference type parameters, by their
index in the defining enum's `typeParameters` list.
"""
variants: [MoveEnumVariant!]
}

type MoveEnumVariant {
"""
The name of the variant
"""
name: String!
"""
The names and types of the variant's fields. Field types reference type parameters, by their
index in the defining enum's `typeParameters` list.
"""
fields: [MoveField!]
}

"""
Represents types that could contain references or free type parameters. Such types can appear
as function parameters, in fields of structs, or as actual type parameter.
"""
type OpenMoveType {
"""
Structured representation of the type signature.
"""
signature: OpenMoveTypeSignature!
"""
Flat representation of the type signature, as a displayable string.
"""
repr: String!
}
"""
The shape of an abstract Move Type (a type that can contain free type parameters, and can optionally be taken by reference), corresponding to the following recursive type:
type OpenMoveTypeSignature = {
ref: ("&" | "&mut")?,
body: OpenMoveTypeSignatureBody,
}
type OpenMoveTypeSignatureBody =
"address"
| "bool"
| "u8" | "u16" | ... | "u256"
| { vector: OpenMoveTypeSignatureBody }
| {
datatype {
package: string,
module: string,
type: string,
typeParameters: [OpenMoveTypeSignatureBody]
}
}
| { typeParameter: number }
"""
scalar OpenMoveTypeSignature

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants