-
Notifications
You must be signed in to change notification settings - Fork 11.3k
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
Object Tutorials Chapter 4 #1848
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Super helpful stuff!
|
||
Now let's look at how we could enable a swap/trade between your object and others' objects. A straightforward idea is this: define a function that takes two objects from two accounts, and swap their ownership. But this doesn't work in Sui! Recall from Chapter 2 that only object owners can send a transaction to mutate the object. So one person cannot send a transaction that would swap their own object with someone else's object. | ||
|
||
In the future, we will likely introduce multi-sig transactions so that two people can sign the same transaction for this type of usecase. However you may not always be able to find someone to swap with right away. A multi-sig transaction won't work in this scenario. Even if you can, you may not want to carry the burden of finding a swap target. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Multi-sig" usually refers to requiring multiple keys to send a tx from a single address rather than sending a tx that acts on behalf of multiple addresses. We used to call the idea you are describing "multi-agent" transactions.
} | ||
``` | ||
Now `Bar` is also a Sui object type. When we put a Sui object of type `Bar` into a Sui object of type `Foo`, the Sui object of type `Bar` is said to be **wrapped**. | ||
There are some interesting consequences of wrapping an Sui object into another. When an object is wrapped, this object no longer exists independently on-chain. One will no longer be able to look up this object by its ID. This object becomes part of the data of the object that wraps it. Most importantly, one can no longer pass the wrapped object as an argument in any way in Move calls. The only access point is through the wrapping object. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably explain 3 edge cases (with a note):
-
It's not clear if we can wrap an already wrapped object?
wrap(wrap(wrap(obj))) -
Are accidental cycles resolved automatically at compilation or the dev should take care of it?
-
Can a regular struct hold a Sui object (thus the opposite from the example)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call! Will explain them in the doc.
To answer your question
- No. A wrapped object cannot be used directly.
- Since 1) is no, there cannot be cycles
- No.
Co-authored-by: Sam Blackshear <sam.blackshear@gmail.com>
Replace One with We Co-authored-by: Sam Blackshear <sam.blackshear@gmail.com>
Introduce Wrapper object Co-authored-by: Sam Blackshear <sam.blackshear@gmail.com>
Fix typo Co-authored-by: Sam Blackshear <sam.blackshear@gmail.com>
Fix typo, remove hyphens from third-party nouns Co-authored-by: Sam Blackshear <sam.blackshear@gmail.com>
Fix typo Co-authored-by: Sam Blackshear <sam.blackshear@gmail.com>
Refine service operator limitations Co-authored-by: Sam Blackshear <sam.blackshear@gmail.com>
Specify old sword returned Co-authored-by: Sam Blackshear <sam.blackshear@gmail.com>
Thank you @Clay-Mysten! |
Make initial edits
|
||
There are some interesting consequences of wrapping an Sui object into another. When an object is wrapped, this object no longer exists independently on-chain. We will no longer be able to look up this object by its ID. This object becomes part of the data of the object that wraps it. Most importantly, *we can no longer pass the wrapped object as an argument in any way in Move calls*. The only access point is through the wrapping object. | ||
|
||
>:bulb: The fact that you can no longer use a wrapped Sui object means that it's impossible to create circular wrapping behavior, where A wraps B, B wraps C, and C also wraps A. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<3
value: u64, | ||
} | ||
``` | ||
> :book: For a struct type to be capable of being embedded in a Sui object struct (which will have `key` ability), the embedded struct type must have the `store` ability. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks!
Finish direct edits
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Xun,
Fantastic work, as always. I made my edits directly in two commits and have no questions or TODOs. I did note you and I had commits going simultaneously where you were addressing feedback from Kostas.
Please, please help me ensure I overwrote none of your work. I saw no conflicts but don't yet know how they would manifest in GitHub at the commit (as opposed to PR) level. If I can help, let me know. Thanks!
* Object Tutorials Chapter 4 * Update doc/src/build/programming-with-objects/ch4-object-wrapping.md Co-authored-by: Sam Blackshear <sam.blackshear@gmail.com> * Update doc/src/build/programming-with-objects/ch4-object-wrapping.md Replace One with We Co-authored-by: Sam Blackshear <sam.blackshear@gmail.com> * Update doc/src/build/programming-with-objects/ch4-object-wrapping.md Introduce Wrapper object Co-authored-by: Sam Blackshear <sam.blackshear@gmail.com> * Update doc/src/build/programming-with-objects/ch4-object-wrapping.md Fix typo Co-authored-by: Sam Blackshear <sam.blackshear@gmail.com> * Update doc/src/build/programming-with-objects/ch4-object-wrapping.md Fix typo, remove hyphens from third-party nouns Co-authored-by: Sam Blackshear <sam.blackshear@gmail.com> * Update doc/src/build/programming-with-objects/ch4-object-wrapping.md Fix typo Co-authored-by: Sam Blackshear <sam.blackshear@gmail.com> * Update doc/src/build/programming-with-objects/ch4-object-wrapping.md Refine service operator limitations Co-authored-by: Sam Blackshear <sam.blackshear@gmail.com> * Update doc/src/build/programming-with-objects/ch4-object-wrapping.md Specify old sword returned Co-authored-by: Sam Blackshear <sam.blackshear@gmail.com> * Address Kostas's questions * Create ch4-object-wrapping.md Make initial edits * Update ch4-object-wrapping.md Finish direct edits Co-authored-by: Clay-Mysten <100217682+Clay-Mysten@users.noreply.github.com> Co-authored-by: Sam Blackshear <sam.blackshear@gmail.com>
* Object Tutorials Chapter 4 * Update doc/src/build/programming-with-objects/ch4-object-wrapping.md Co-authored-by: Sam Blackshear <sam.blackshear@gmail.com> * Update doc/src/build/programming-with-objects/ch4-object-wrapping.md Replace One with We Co-authored-by: Sam Blackshear <sam.blackshear@gmail.com> * Update doc/src/build/programming-with-objects/ch4-object-wrapping.md Introduce Wrapper object Co-authored-by: Sam Blackshear <sam.blackshear@gmail.com> * Update doc/src/build/programming-with-objects/ch4-object-wrapping.md Fix typo Co-authored-by: Sam Blackshear <sam.blackshear@gmail.com> * Update doc/src/build/programming-with-objects/ch4-object-wrapping.md Fix typo, remove hyphens from third-party nouns Co-authored-by: Sam Blackshear <sam.blackshear@gmail.com> * Update doc/src/build/programming-with-objects/ch4-object-wrapping.md Fix typo Co-authored-by: Sam Blackshear <sam.blackshear@gmail.com> * Update doc/src/build/programming-with-objects/ch4-object-wrapping.md Refine service operator limitations Co-authored-by: Sam Blackshear <sam.blackshear@gmail.com> * Update doc/src/build/programming-with-objects/ch4-object-wrapping.md Specify old sword returned Co-authored-by: Sam Blackshear <sam.blackshear@gmail.com> * Address Kostas's questions * Create ch4-object-wrapping.md Make initial edits * Update ch4-object-wrapping.md Finish direct edits Co-authored-by: Clay-Mysten <100217682+Clay-Mysten@users.noreply.github.com> Co-authored-by: Sam Blackshear <sam.blackshear@gmail.com>
This PR adds Chapter 4, object wrapping.
The last section is still work in progress, but want to send this out early to get feedback.