rooch-network / rooch

VApp Container with Move Language
https://rooch.network
Apache License 2.0
128 stars 54 forks source link

[MoveosStd] Refactor ObjectRef, context:new_object and context::remove_object #948

Closed jolestar closed 7 months ago

jolestar commented 7 months ago

Summary

[MoveosStd] Refactor ObjectRef, context:new_object and context::remove_object

  1. Make ObjectRef can not copy.
  2. context::new_object<T> auto add Object to storage, and return ObjectRef
  3. context::remove_object<T> auto unpack the Object, and return (id, owner, T)
  4. Refactor examples to use ObjectRef.

Continue #935

Part of #901

@geometryolife Some documents and example readme need to be updated. @wubuku the code generator needs to be updated with new Object and ObjectRef API.

vercel[bot] commented 7 months ago

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

1 Ignored Deployment | Name | Status | Preview | Comments | Updated (UTC) | | :--- | :----- | :------ | :------- | :------ | | **rooch** | ⬜️ Ignored ([Inspect](https://vercel.com/rooch/rooch/4Jiat4ufww65cJb2Lz5zC8mY2fKX)) | [Visit Preview](https://rooch-git-objectrefrefactor-rooch.vercel.app) | | Oct 14, 2023 1:19am |
WGB5445 commented 7 months ago

ObjectRef is a way to divide Object permissions. ObjectRef allows anyone to operate on the Object body. Should we abstract the permissions of sending and extending Objects, so that Objects are more flexible?

jolestar commented 7 months ago

ObjectRef is a way to divide Object permissions. ObjectRef allows anyone to operate on the Object body. Should we abstract the permissions of sending and extending Objects, so that Objects are more flexible?

Do you have some ideas about this?

WGB5445 commented 7 months ago

ObjectRef is a way to divide Object permissions. ObjectRef allows anyone to operate on the Object body. Should we abstract the permissions of sending and extending Objects, so that Objects are more flexible?

Do you have some ideas about this?

Here, we limit the sending of Objects of type to the module of T. We can modify Objects so that they can be sent anywhere.

https://github.com/rooch-network/rooch/blob/aa85fd70355e8b9ad77a2004f22301185fe74489/moveos/moveos-stdlib/moveos-stdlib/sources/object.move#L56-#L60

We can limit the sending permissions of Objects by adding some fields. Only users who have TransferRef can send this Object.

struct Object {
    allow_ungated_transfer: bool,
}

As a result, all Objects can be sent arbitrarily, and the creator can close the sending of some Objects. Here is the implementation of Aptos, which I think is very good.

https://github.com/aptos-labs/aptos-core/blob/main/aptos-move/framework/aptos-framework/sources/object.move#L400-L410

jolestar commented 7 months ago

Here, we limit the sending of Objects of type to the module of T. We can modify Objects so that they can be sent anywhere.

https://github.com/rooch-network/rooch/blob/aa85fd70355e8b9ad77a2004f22301185fe74489/moveos/moveos-stdlib/moveos-stdlib/sources/object.move#L56-#L60

We can limit the sending permissions of Objects by adding some fields. Only users who have TransferRef can send this Object.

struct Object {
    allow_ungated_transfer: bool,
}

As a result, all Objects can be sent arbitrarily, and the creator can close the sending of some Objects. Here is the implementation of Aptos, which I think is very good.

https://github.com/aptos-labs/aptos-core/blob/main/aptos-move/framework/aptos-framework/sources/object.move#L400-L410

We can provide a public_transfer to Object, if needed. The public_transfer requires the T has key + store ability but does not require private_generics(T) like Sui.

WGB5445 commented 7 months ago

Here, we limit the sending of Objects of type to the module of T. We can modify Objects so that they can be sent anywhere. https://github.com/rooch-network/rooch/blob/aa85fd70355e8b9ad77a2004f22301185fe74489/moveos/moveos-stdlib/moveos-stdlib/sources/object.move#L56-#L60 We can limit the sending permissions of Objects by adding some fields. Only users who have TransferRef can send this Object.

struct Object {
    allow_ungated_transfer: bool,
}

As a result, all Objects can be sent arbitrarily, and the creator can close the sending of some Objects. Here is the implementation of Aptos, which I think is very good. https://github.com/aptos-labs/aptos-core/blob/main/aptos-move/framework/aptos-framework/sources/object.move#L400-L410

We can provide a public_transfer to Object, if needed. The public_transfer requires the T has key + store ability but does not require private_generics(T) like Sui.

I believe it is necessary, As a special type, Object should have some differences from ordinary structs, such as inheritance, polymorphism, and extensibility. And I think it is essential that Object be extensible. A built-in typetable or other extension mechanism would increase Object's flexibility.