sui
sui copied to clipboard
[sui/move] support dynamic access of child objects
This is a step we have discussed that will significantly improve the expressiveness of Sui Move by allowing the implementation of collections that require pointer-like structures. The basic idea is:
- Remove the requirement to supply child objects as explicit transaction inputs
- Expose operators for dynamically accessing child objects given a reference to the parent. Children might be accessed by a "key" value (e.g.,
remove_child_by_key<K: copy + drop, P: key, C: key>(parent: &mut P, key: &K): C), a type (e.g.,remove_child_by_type<K, P: key, C: key(parent: &mut P): C), by id (e.g.,remove_child_by_id<P: key, C: key>(parent: &mut P, id: ID): C, or all of the above. - The parent/child relationship now looks like a pointer, and design patterns/collection types that require this can be build accordingly
- gaining consensus around lamport timestamps
- Todd to bring up remaining decision points in next weeks design meeting
How long will it take to complete this feature
If completed, can an object own infinitely many child objects, like Key-Value map? (What I mean by "Infinitely" is only in theoretical term.)
If completed, can an object own infinitely many child objects, like Key-Value map? (What I mean by "Infinitely" is only in theoretical term.)
Yes! It can have an unbounded number
How long will it take to complete this feature
This is a question for @tnowacki, but I think sometime in October
How long will it take to complete this feature
This is a question for @tnowacki, but I think sometime in October
@tnowacki Can you speed it up
Removing child objects by type would be useful for the following use case:
// package1
struct Foo has key {
id: UID,
children: vector<ID>,
}
struct Bar<phantom FT> has key {
id: UID,
amount: Balance<FT>,
}
public fun pop_child_any_mint<FT>(parent: &mut Foo): Balance<FT> {
let Bar { id, amount } = remove_child_by_type<FT>(parent);
object::delete(id);
amount
}
// package2
// custom royalty collection in USDC and SUI
public fun custom_royalty_collection(foo: Foo) {
let ft = package1::pop_child_any_mint<USDC>(&mut foo);
let s = package1::pop_child_any_mint<SUI>(&mut foo);
// ...
}
Ie. I know the type I want to get in a specific implementation, but want to create a generic interface for doing that for any type.
Not sure how multiple children of the same type should be handled though. Return a vec of all, or first one at random, or ...?
It would be ideal to also have native APIs to check whether a parent object owns a child object, and other helper methods as well. e.g.contains_child_by_id<P: key>(parent: &P, id: &ID): bool
Are there APIs to show all objects the parents owns? If not then a vector of IDs need to be kept to keep track of which objects the parent owns.
It would be ideal to also have native APIs to check whether a parent object owns a child object, and other helper methods as well. e.g.
contains_child_by_id<P: key>(parent: &P, id: &ID): boolAre there APIs to show all objects the parents owns? If not then a vector of IDs need to be kept to keep track of which objects the parent owns.
has_child_object is being included as a method:
https://github.com/MystenLabs/sui/pull/5169/files