Skip to content

Commit

Permalink
[NFT Standard] (#963)
Browse files Browse the repository at this point in the history
  • Loading branch information
WGB5445 authored Oct 21, 2023
1 parent cd623a9 commit d7b1870
Show file tree
Hide file tree
Showing 11 changed files with 940 additions and 3 deletions.
1 change: 1 addition & 0 deletions crates/rooch-framework/doc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ This is the reference documentation of the Rooch Framework.
- [`0x3::coin_store`](coin_store.md#0x3_coin_store)
- [`0x3::core_addresses`](core_addresses.md#0x3_core_addresses)
- [`0x3::decoding`](decoding.md#0x3_decoding)
- [`0x3::display`](display.md#0x3_display)
- [`0x3::ecdsa_k1`](ecdsa_k1.md#0x3_ecdsa_k1)
- [`0x3::ecdsa_k1_recoverable`](ecdsa_k1_recoverable.md#0x3_ecdsa_k1_recoverable)
- [`0x3::ed25519`](ed25519.md#0x3_ed25519)
Expand Down
253 changes: 253 additions & 0 deletions crates/rooch-framework/doc/display.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,253 @@

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

# Module `0x3::display`



- [Resource `Display`](#0x3_display_Display)
- [Function `new`](#0x3_display_new)
- [Function `set`](#0x3_display_set)
- [Function `borrow`](#0x3_display_borrow)
- [Function `borrow_mut`](#0x3_display_borrow_mut)
- [Function `remove`](#0x3_display_remove)
- [Function `keys`](#0x3_display_keys)
- [Function `values`](#0x3_display_values)
- [Function `contains_key`](#0x3_display_contains_key)


<pre><code><b>use</b> <a href="">0x1::string</a>;
<b>use</b> <a href="">0x2::context</a>;
<b>use</b> <a href="">0x2::object_ref</a>;
<b>use</b> <a href="">0x2::simple_map</a>;
</code></pre>



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

## Resource `Display`



<pre><code><b>struct</b> <a href="display.md#0x3_display_Display">Display</a>&lt;T&gt; <b>has</b> <b>copy</b>, drop, store, key
</code></pre>



<details>
<summary>Fields</summary>


<dl>
<dt>
<code>sample_map: <a href="_SimpleMap">simple_map::SimpleMap</a>&lt;<a href="_String">string::String</a>, <a href="_String">string::String</a>&gt;</code>
</dt>
<dd>

</dd>
</dl>


</details>

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

## Function `new`



<pre><code><b>public</b> <b>fun</b> <a href="display.md#0x3_display_new">new</a>&lt;T&gt;(ctx: &<b>mut</b> <a href="_Context">context::Context</a>): <a href="_ObjectRef">object_ref::ObjectRef</a>&lt;<a href="display.md#0x3_display_Display">display::Display</a>&lt;T&gt;&gt;
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="display.md#0x3_display_new">new</a>&lt;T&gt;(ctx: &<b>mut</b> Context): ObjectRef&lt;<a href="display.md#0x3_display_Display">Display</a>&lt;T&gt;&gt; {
<a href="_new_singleton_object">context::new_singleton_object</a>(ctx, <a href="display.md#0x3_display_Display">Display</a>&lt;T&gt; {
sample_map: <a href="_create">simple_map::create</a>()
})
}
</code></pre>



</details>

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

## Function `set`



<pre><code><b>public</b> <b>fun</b> <a href="display.md#0x3_display_set">set</a>&lt;T&gt;(self: &<b>mut</b> <a href="_ObjectRef">object_ref::ObjectRef</a>&lt;<a href="display.md#0x3_display_Display">display::Display</a>&lt;T&gt;&gt;, key: <a href="_String">string::String</a>, value: <a href="_String">string::String</a>)
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="display.md#0x3_display_set">set</a>&lt;T&gt;(self: &<b>mut</b> ObjectRef&lt;<a href="display.md#0x3_display_Display">Display</a>&lt;T&gt;&gt;, key: String, value: String) {
<b>let</b> display_ref = <a href="_borrow_mut">object_ref::borrow_mut</a>(self);
<a href="_add">simple_map::add</a>(&<b>mut</b> display_ref.sample_map, key, value);
}
</code></pre>



</details>

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

## Function `borrow`



<pre><code><b>public</b> <b>fun</b> <a href="display.md#0x3_display_borrow">borrow</a>&lt;T&gt;(self: &<a href="_ObjectRef">object_ref::ObjectRef</a>&lt;<a href="display.md#0x3_display_Display">display::Display</a>&lt;T&gt;&gt;, key: &<a href="_String">string::String</a>): &<a href="_String">string::String</a>
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="display.md#0x3_display_borrow">borrow</a>&lt;T&gt;(self: & ObjectRef&lt;<a href="display.md#0x3_display_Display">Display</a>&lt;T&gt;&gt; , key: &String): &String {
<b>let</b> display_ref = <a href="_borrow">object_ref::borrow</a>(self);
<a href="_borrow">simple_map::borrow</a>(&display_ref.sample_map, key)
}
</code></pre>



</details>

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

## Function `borrow_mut`



<pre><code><b>public</b> <b>fun</b> <a href="display.md#0x3_display_borrow_mut">borrow_mut</a>&lt;T&gt;(self: &<b>mut</b> <a href="_ObjectRef">object_ref::ObjectRef</a>&lt;<a href="display.md#0x3_display_Display">display::Display</a>&lt;T&gt;&gt;, key: &<a href="_String">string::String</a>): &<b>mut</b> <a href="_String">string::String</a>
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="display.md#0x3_display_borrow_mut">borrow_mut</a>&lt;T&gt;(self: &<b>mut</b> ObjectRef&lt;<a href="display.md#0x3_display_Display">Display</a>&lt;T&gt;&gt;, key: &String): &<b>mut</b> String {
<b>let</b> display_ref = <a href="_borrow_mut">object_ref::borrow_mut</a>(self);
<a href="_borrow_mut">simple_map::borrow_mut</a>(&<b>mut</b> display_ref.sample_map, key)
}
</code></pre>



</details>

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

## Function `remove`



<pre><code><b>public</b> <b>fun</b> <a href="display.md#0x3_display_remove">remove</a>&lt;T&gt;(self: &<b>mut</b> <a href="_ObjectRef">object_ref::ObjectRef</a>&lt;<a href="display.md#0x3_display_Display">display::Display</a>&lt;T&gt;&gt;, key: &<a href="_String">string::String</a>)
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="display.md#0x3_display_remove">remove</a>&lt;T&gt;(self: &<b>mut</b> ObjectRef&lt;<a href="display.md#0x3_display_Display">Display</a>&lt;T&gt;&gt;, key: &String) {
<b>let</b> display_ref = <a href="_borrow_mut">object_ref::borrow_mut</a>(self);
<a href="_remove">simple_map::remove</a>(&<b>mut</b> display_ref.sample_map, key);
}
</code></pre>



</details>

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

## Function `keys`



<pre><code><b>public</b> <b>fun</b> <a href="display.md#0x3_display_keys">keys</a>&lt;T&gt;(self: &<a href="_ObjectRef">object_ref::ObjectRef</a>&lt;<a href="display.md#0x3_display_Display">display::Display</a>&lt;T&gt;&gt;): <a href="">vector</a>&lt;<a href="_String">string::String</a>&gt;
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="display.md#0x3_display_keys">keys</a>&lt;T&gt;(self: & ObjectRef&lt;<a href="display.md#0x3_display_Display">Display</a>&lt;T&gt;&gt;): <a href="">vector</a>&lt;String&gt; {
<b>let</b> display_ref = <a href="_borrow">object_ref::borrow</a>(self);
<a href="_keys">simple_map::keys</a>(& display_ref.sample_map)
}
</code></pre>



</details>

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

## Function `values`



<pre><code><b>public</b> <b>fun</b> <a href="display.md#0x3_display_values">values</a>&lt;T&gt;(self: &<a href="_ObjectRef">object_ref::ObjectRef</a>&lt;<a href="display.md#0x3_display_Display">display::Display</a>&lt;T&gt;&gt;): <a href="">vector</a>&lt;<a href="_String">string::String</a>&gt;
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="display.md#0x3_display_values">values</a>&lt;T&gt;(self: & ObjectRef&lt;<a href="display.md#0x3_display_Display">Display</a>&lt;T&gt;&gt;): <a href="">vector</a>&lt;String&gt; {
<b>let</b> display_ref = <a href="_borrow">object_ref::borrow</a>(self);
<a href="_values">simple_map::values</a>(& display_ref.sample_map)
}
</code></pre>



</details>

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

## Function `contains_key`



<pre><code><b>public</b> <b>fun</b> <a href="display.md#0x3_display_contains_key">contains_key</a>&lt;T&gt;(self: &<a href="_ObjectRef">object_ref::ObjectRef</a>&lt;<a href="display.md#0x3_display_Display">display::Display</a>&lt;T&gt;&gt;, key: &<a href="_String">string::String</a>): bool
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="display.md#0x3_display_contains_key">contains_key</a>&lt;T&gt;(self: & ObjectRef&lt;<a href="display.md#0x3_display_Display">Display</a>&lt;T&gt;&gt;, key: &String): bool {
<b>let</b> display_ref = <a href="_borrow">object_ref::borrow</a>(self);
<a href="_contains_key">simple_map::contains_key</a>(& display_ref.sample_map, key)
}
</code></pre>



</details>
54 changes: 54 additions & 0 deletions crates/rooch-framework/sources/display.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
module rooch_framework::display{
use std::string::String;
use moveos_std::object_ref;
use moveos_std::context::Context;
use moveos_std::context;
use moveos_std::object_ref::ObjectRef;
use moveos_std::simple_map;

struct Display<phantom T> has key, store,drop,copy {
sample_map: simple_map::SimpleMap<String, String>
}

public fun new<T>(ctx: &mut Context): ObjectRef<Display<T>> {
context::new_singleton_object(ctx, Display<T> {
sample_map: simple_map::create()
})
}

public fun set<T>(self: &mut ObjectRef<Display<T>>, key: String, value: String) {
let display_ref = object_ref::borrow_mut(self);
simple_map::add(&mut display_ref.sample_map, key, value);
}

public fun borrow<T>(self: & ObjectRef<Display<T>> , key: &String): &String {
let display_ref = object_ref::borrow(self);
simple_map::borrow(&display_ref.sample_map, key)
}

public fun borrow_mut<T>(self: &mut ObjectRef<Display<T>>, key: &String): &mut String {
let display_ref = object_ref::borrow_mut(self);
simple_map::borrow_mut(&mut display_ref.sample_map, key)
}

public fun remove<T>(self: &mut ObjectRef<Display<T>>, key: &String) {
let display_ref = object_ref::borrow_mut(self);
simple_map::remove(&mut display_ref.sample_map, key);
}

public fun keys<T>(self: & ObjectRef<Display<T>>): vector<String> {
let display_ref = object_ref::borrow(self);
simple_map::keys(& display_ref.sample_map)
}

public fun values<T>(self: & ObjectRef<Display<T>>): vector<String> {
let display_ref = object_ref::borrow(self);
simple_map::values(& display_ref.sample_map)
}

public fun contains_key<T>(self: & ObjectRef<Display<T>>, key: &String): bool {
let display_ref = object_ref::borrow(self);
simple_map::contains_key(& display_ref.sample_map, key)
}

}
14 changes: 14 additions & 0 deletions examples/nft/Move.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "nft"
version = "0.0.1"

[dependencies]
MoveStdlib = { local = "../../moveos/moveos-stdlib/move-stdlib" }
MoveosStdlib = { local = "../../moveos/moveos-stdlib/moveos-stdlib" }
RoochFramework = { local = "../../crates/rooch-framework" }

[addresses]
nft = "_"

[dev-addresses]
nft = "0x42"
Empty file added examples/nft/README.md
Empty file.
Loading

0 comments on commit d7b1870

Please sign in to comment.