Closed jolestar closed 1 year ago
What are the advantages of Object and global storage respectively?
What are the advantages of Object and global storage respectively?
Give an example. We use Move to write a Blog system.
Where to save the Article? If we save the Article in the author's storage, How do we aggregate the author's articles for the list?
A solution uses the Object and Global Storage:
An idea about ResourceTable
We can only save ObjectRef in the ResourceTable, requiring the struct with the key
ability to be an Object, like Sui.
move_to<T>(signer)
= save T to object store and save a reference in ResourceTable.borrow_global<T>(address)
= get the T object reference and borrow it from the object store.Some ideas about ObjectRef
We need two types of ObjectRef:
Question:
What are the advantages of Object and global storage respectively?
Give an example. We use Move to write a Blog system.
Where to save the Article? If we save the Article in the author's storage, How do we aggregate the author's articles for the list?
A solution uses the Object and Global Storage:
- We define the Article as an Object and save the Article to the object store.
- We reference articles by the ObjectID, make an index for every list, and save the index to the global storage.
Got it.
In hybrid mode, We need a method to get the Object from it's id.
For example, there is a function
public entry fun update_article(article: &mut Article, content: vector<u8>)
If we retrieve the ObjectID of article from the global storage, we need a method like borrow_mut_object_from_id<Article>(id: address): &mut Article
to get the Article object, and then we can pass it to the update_article
function.
I haven't decided whether to provide this method. In Sui, an Object can only be passed through transaction parameters and cannot be directly retrieved from the Object Store using the ObjectID. This relies on the design of ObjectRef.
In core Move, global storage is part of the programming model and can be accessed through special operations, such as move_to, move_from and many more global storage operators. Both resources and modules are stored in the core Move global storage.
Sui introduce Object model in Move, and disable all global storage operators.
We try to hybridize the two features and make the Move language more expressive.
The developers can use global storage to save the Object index and use Objects to express Resources.