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

Contribution: missing Object content getters #72

Open
unmaykr-aftermath opened this issue Dec 18, 2024 · 3 comments
Open

Contribution: missing Object content getters #72

unmaykr-aftermath opened this issue Dec 18, 2024 · 3 comments

Comments

@unmaykr-aftermath
Copy link
Contributor

Hi folks. I've noticed that sui_sdk_types::types::Object is missing any way of accessing its inner package/struct contents.

Personally, I'm mostly interested in the BCS bytes of the inner MoveStruct. I see that its other attributes are unnecessary from the user's POV, since we already have the Object::version and Object::object_type methods.

Therefore I'd like to contribute with a new method to Object:

pub fn as_struct(&self) -> Option<(&StructTag, &[u8])>;

Naming up for discussion ofc :)

Notice I included the struct tag in the return, otherwise callers run into scenarios like:

let ObjectType::Struct(tag) = object.object_type() else {
    // ...
};
let bcs = object.as_struct().expect("checked if struct above");
@bmwill
Copy link
Collaborator

bmwill commented Dec 18, 2024

What would your thoughts be on having the as_struct method return an Option<&MoveStruct> and then having the user use accessors on MoveStruct to be able to get out the Type and contents?

@unmaykr-aftermath
Copy link
Contributor Author

What would your thoughts be on having the as_struct method return an Option<&MoveStruct> and then having the user use accessors on MoveStruct to be able to get out the Type and contents?

Sure, no immediate problem with it. I just usually err on the side of exposing the least possible or the types that I think are most stable. But to be fair I guess MoveStruct is one of those types. Probably a good idea to keep MoveStruct::has_public_transfer private to avoid any misinterpretation there (there's a comment clearly stating it's deprecated)

@unmaykr-aftermath
Copy link
Contributor Author

I realize now that I was only looking at the source on docs.rs and missed the fact that a lot of private fields now have getters (added in 6969208). So I guess this contrib makes less sense now.

I still think pub fn as_struct(&self) -> Option<&MoveStruct> can be valuable as it's more ergonomic in certain scenarios compared to pattern matching with sui_sdk_types::types::ObjectData.

Probably a good idea to keep MoveStruct::has_public_transfer private to avoid any misinterpretation there (there's a comment clearly stating it's deprecated)

Also the comment above still stands

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

2 participants