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

[framework] Display object module #7668

Merged
merged 20 commits into from
Feb 22, 2023
Merged

[framework] Display object module #7668

merged 20 commits into from
Feb 22, 2023

Conversation

damirka
Copy link
Contributor

@damirka damirka commented Jan 25, 2023

@damirka damirka added the move label Jan 25, 2023
@damirka damirka self-assigned this Jan 25, 2023
@vercel
Copy link

vercel bot commented Jan 25, 2023

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

Name Status Preview Comments Updated
explorer ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Feb 22, 2023 at 8:14PM (UTC)
frenemies ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Feb 22, 2023 at 8:14PM (UTC)
wallet-adapter ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Feb 22, 2023 at 8:14PM (UTC)
1 Ignored Deployment
Name Status Preview Comments Updated
explorer-storybook ⬜️ Ignored (Inspect) Feb 22, 2023 at 8:14PM (UTC)

crates/sui-framework/sources/display.move Outdated Show resolved Hide resolved
crates/sui-framework/sources/display.move Outdated Show resolved Hide resolved
/// we don't need to perform an authorization check.
///
/// Also, the only place it can be used is the function where the Display
/// object was created; hence values and names are likely to be hardcoded and
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think I understand what this is saying (Move doesn't currently allow string constants and thus wannabe string constants have type vector<u8>), but I think asking for strings is clearer/less error-prone here--a UTF8 decoding error inside this function would be puzzling.

Copy link
Contributor

Choose a reason for hiding this comment

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

Don't we now allow String on entry functions?

I agree though that we probably want to make these functions all take String instead of vector<u8> to avoid confusion.

Copy link
Contributor

Choose a reason for hiding this comment

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

I noticed this has been merged with vector<u8>. Are we still planning to change this to String?

crates/sui-framework/sources/display.move Outdated Show resolved Hide resolved
crates/sui-framework/sources/display.move Outdated Show resolved Hide resolved
crates/sui-framework/sources/display.move Outdated Show resolved Hide resolved
}

/// Create an empty Display object. It can either be shared empty of filled
/// with data right away via cheaper `set_owned` method.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there also a case where we'd want Display to be single-owner or immutable rather than shared?

Intuitively, it seems like a single-owner display owned by the address that has the Publisher cap would be the most common--you want anyone to be able to read the Display info, but no one else needs to update it or read it on-chain.

crates/sui-framework/sources/display.move Outdated Show resolved Hide resolved
crates/sui-framework/sources/display.move Show resolved Hide resolved

/// Create an empty Display object. It can either be shared empty of filled
/// with data right away via cheaper `set_owned` method.
public fun empty<T: key>(pub: &Publisher, ctx: &mut TxContext): Display<T> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this specify that it should be called at most once for a given type T (and explain what happens if that assumption is violated)?

Copy link
Contributor Author

@damirka damirka Feb 17, 2023

Choose a reason for hiding this comment

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

That's a good one! I have an idea of creating a centralized registry of displays for the sake of discoverability and also uniqueness. We might handle versions there as well.

Another benefit we can get from the centralization is the ability to destroy older versions of the display and get a storage rebate (as opposed to shared objects which are not deletable yet).

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you update the comment to explain the intention?

crates/sui-framework/sources/display.move Outdated Show resolved Hide resolved
crates/sui-framework/sources/display.move Show resolved Hide resolved
/// we don't need to perform an authorization check.
///
/// Also, the only place it can be used is the function where the Display
/// object was created; hence values and names are likely to be hardcoded and
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't we now allow String on entry functions?

I agree though that we probably want to make these functions all take String instead of vector<u8> to avoid confusion.

crates/sui-framework/sources/display.move Outdated Show resolved Hide resolved
@Suficio
Copy link

Suficio commented Feb 7, 2023

This sounds like a great initiative and is a big step forward for display standards in SUI!

I would like to structure my feedback in two, how this structure affects OriginByte NFTs and perhaps proposing an alternative approach.

Displaying OriginByte NFTs thus far works based on DisplayDomain which contains the bare name and description fields. There are additional domains such as UrlDomain which allow more composability of display properties.

A collection using OB NFTs does not have to use these domains and may opt to instead provide its own methods of storing display information. Since domains are indexed by type, not string, and are dynamic objects, I'm not sure if this proposal will allow for indexing into them like so: {DisplayDomain.name}. This is not a deal-breaker as we can always provide these fields in the core Nft type.

In the same vein, will dynamic fields with string keys be supported for this indexing?

As I mentioned initially, we would like to propose an alternative approach.

