[MoveosStd] Refactor Object & ObjectRef, unify Object APIs and support Object public transfer #1001
Closed
Labels
area::move-language
Move language relative issue, verifier,prover,VM
area:stdlib
Move stdlib or framework issues
skill::move
Need the Move language skill to complete the issue
status::design
The issue need to do more detail design
Milestone
Motivation
Currently, Object & ObjectRef provides APIs that make developers to get confused when using them.
For example:
private_generics
, and the owner can't transfer the Object directly, what does the owner stand for? Is it possible to provide an API similar to Sui'spublic_transfer
? [Object] Proposal for an Owner method to directly operate on Objects #80 [Move Object] Public Object transfer, borrow, borrow_mut #989This refactoring tries to solve the above problems.
Solution
We define two kinds of Object owner:
When an Object is created, it is the CodeOwner by default until it is explicitly transferred to a user.
When an Object is created, an ObjectRef is created at the same time, which cannot be
copy
, and cannot bedrop
. There are two cases when an ObjectRef is dropped:That is, if any Object is referenced by an ObjectRef, it belongs to the code that references it (usually another struct). Otherwise, it must belong to some user.
The User Owner's Object can be passed as an argument to the entry function,
&ObjectRef<T>
,&mut ObjectRef<T>
. That is, the ObjectRef of the UserOwner Object is actually referenced externally.Example Code
We can remove all
ObjectID
functions from Context, such as:borrow_object(ObjectID)
, andborrow_object_mut(ObjectID)
. We do not provide function for handle Object via ObjectID.If the T of Object has
key + store
, the Object is public. Otherwise, it is private.The public Object can be directly handled with
transfer
,borrow
,borrow_mut
functions.The private Object needs the T module to extend the
transfer_extend
,borrow_extend
,borrow_mut_extend
functions.When the
ObjectRef<T>
is an entry function argument, it needs to satisfy the following requirements:Relative issues
The text was updated successfully, but these errors were encountered: