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

[Move] Added example of an auction using shared objects #856

Merged
merged 9 commits into from
Mar 18, 2022

Conversation

awelc
Copy link
Contributor

@awelc awelc commented Mar 15, 2022

This is the counterpart to the existing auction implementation using single-owner objects only. I have also refactored existing code to share common parts with the new implementation.

@awelc awelc requested review from lxfind, sblackshear and damirka March 15, 2022 23:44
@awelc awelc self-assigned this Mar 15, 2022
/// bidder or to the original owner if no bids have been placed.
public fun end_auction<T: key + store>(auction: Auction<T>) {
let Auction { id, to_sell, owner, bid_data } = auction;
ID::delete(id);
Copy link
Contributor

Choose a reason for hiding this comment

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

Shared object cannot be deleted :(

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense... Can we then even transfer an object wrapped in a shared object? It would seem like we can mutate the object, but then we'd have to replace it with another one. Does it mean, that for to_sell item to be transferable in the shared-object version, it would have to become an Option in the Auction struct?

    struct Auction<T:  key + store> has key {
        id: VersionedID,
        /// Item to be sold.
        to_sell: Option<T>,
        /// Owner of the time to be sold.
        owner: address,
        /// Data representing the highest bid (starts with no bid)
        bid_data: Option<BidData>,
    }

Copy link
Contributor

Choose a reason for hiding this comment

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

If you intend the transfer out the wrapped object, then yes it needs to be optional.

/// bidder or back to the original owner if no bids have been
/// placed. This is executed by the owner of the asset to be
/// auctioned.
public fun end_auction<T: key + store>(auction: Auction<T>, ctx: &mut TxContext) {
Copy link
Contributor

Choose a reason for hiding this comment

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

In fact, a shared object cannot be passed by-value, so it would fail here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed both issues (I hope...)

@awelc awelc force-pushed the aw/auction-example-shared branch from 576123c to 0504990 Compare March 17, 2022 02:26
@awelc
Copy link
Contributor Author

awelc commented Mar 17, 2022

@lxfind - does it look more reasonable now?

@huitseeker huitseeker force-pushed the aw/auction-example-shared branch from cbba68b to 5a7b1b7 Compare March 17, 2022 18:27
@awelc awelc force-pushed the aw/auction-example-shared branch from 5a7b1b7 to f7608a7 Compare March 17, 2022 20:33
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.

Ship it!

@awelc awelc merged commit 289c0de into main Mar 18, 2022
@awelc awelc deleted the aw/auction-example-shared branch March 18, 2022 01:02
mwtian pushed a commit that referenced this pull request Sep 12, 2022
mwtian pushed a commit to mwtian/sui that referenced this pull request Sep 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants