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

SDK swallows enum variant when fetching object with SuiClient::get_object_with_options #19340

Open
porkbrain opened this issue Sep 12, 2024 · 0 comments
Assignees
Labels
cli Command line tools rust-sdk

Comments

@porkbrain
Copy link
Contributor

porkbrain commented Sep 12, 2024

  • Use SDK and CLI from tag "testnet-1.33.0"
  • Start a local network
  • Have the following object in your Move package:
    public struct Foo has key {
        id: UID,
        inner: VecMap<String, Bar>,
    }

    public enum Bar has store {
        A(ID),
        B(ID),
    }
  • Fetch that Move object with Sui SDK
let object_resp = sui.read_api()
            .get_object_with_options(
                your_object_id,
                SuiObjectDataOptions {
                    show_content: true,
                    ..Default::default()
                },
            )
            .await
            .unwrap();

let json = object_resp.data
            .unwrap_or_else(|| panic!("No data found for Foo at {your_object_id}"))
            .content
            .unwrap_or_else(|| panic!("No content found for Foo at {your_object_id}"))
            .try_into_move()
            .map(|SuiParsedMoveObject { fields, .. }| dbg!(fields).to_json_value())
            .unwrap_or_else(|| panic!("Foo at {your_object_id} is not a Move object"));

I would expect to see which variant of Bar was used. When I open my local explorer provided by Suibase, I can actually see the variant there.

The SDK swallows the variant parameter. While I can see "pos0" representing Bar::A or Bar::B positional argument, the actual variant is not present. I get something like:

{
  "key": String("text"),
  "value": Struct(WithTypes {
      type_: StructTag { .. },
      fields: { "pos0": Address(0xdef) },
    }),
}

But the explorer correctly shows me:

{ 
  "key": "text",
  "value": {
    "type": "0xabc::foo::Bar"
    "variant": "A",
    "fields": { "pos0": "0xdef" }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cli Command line tools rust-sdk
Projects
None yet
Development

No branches or pull requests

3 participants