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

[MoveosStd] Refactor ObjectRef, allow ObjectRef as transaction argument #1026

Merged
merged 18 commits into from
Oct 28, 2023

Conversation

jolestar
Copy link
Contributor

@jolestar jolestar commented Oct 24, 2023

Summary

  1. [MoveosStd] Refactor ObjectRef, allow ObjectRef as transaction argument
  2. [CLI] verify modules when publishing on the client side.
  3. [Example] Refactor simple_blog example via new ObjectRef API.

Part of #1001

  1. Anyone can obtain &ObjectRef<T> by ObjectID, and then get &T. This can be achieved through the entry function arguments or context::borrow_object(ctx, ObjectID).
  2. Only the owner can obtain &mut ObjectRef<T> by ObjectID, and then get &mut T. This can be achieved through the entry function arguments or context::borrow_mut_object(ctx,signer,ObjectID).
  3. If T has both key and store ability, anyone can transfer ownership by object_ref::transfer(&mut Object<T>, address).
  4. The module where T is defined can use context::borrow_mut_object_extend to obtain any &mut ObjectRef<T>, and can transfer ownership by using object_ref::transfer_extend(&mut Object<T>, address).
  5. Only the module where T is defined can call the object_ref::remove(ObjectRef<T>) method to remove the Object.
  6. The object_ref::to_permanent method is provided to drop ObjectRef<T>, but once ObjectRef<T> is dropped, the Object cannot be removed from object storage.
  7. Provide to_shared, to_frozen function.

TODO in next PR

  1. Rename Object to ObjectEntity and object.move to object_entity.move.
  2. Rename ObjectRef to Object and object_ref.move to object.move
  3. Implement shared and frozen

@vercel
Copy link

vercel bot commented Oct 24, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
rooch ⬜️ Ignored (Inspect) Visit Preview Oct 27, 2023 3:13pm

@jolestar jolestar marked this pull request as draft October 24, 2023 08:02
@jolestar jolestar marked this pull request as ready for review October 25, 2023 17:03
let obj = storage_context::remove<T>(&mut self.storage_context, object_id);
object::unpack_internal(obj)
/// The module of T can borrow mut Object from object store with any object_id
public fun borrow_object_mut_extend<T: key>(self: &mut Context, object_id: ObjectID) : &mut ObjectRef<T> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If an object is transferred to another address, the module where the object is defined can still get the write reference of the object through borrow_object_mut_extend?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

@jolestar jolestar requested a review from wubuku as a code owner October 27, 2023 13:04
@jolestar jolestar merged commit 0c151ef into main Oct 28, 2023
4 checks passed
@jolestar jolestar deleted the object_refactor_v2 branch October 28, 2023 02:35
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

Successfully merging this pull request may close these issues.

3 participants