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

Object Tutorials Chapter 4 #1848

Merged
merged 12 commits into from
May 10, 2022
Merged

Object Tutorials Chapter 4 #1848

merged 12 commits into from
May 10, 2022

Conversation

lxfind
Copy link
Contributor

@lxfind lxfind commented May 6, 2022

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.

@lxfind lxfind requested a review from Clay-Mysten as a code owner May 6, 2022 18:37
@github-actions github-actions bot added the Type: Documentation Improvements or additions to documentation label May 6, 2022
Copy link
Collaborator

@sblackshear sblackshear left a 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.
Copy link
Collaborator

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.
Copy link
Collaborator

@kchalkias kchalkias May 8, 2022

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):

  1. It's not clear if we can wrap an already wrapped object?
    wrap(wrap(wrap(obj)))

  2. Are accidental cycles resolved automatically at compilation or the dev should take care of it?

  3. Can a regular struct hold a Sui object (thus the opposite from the example)?

Copy link
Contributor Author

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

  1. No. A wrapped object cannot be used directly.
  2. Since 1) is no, there cannot be cycles
  3. No.

Clay-Mysten and others added 8 commits May 9, 2022 09:24
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>
@lxfind
Copy link
Contributor Author

lxfind commented May 9, 2022

Thank you @Clay-Mysten!
I will also update based on Kostas's question latter today.

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.
Copy link
Collaborator

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.
Copy link
Collaborator

Choose a reason for hiding this comment

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

thanks!

Finish direct edits
Copy link
Contributor

@Clay-Mysten Clay-Mysten left a 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!

@lxfind lxfind merged commit 254ab75 into main May 10, 2022
@lxfind lxfind deleted the chapter-4 branch May 10, 2022 20:06
longbowlu pushed a commit that referenced this pull request May 12, 2022
* 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>
punwai pushed a commit that referenced this pull request Jul 27, 2022
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dogfooding Type: Documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants