Skip to content

Commit

Permalink
chore(merge): Implemented a Display object for the Stardust Nft type
Browse files Browse the repository at this point in the history
  • Loading branch information
valeriyr authored Apr 29, 2024
2 parents 4029e4d + 40cf2d9 commit 10b8c72
Show file tree
Hide file tree
Showing 6 changed files with 166 additions and 5 deletions.
2 changes: 1 addition & 1 deletion crates/sui-framework/docs/stardust/alias.md
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ Get the Alias's id.
<summary>Implementation</summary>


<pre><code><b>public</b>(package) <b>fun</b> <a href="alias.md#0x107a_alias_id">id</a>(self: &<b>mut</b> <a href="alias.md#0x107a_alias_Alias">Alias</a>): &<b>mut</b> UID {
<pre><code><b>public</b>(<a href="../sui-framework/package.md#0x2_package">package</a>) <b>fun</b> <a href="alias.md#0x107a_alias_id">id</a>(self: &<b>mut</b> <a href="alias.md#0x107a_alias_Alias">Alias</a>): &<b>mut</b> UID {
&<b>mut</b> self.id
}
</code></pre>
Expand Down
2 changes: 1 addition & 1 deletion crates/sui-framework/docs/stardust/alias_output.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ Other modules in the Stardust package can call this function to receive an <code
<summary>Implementation</summary>


<pre><code><b>public</b>(package) <b>fun</b> <a href="alias_output.md#0x107a_alias_output_receive">receive</a>(parent: &<b>mut</b> UID, output: Receiving&lt;<a href="alias_output.md#0x107a_alias_output_AliasOutput">AliasOutput</a>&gt;) : <a href="alias_output.md#0x107a_alias_output_AliasOutput">AliasOutput</a> {
<pre><code><b>public</b>(<a href="../sui-framework/package.md#0x2_package">package</a>) <b>fun</b> <a href="alias_output.md#0x107a_alias_output_receive">receive</a>(parent: &<b>mut</b> UID, output: Receiving&lt;<a href="alias_output.md#0x107a_alias_output_AliasOutput">AliasOutput</a>&gt;) : <a href="alias_output.md#0x107a_alias_output_AliasOutput">AliasOutput</a> {
<a href="../sui-framework/transfer.md#0x2_transfer_receive">transfer::receive</a>(parent, output)
}
</code></pre>
Expand Down
2 changes: 1 addition & 1 deletion crates/sui-framework/docs/stardust/basic_output.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ Other modules in the Stardust package can call this function to receive a basic
<summary>Implementation</summary>


<pre><code><b>public</b>(package) <b>fun</b> <a href="basic_output.md#0x107a_basic_output_receive">receive</a>(parent: &<b>mut</b> UID, output: Receiving&lt;<a href="basic_output.md#0x107a_basic_output_BasicOutput">BasicOutput</a>&gt;) : <a href="basic_output.md#0x107a_basic_output_BasicOutput">BasicOutput</a> {
<pre><code><b>public</b>(<a href="../sui-framework/package.md#0x2_package">package</a>) <b>fun</b> <a href="basic_output.md#0x107a_basic_output_receive">receive</a>(parent: &<b>mut</b> UID, output: Receiving&lt;<a href="basic_output.md#0x107a_basic_output_BasicOutput">BasicOutput</a>&gt;) : <a href="basic_output.md#0x107a_basic_output_BasicOutput">BasicOutput</a> {
<a href="../sui-framework/transfer.md#0x2_transfer_receive">transfer::receive</a>(parent, output)
}
</code></pre>
Expand Down
106 changes: 105 additions & 1 deletion crates/sui-framework/docs/stardust/nft.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ title: Module `0x107a::nft`



- [Struct `NFT`](#0x107a_nft_NFT)
- [Resource `Nft`](#0x107a_nft_Nft)
- [Function `init`](#0x107a_nft_init)
- [Function `destroy`](#0x107a_nft_destroy)
- [Function `legacy_sender`](#0x107a_nft_legacy_sender)
- [Function `metadata`](#0x107a_nft_metadata)
Expand All @@ -16,11 +18,44 @@ title: Module `0x107a::nft`

<pre><code><b>use</b> <a href="irc27.md#0x107a_irc27">0x107a::irc27</a>;
<b>use</b> <a href="../move-stdlib/option.md#0x1_option">0x1::option</a>;
<b>use</b> <a href="../move-stdlib/string.md#0x1_string">0x1::string</a>;
<b>use</b> <a href="../sui-framework/display.md#0x2_display">0x2::display</a>;
<b>use</b> <a href="../sui-framework/object.md#0x2_object">0x2::object</a>;
<b>use</b> <a href="../sui-framework/package.md#0x2_package">0x2::package</a>;
<b>use</b> <a href="../sui-framework/transfer.md#0x2_transfer">0x2::transfer</a>;
<b>use</b> <a href="../sui-framework/tx_context.md#0x2_tx_context">0x2::tx_context</a>;
</code></pre>



<a name="0x107a_nft_NFT"></a>

## Struct `NFT`

One Time Witness.


<pre><code><b>struct</b> <a href="nft.md#0x107a_nft_NFT">NFT</a> <b>has</b> drop
</code></pre>



<details>
<summary>Fields</summary>


<dl>
<dt>
<code>dummy_field: bool</code>
</dt>
<dd>

</dd>
</dl>


</details>

<a name="0x107a_nft_Nft"></a>

## Resource `Nft`
Expand Down Expand Up @@ -78,6 +113,75 @@ The Stardust NFT representation.
</dl>


</details>

<a name="0x107a_nft_init"></a>

## Function `init`

The <code><a href="nft.md#0x107a_nft_Nft">Nft</a></code> module initializer.


<pre><code><b>fun</b> <a href="nft.md#0x107a_nft_init">init</a>(otw: <a href="nft.md#0x107a_nft_NFT">nft::NFT</a>, ctx: &<b>mut</b> <a href="../sui-framework/tx_context.md#0x2_tx_context_TxContext">tx_context::TxContext</a>)
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>fun</b> <a href="nft.md#0x107a_nft_init">init</a>(otw: <a href="nft.md#0x107a_nft_NFT">NFT</a>, ctx: &<b>mut</b> TxContext) {
// Claim the <b>module</b> publisher.
<b>let</b> publisher = <a href="../sui-framework/package.md#0x2_package_claim">package::claim</a>(otw, ctx);

// Build a `Display` <a href="../sui-framework/object.md#0x2_object">object</a>.
<b>let</b> keys = <a href="../move-stdlib/vector.md#0x1_vector">vector</a>[
// The Sui standard fields.
<a href="../move-stdlib/string.md#0x1_string_utf8">string::utf8</a>(b"name"),
<a href="../move-stdlib/string.md#0x1_string_utf8">string::utf8</a>(b"image_url"),
<a href="../move-stdlib/string.md#0x1_string_utf8">string::utf8</a>(b"description"),
<a href="../move-stdlib/string.md#0x1_string_utf8">string::utf8</a>(b"creator"),

// The extra IRC27-nested fileds.
<a href="../move-stdlib/string.md#0x1_string_utf8">string::utf8</a>(b"version"),
<a href="../move-stdlib/string.md#0x1_string_utf8">string::utf8</a>(b"media_type"),
<a href="../move-stdlib/string.md#0x1_string_utf8">string::utf8</a>(b"collection_name"),
];

<b>let</b> values = <a href="../move-stdlib/vector.md#0x1_vector">vector</a>[
// The Sui standard fields.
<a href="../move-stdlib/string.md#0x1_string_utf8">string::utf8</a>(b"{immutable_metadata.name}"),
<a href="../move-stdlib/string.md#0x1_string_utf8">string::utf8</a>(b"{immutable_metadata.uri}"),
<a href="../move-stdlib/string.md#0x1_string_utf8">string::utf8</a>(b"{immutable_metadata.description}"),
<a href="../move-stdlib/string.md#0x1_string_utf8">string::utf8</a>(b"{immutable_metadata.issuer_name}"),

// The extra IRC27-nested fileds.
<a href="../move-stdlib/string.md#0x1_string_utf8">string::utf8</a>(b"{immutable_metadata.version}"),
<a href="../move-stdlib/string.md#0x1_string_utf8">string::utf8</a>(b"{immutable_metadata.media_type}"),
<a href="../move-stdlib/string.md#0x1_string_utf8">string::utf8</a>(b"{immutable_metadata.collection_name}"),
];

<b>let</b> <b>mut</b> <a href="../sui-framework/display.md#0x2_display">display</a> = <a href="../sui-framework/display.md#0x2_display_new_with_fields">display::new_with_fields</a>&lt;<a href="nft.md#0x107a_nft_Nft">Nft</a>&gt;(
&publisher,
keys,
values,
ctx
);

// Commit the first version of `Display` <b>to</b> <b>apply</b> changes.
<a href="../sui-framework/display.md#0x2_display">display</a>.update_version();

// Burn the publisher <a href="../sui-framework/object.md#0x2_object">object</a>.
<a href="../sui-framework/package.md#0x2_package_burn_publisher">package::burn_publisher</a>(publisher);

// Freeze the <a href="../sui-framework/display.md#0x2_display">display</a> <a href="../sui-framework/object.md#0x2_object">object</a>.
sui::transfer::public_freeze_object(<a href="../sui-framework/display.md#0x2_display">display</a>);
}
</code></pre>



</details>

<a name="0x107a_nft_destroy"></a>
Expand Down Expand Up @@ -257,7 +361,7 @@ Get the Nft's id.
<summary>Implementation</summary>


<pre><code><b>public</b>(package) <b>fun</b> <a href="nft.md#0x107a_nft_id">id</a>(self: &<b>mut</b> <a href="nft.md#0x107a_nft_Nft">Nft</a>): &<b>mut</b> UID {
<pre><code><b>public</b>(<a href="../sui-framework/package.md#0x2_package">package</a>) <b>fun</b> <a href="nft.md#0x107a_nft_id">id</a>(self: &<b>mut</b> <a href="nft.md#0x107a_nft_Nft">Nft</a>): &<b>mut</b> UID {
&<b>mut</b> self.id
}
</code></pre>
Expand Down
2 changes: 1 addition & 1 deletion crates/sui-framework/docs/stardust/nft_output.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ Other modules in the stardust package can call this function to receive an <code
<summary>Implementation</summary>


<pre><code><b>public</b>(package) <b>fun</b> <a href="nft_output.md#0x107a_nft_output_receive">receive</a>(parent: &<b>mut</b> UID, <a href="nft.md#0x107a_nft">nft</a>: Receiving&lt;<a href="nft_output.md#0x107a_nft_output_NftOutput">NftOutput</a>&gt;) : <a href="nft_output.md#0x107a_nft_output_NftOutput">NftOutput</a> {
<pre><code><b>public</b>(<a href="../sui-framework/package.md#0x2_package">package</a>) <b>fun</b> <a href="nft_output.md#0x107a_nft_output_receive">receive</a>(parent: &<b>mut</b> UID, <a href="nft.md#0x107a_nft">nft</a>: Receiving&lt;<a href="nft_output.md#0x107a_nft_output_NftOutput">NftOutput</a>&gt;) : <a href="nft_output.md#0x107a_nft_output_NftOutput">NftOutput</a> {
<a href="../sui-framework/transfer.md#0x2_transfer_receive">transfer::receive</a>(parent, <a href="nft.md#0x107a_nft">nft</a>)
}
</code></pre>
Expand Down
57 changes: 57 additions & 0 deletions crates/sui-framework/packages/stardust/sources/nft/nft.move
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,16 @@

module stardust::nft {

use std::string;

use sui::display;
use sui::package;

use stardust::irc27::{Self, Irc27Metadata};

/// One Time Witness.
public struct NFT has drop {}

/// The Stardust NFT representation.
public struct Nft has key, store {
/// The Nft's ID is nested from Stardust.
Expand All @@ -24,6 +32,55 @@ module stardust::nft {
immutable_metadata: Irc27Metadata,
}

/// The `Nft` module initializer.
fun init(otw: NFT, ctx: &mut TxContext) {
// Claim the module publisher.
let publisher = package::claim(otw, ctx);

// Build a `Display` object.
let keys = vector[
// The Sui standard fields.
string::utf8(b"name"),
string::utf8(b"image_url"),
string::utf8(b"description"),
string::utf8(b"creator"),

// The extra IRC27-nested fileds.
string::utf8(b"version"),
string::utf8(b"media_type"),
string::utf8(b"collection_name"),
];

let values = vector[
// The Sui standard fields.
string::utf8(b"{immutable_metadata.name}"),
string::utf8(b"{immutable_metadata.uri}"),
string::utf8(b"{immutable_metadata.description}"),
string::utf8(b"{immutable_metadata.issuer_name}"),

// The extra IRC27-nested fileds.
string::utf8(b"{immutable_metadata.version}"),
string::utf8(b"{immutable_metadata.media_type}"),
string::utf8(b"{immutable_metadata.collection_name}"),
];

let mut display = display::new_with_fields<Nft>(
&publisher,
keys,
values,
ctx
);

// Commit the first version of `Display` to apply changes.
display.update_version();

// Burn the publisher object.
package::burn_publisher(publisher);

// Freeze the display object.
sui::transfer::public_freeze_object(display);
}

/// Permanently destroy an `Nft` object.
public fun destroy(nft: Nft) {
let Nft {
Expand Down

0 comments on commit 10b8c72

Please sign in to comment.