From 0ca4b5bf9a1916e606e0c2da3b19f38d924dd3e5 Mon Sep 17 00:00:00 2001 From: Damir Shamanaev Date: Tue, 5 Nov 2024 16:51:05 +0400 Subject: [PATCH] use module label --- docs/content/standards/display.mdx | 252 ++++++++++++++--------------- 1 file changed, 126 insertions(+), 126 deletions(-) diff --git a/docs/content/standards/display.mdx b/docs/content/standards/display.mdx index 0f1867b37e004..b3c9142f43aee 100644 --- a/docs/content/standards/display.mdx +++ b/docs/content/standards/display.mdx @@ -44,77 +44,77 @@ The following represents the template the `init` function defines: /// mint their Hero. Shows how to initialize the `Publisher` and how /// to use it to get the `Display` object - a way to describe a /// type for the ecosystem. -module examples::my_hero { - use std::string::String; - - // The creator bundle: these two packages often go together. - use sui::package; - use sui::display; - - /// The Hero - an outstanding collection of digital art. - public struct Hero has key, store { - id: UID, - name: String, - image_url: String, - } +module examples::my_hero; - /// One-Time-Witness for the module. - public struct MY_HERO has drop {} - - /// In the module initializer one claims the `Publisher` object - /// to then create a `Display`. The `Display` is initialized with - /// a set of fields (but can be modified later) and published via - /// the `update_version` call. - /// - /// Keys and values are set in the initializer but could also be - /// set after publishing if a `Publisher` object was created. - fun init(otw: MY_HERO, ctx: &mut TxContext) { - let keys = vector[ - b"name".to_string(), - b"link".to_string(), - b"image_url".to_string(), - b"description".to_string(), - b"project_url".to_string(), - b"creator".to_string(), - ]; - - let values = vector[ - // For `name` one can use the `Hero.name` property - b"{name}".to_string(), - // For `link` one can build a URL using an `id` property - b"https://sui-heroes.io/hero/{id}".to_string(), - // For `image_url` use an IPFS template + `image_url` property. - b"ipfs://{image_url}".to_string(), - // Description is static for all `Hero` objects. - b"A true Hero of the Sui ecosystem!".to_string(), - // Project URL is usually static - b"https://sui-heroes.io".to_string(), - // Creator field can be any - b"Unknown Sui Fan".to_string(), - ]; - - // Claim the `Publisher` for the package! - let publisher = package::claim(otw, ctx); - - // Get a new `Display` object for the `Hero` type. - let mut display = display::new_with_fields( - &publisher, keys, values, ctx - ); - - // Commit first version of `Display` to apply changes. - display.update_version(); - - transfer::public_transfer(publisher, ctx.sender()); - transfer::public_transfer(display, ctx.sender()); - } +use std::string::String; + +// The creator bundle: these two packages often go together. +use sui::package; +use sui::display; + +/// The Hero - an outstanding collection of digital art. +public struct Hero has key, store { + id: UID, + name: String, + image_url: String, +} + +/// One-Time-Witness for the module. +public struct MY_HERO has drop {} + +/// In the module initializer one claims the `Publisher` object +/// to then create a `Display`. The `Display` is initialized with +/// a set of fields (but can be modified later) and published via +/// the `update_version` call. +/// +/// Keys and values are set in the initializer but could also be +/// set after publishing if a `Publisher` object was created. +fun init(otw: MY_HERO, ctx: &mut TxContext) { + let keys = vector[ + b"name".to_string(), + b"link".to_string(), + b"image_url".to_string(), + b"description".to_string(), + b"project_url".to_string(), + b"creator".to_string(), + ]; + + let values = vector[ + // For `name` one can use the `Hero.name` property + b"{name}".to_string(), + // For `link` one can build a URL using an `id` property + b"https://sui-heroes.io/hero/{id}".to_string(), + // For `image_url` use an IPFS template + `image_url` property. + b"ipfs://{image_url}".to_string(), + // Description is static for all `Hero` objects. + b"A true Hero of the Sui ecosystem!".to_string(), + // Project URL is usually static + b"https://sui-heroes.io".to_string(), + // Creator field can be any + b"Unknown Sui Fan".to_string(), + ]; + + // Claim the `Publisher` for the package! + let publisher = package::claim(otw, ctx); + + // Get a new `Display` object for the `Hero` type. + let mut display = display::new_with_fields( + &publisher, keys, values, ctx + ); + + // Commit first version of `Display` to apply changes. + display.update_version(); + + transfer::public_transfer(publisher, ctx.sender()); + transfer::public_transfer(display, ctx.sender()); +} - /// Anyone can mint their `Hero`! - public fun mint(name: String, image_url: String, ctx: &mut TxContext): Hero { - Hero { - id: object::new(ctx), - name, - image_url - } +/// Anyone can mint their `Hero`! +public fun mint(name: String, image_url: String, ctx: &mut TxContext): Hero { + Hero { + id: object::new(ctx), + name, + image_url } } ``` @@ -125,31 +125,31 @@ The `display::new` call creates a `Display`, either in a custom function or m The following code sample demonstrates how to create a `Display`: ```move -module sui::display { - /// Get a new Display object for the `T`. - /// Publisher must be the publisher of the T, `from_package` - /// check is performed. - public fun new(pub: &Publisher): Display { /* ... */ } -} +module sui::display; + +/// Get a new Display object for the `T`. +/// Publisher must be the publisher of the T, `from_package` +/// check is performed. +public fun new(pub: &Publisher): Display { /* ... */ } ``` After you create the `Display`, you can modify it. The following code sample demonstrates how to modify a `Display`: ```move -module sui::display { - /// Sets multiple fields at once - public fun add_multiple( - self: &mut Display, - keys: vector, - values: vector - ) { /* ... */ } - - /// Edit a single field - public fun edit(self: &mut Display, key: String, value: String) { /* ... */ } - - /// Remove a key from Display - public fun remove(self: &mut Display, key: String ) { /* ... */ } -} +module sui::display; + +/// Sets multiple fields at once +public fun add_multiple( + self: &mut Display, + keys: vector, + values: vector +) { /* ... */ } + +/// Edit a single field +public fun edit(self: &mut Display, key: String, value: String) { /* ... */ } + +/// Remove a key from Display +public fun remove(self: &mut Display, key: String ) { /* ... */ } ``` Next, the `update_version` call applies the changes and sets the `Display` for the `T` by emitting an event. Full nodes receive the event and use the data in the event to retrieve a template for the type. @@ -157,10 +157,10 @@ Next, the `update_version` call applies the changes and sets the `Display` for t The following code sample demonstrates how to use the `update_version` call: ```move -module sui::display { - /// Update the version of Display and emit an event - public fun update_version(self: &mut Display) { /* ... */ } -} +module sui::display; + +/// Update the version of Display and emit an event +public fun update_version(self: &mut Display) { /* ... */ } ``` ## Sui utility objects @@ -171,11 +171,11 @@ With capabilities, it is important to provide a meaningful description of object The following example demonstrates how to create a capy capability: ```move -module capy::utility { - /// A capability which grants Capy Manager permission to add - /// new genes and manage the Capy Market - public struct CapyManagerCap has key, store { id: UID } -} +module capy::utility; + +/// A capability which grants Capy Manager permission to add +/// new genes and manage the Capy Market +public struct CapyManagerCap has key, store { id: UID } ``` ## Typical objects with data duplication @@ -186,15 +186,15 @@ In some cases, users mint in-game items when a game allows them or when they pur The following example demonstrates how to create a Capy: ```move -module capy::capy_items { - use std::string::String; - - /// A wearable Capy item. For some items there can be an - /// unlimited supply. And items with the same name are identical. - public struct CapyItem has key, store { - id: UID, - name: String - } +module capy::capy_items; + +use std::string::String; + +/// A wearable Capy item. For some items there can be an +/// unlimited supply. And items with the same name are identical. +public struct CapyItem has key, store { + id: UID, + name: String } ``` @@ -207,14 +207,14 @@ To implement this, the Capys game API service refreshes the image in response to The following example demonstrates how to implement dynamic image generation: ```move -module capy::capy { - /// A Capy - very diverse object with different combination - /// of genes. Created dynamically + for images a dynamic SVG - /// generation is used. - public struct Capy has key, store { - id: UID, - genes: vector - } +module capy::capy; + +/// A Capy - very diverse object with different combination +/// of genes. Created dynamically + for images a dynamic SVG +/// generation is used. +public struct Capy has key, store { + id: UID, + genes: vector } ``` @@ -223,16 +223,16 @@ module capy::capy { This is the simplest scenario - an object represents everything itself. It is very easy to apply a metadata standard to an object of this kind, especially if the object stays immutable forever. However, if the metadata standard evolves and some ecosystem projects add new features for some properties, this object always stays in its original form and might require backward-compatible changes. ```move -module sui::devnet_nft { - use std::string::String; - - /// A Collectible with a static data. URL, name, description are - /// set only once on a mint event - public struct DevNetNFT has key, store { - id: UID, - name: String, - description: String, - url: String, - } +module sui::devnet_nft; + +use std::string::String; + +/// A Collectible with a static data. URL, name, description are +/// set only once on a mint event +public struct DevNetNFT has key, store { + id: UID, + name: String, + description: String, + url: String, } ```