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/move] support dynamic access of child objects #4203

Open
sblackshear opened this issue Aug 22, 2022 · 9 comments
Open

[sui/move] support dynamic access of child objects #4203

sblackshear opened this issue Aug 22, 2022 · 9 comments
Assignees
Labels
design move Priority: High Very important task, not blocking but potentially delaying milestones or limiting our offering Type: Major Feature Major new functionality or integration, which has a significant impact on the network
Milestone

Comments

@sblackshear
Copy link
Collaborator

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
@sblackshear sblackshear added Type: Major Feature Major new functionality or integration, which has a significant impact on the network Priority: High Very important task, not blocking but potentially delaying milestones or limiting our offering move design labels Aug 22, 2022
@bholc646 bholc646 assigned bholc646 and tnowacki and unassigned bholc646 Aug 25, 2022
@bholc646 bholc646 added this to the [C] Wave 2 milestone Aug 25, 2022
@bholc646
Copy link
Contributor

bholc646 commented Sep 8, 2022

  • gaining consensus around lamport timestamps
  • Todd to bring up remaining decision points in next weeks design meeting

@xander988
Copy link

How long will it take to complete this feature

@0xys
Copy link

0xys commented Sep 26, 2022

If completed, can an object own infinitely many child objects, like Key-Value map?
(What I mean by "Infinitely" is only in theoretical term.)

@sblackshear
Copy link
Collaborator Author

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

@sblackshear
Copy link
Collaborator Author

How long will it take to complete this feature

This is a question for @tnowacki, but I think sometime in October

@xander988
Copy link

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

@porkbrain
Copy link
Contributor

porkbrain commented Oct 11, 2022

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 ...?

@JohnChangUK
Copy link

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.

@PaulFidika
Copy link
Contributor

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.

has_child_object is being included as a method:

https://github.com/MystenLabs/sui/pull/5169/files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
design move Priority: High Very important task, not blocking but potentially delaying milestones or limiting our offering Type: Major Feature Major new functionality or integration, which has a significant impact on the network
Projects
None yet
Development

No branches or pull requests

8 participants