MystenLabs / sui

Sui, a next-generation smart contract platform with high throughput, low latency, and an asset-oriented programming model powered by the Move programming language
https://sui.io
Apache License 2.0
6.2k stars 11.2k forks source link

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

Open Sceat opened 1 month ago

Sceat commented 1 month ago

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 https://github.com/MystenLabs/sui/issues/19512#issuecomment-2373052109

Reproduce

npx sui-bcs gen --package 0xaac2ba277ff9d30fc1ad445a19e59d1e33e3755e5f97e9dc218b709809787686 --file aresrpg-bcs --network testnet
amnn commented 1 month ago

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:

https://github.com/MystenLabs/sui/blob/63fa5c0079ceb5191bbf4eb47a63da5b83ecbb65/crates/sui-graphql-rpc/schema.graphql#L3284-L3288

https://github.com/MystenLabs/sui/blob/63fa5c0079ceb5191bbf4eb47a63da5b83ecbb65/crates/sui-graphql-rpc/schema.graphql#L2487-L2533

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

https://github.com/MystenLabs/sui/blob/63fa5c0079ceb5191bbf4eb47a63da5b83ecbb65/crates/sui-graphql-rpc/schema.graphql#L1967-L1970

https://github.com/MystenLabs/sui/blob/63fa5c0079ceb5191bbf4eb47a63da5b83ecbb65/crates/sui-graphql-rpc/schema.graphql#L1849-L1855

https://github.com/MystenLabs/sui/blob/63fa5c0079ceb5191bbf4eb47a63da5b83ecbb65/crates/sui-graphql-rpc/schema.graphql#L2424-L2451

https://github.com/MystenLabs/sui/blob/63fa5c0079ceb5191bbf4eb47a63da5b83ecbb65/crates/sui-graphql-rpc/schema.graphql#L1779-L1806

https://github.com/MystenLabs/sui/blob/63fa5c0079ceb5191bbf4eb47a63da5b83ecbb65/crates/sui-graphql-rpc/schema.graphql#L1837-L1847

https://github.com/MystenLabs/sui/blob/63fa5c0079ceb5191bbf4eb47a63da5b83ecbb65/crates/sui-graphql-rpc/schema.graphql#L2921-L2959