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.01k stars 11.12k forks source link

Add a sui::object::get_type(&uid) function #8404

Closed PaulFidika closed 10 months ago

PaulFidika commented 1 year ago

Would it be possible to add a function to sui::object that is like:

get_type(uid: &UID): Option<ascii::String>

(alternatively we could return a std::type_name::TypeName instead of a string (but I like strings more)).

The intention is that, given a UID, you can query what the type is of the object to which it belons (because presumably most UIDs are embedded inside of an object as an id). This would be useful for dynamic fields, which pass around &mut UID's to each other, rather than operating on the object directly. The Option<> portion is because the UID might not be inside of an object at all, in which case we would return option::none().

I suppose this is a rather niche use, but it would be helpful with Capsules, who frequently pass around &mut UIDs to each other so that programs can attach their own custom fields to other program's structs. I think this should be possible to implement within Sui. Thanks.

github-actions[bot] commented 1 year ago

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days.

stefan-mysten commented 10 months ago

@PaulFidika thanks for raising this up. Is this still something you are interest in having?

tnowacki commented 10 months ago

Unfortunately this is not implementable, as you cannot generally query objects in this way. So I'll close for now

tnowacki commented 10 months ago

A bit more context here: You cannot query information about all objects in Sui, only input objects (and dynamic fields off of those input objects). So such an API would be limited to input objects, but at that point, you could just get the TypeName off of the object itself, which would really limit the usefulness of such a UID-based API.