Since Display in essence provides a struct that provides a "view" into the object, here at OriginByte we were wondering if there are alternative ways to make that happen.

An initial solution that comes to mind is allowing entry functions (or view functions) to return view structs that contain fields otherwise available in the Display VecMap. For OriginByte, this would allow collection creators to define such a view function that would serialize all of their fields of interest. In a more general view it enables creators more flexibility to implement just in time transformation of their data.

These view functions would run immutably and be limited in complexity, and be run on the same module that would otherwise populate the template fields in Display<T>.

@damirka
Copy link
Contributor Author

damirka commented Feb 17, 2023

Hey @Suficio! Thank you for your feedback. I've replied on the Sui Developers (link to the reply).

Hopefully this answers all of the topics raised in your question, please feel free to disagree or ask if anything is unclear.

@damirka damirka marked this pull request as ready for review February 17, 2023 13:24
@damirka damirka changed the title [wip] Display object module [framework] Display object module Feb 22, 2023
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.

Suggesting changes to add a version field + more tests, but otherwise LGTM!

@damirka damirka requested a review from sblackshear February 22, 2023 17:25
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.

LGTM pending tests!

crates/sui-framework/sources/display.move Outdated Show resolved Hide resolved
@damirka damirka enabled auto-merge (squash) February 22, 2023 18:12
@vercel vercel bot temporarily deployed to Preview – wallet-adapter February 22, 2023 20:13 Inactive
@vercel vercel bot temporarily deployed to Preview – frenemies February 22, 2023 20:14 Inactive
@damirka damirka merged commit 02fead9 into main Feb 22, 2023
@damirka damirka deleted the ds/display-metadata branch February 22, 2023 20:48
/// we don't need to perform an authorization check.
///
/// Also, the only place it can be used is the function where the Display
/// object was created; hence values and names are likely to be hardcoded and
Copy link
Contributor

Choose a reason for hiding this comment

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

I noticed this has been merged with vector<u8>. Are we still planning to change this to String?

Comment on lines +176 to +177
let i = 0;
while (i < 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Uh this should be while (i < len)

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 catch! Thank you!

666lcz added a commit that referenced this pull request Feb 28, 2023
## Description 

This PR adds the RPC support for
#7668 and added e2e TS tests

Todos(in separate PRs)

- [ ] merge the display endpoint into the[ new queryObjects
API](https://www.notion.so/mystenlabs/RFC-GetObjects-API-Refactoring-27ff6b8d6ffc42c8b492c1efa368b70a?pvs=4)
- [ ] Handle struct that has no Display defined `Overall display should
be treated as Debug and Display traits in Rust. If we don’t have Display
defined, we show default debug (on the FE/Apps), if there’s Display, we
show things nicely.` I'll implement this when we implement the new
queryObjects API
- [ ] Add rust based tests


## Test Plan 

How did you test the new or updated feature?

Added e2e TS tests to cover the following test cases
- Escape syntax (e.g., `\{name\}` should return `{name}` instead of
`Alice` even if there's a field called Alice)
- Nested fields
- multiple fields
- option::some and option::none
- no template value
- sui address
- UID
- `sui::url::Url` type



---
If your changes are not user-facing and not a breaking change, you can
skip the following section. Otherwise, please indicate what changed, and
then add to the Release Notes section as highlighted during the release
process.

### Type of Change (Check all that apply)

- [ ] user-visible impact
- [ ] breaking change for a client SDKs
- [ ] breaking change for FNs (FN binary must upgrade)
- [ ] breaking change for validators or node operators (must upgrade
binaries)
- [ ] breaking change for on-chain data layout
- [ ] necessitate either a data wipe or data migration

### Release notes
@jovicheng
Copy link
Contributor

@damirka Hi, is there any update regarding template syntax (df or dynamic_field_key)?

@damirka
Copy link
Contributor Author

damirka commented Nov 28, 2023

Hey @jovicheng. We're at full capacity already; more updates will be coming next year. But yes, df and vectors and a lot more will be there!

@jovicheng
Copy link
Contributor

Hey @jovicheng. We're at full capacity already; more updates will be coming next year. But yes, df and vectors and a lot more will be there!

Thank you for your reply. I would like to confirm again, currently, this feature is not supported, correct?

@damirka
Copy link
Contributor Author

damirka commented Nov 28, 2023

@jovicheng

I would like to confirm again, currently, this feature is not supported, correct?

Correct, you can't fetch dynamic fields just yet.

@jovicheng
Copy link
Contributor

@jovicheng

I would like to confirm again, currently, this feature is not supported, correct?

Correct, you can't fetch dynamic fields just yet.

thanks, looking forward to this new features."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants