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

[sui/metadata] The enum structure returned by metadata is not the same as the enum struct set in the contract. #20914

Open
vladilen11 opened this issue Jan 17, 2025 · 2 comments
Assignees
Labels

Comments

@vladilen11
Copy link
Contributor

vladilen11 commented Jan 17, 2025

The enum variants field returned by metadata is sorted and is not in the same order as the contract settings.

this is my contract

  module monster_hunter::terrain_type {

  public enum TerrainType has copy, drop , store {
                                None,TallGrass,Boulder
                        }

  public fun new_none(): TerrainType {
    TerrainType::None
  }

  public fun new_tall_grass(): TerrainType {
    TerrainType::TallGrass
  }

  public fun new_boulder(): TerrainType {
    TerrainType::Boulder
  }
}

this is the metadata of my contract:

  "terrain_type": {
    "fileFormatVersion": 7,
    "address": "0x85f95a4253621cac22ebfc27ec67b903c153e7b1bea5a2813c71fa62016746c7",
    "name": "terrain_type",
    "friends": [],
    "structs": {},
    "enums": {
      "TerrainType": {
        "abilities": { "abilities": ["Copy", "Drop", "Store"] },
        "typeParameters": [],
        "variants": { "Boulder": [], "None": [], "TallGrass": [] }
      }
    },

This will cause a problem, the developer can't get the correct structure of the enums in the contract through the metadata, and can't construct the correct bcs struct through the metadata.

To summarise, we want metadata to return information that is consistent with the contract code. In the current scenario, the corresponding metadata would be:

"enums": {
      "TerrainType": {
        "abilities": { "abilities": ["Copy", "Drop", "Store"] },
        "typeParameters": [],
        "variants": { ""None": [], "TallGrass": [], Boulder": [] }
      }
    },
Copy link
Contributor

Thank you for opening this issue, a team member will review it shortly. Until then, please do not interact with any users that claim to be from Sui support and do not click on any links!

@stefan-mysten
Copy link
Member

Thanks for this report. @tzakian any idea here?

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

No branches or pull requests

3 participants