Skip to content

Commit

Permalink
added functions to rotate collectiondata fields
Browse files Browse the repository at this point in the history
  • Loading branch information
0xchloe committed Oct 25, 2022
1 parent dba73f3 commit d054fe0
Show file tree
Hide file tree
Showing 3 changed files with 369 additions and 12 deletions.
27 changes: 26 additions & 1 deletion aptos-move/framework/aptos-stdlib/doc/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,32 @@ This is the reference documentation of the Aptos standard library.
## Index


- [Index](#@Index_1)
- [`0x1::any`](any.md#0x1_any)
- [`0x1::aptos_hash`](hash.md#0x1_aptos_hash)
- [`0x1::bcs`](../../move-stdlib/doc/bcs.md#0x1_bcs)
- [`0x1::bls12381`](bls12381.md#0x1_bls12381)
- [`0x1::capability`](capability.md#0x1_capability)
- [`0x1::comparator`](comparator.md#0x1_comparator)
- [`0x1::copyable_any`](copyable_any.md#0x1_copyable_any)
- [`0x1::debug`](debug.md#0x1_debug)
- [`0x1::ed25519`](ed25519.md#0x1_ed25519)
- [`0x1::error`](../../move-stdlib/doc/error.md#0x1_error)
- [`0x1::from_bcs`](from_bcs.md#0x1_from_bcs)
- [`0x1::hash`](../../move-stdlib/doc/hash.md#0x1_hash)
- [`0x1::math128`](math128.md#0x1_math128)
- [`0x1::math64`](math64.md#0x1_math64)
- [`0x1::multi_ed25519`](multi_ed25519.md#0x1_multi_ed25519)
- [`0x1::option`](../../move-stdlib/doc/option.md#0x1_option)
- [`0x1::pool_u64`](pool_u64.md#0x1_pool_u64)
- [`0x1::ristretto255`](ristretto255.md#0x1_ristretto255)
- [`0x1::secp256k1`](secp256k1.md#0x1_secp256k1)
- [`0x1::signer`](../../move-stdlib/doc/signer.md#0x1_signer)
- [`0x1::simple_map`](simple_map.md#0x1_simple_map)
- [`0x1::string`](../../move-stdlib/doc/string.md#0x1_string)
- [`0x1::table`](table.md#0x1_table)
- [`0x1::table_with_length`](table_with_length.md#0x1_table_with_length)
- [`0x1::type_info`](type_info.md#0x1_type_info)
- [`0x1::vector`](../../move-stdlib/doc/vector.md#0x1_vector)


[move-book]: https://move-language.github.io/move/introduction.html
214 changes: 210 additions & 4 deletions aptos-move/framework/aptos-token/doc/token.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ Checkout our developer doc on our token standard https://aptos.dev/concepts/coin
- [Function `burn`](#0x3_token_burn)
- [Function `mutate_one_token`](#0x3_token_mutate_one_token)
- [Function `create_royalty`](#0x3_token_create_royalty)
- [Function `assert_collection_exists`](#0x3_token_assert_collection_exists)
- [Function `mutate_collection_description`](#0x3_token_mutate_collection_description)
- [Function `mutate_collection_uri`](#0x3_token_mutate_collection_uri)
- [Function `mutate_collection_maximum`](#0x3_token_mutate_collection_maximum)
- [Function `assert_tokendata_exists`](#0x3_token_assert_tokendata_exists)
- [Function `mutate_tokendata_maximum`](#0x3_token_mutate_tokendata_maximum)
- [Function `mutate_tokendata_uri`](#0x3_token_mutate_tokendata_uri)
Expand All @@ -59,6 +63,9 @@ Checkout our developer doc on our token standard https://aptos.dev/concepts/coin
- [Function `check_tokendata_exists`](#0x3_token_check_tokendata_exists)
- [Function `create_tokendata`](#0x3_token_create_tokendata)
- [Function `get_collection_supply`](#0x3_token_get_collection_supply)
- [Function `get_collection_description`](#0x3_token_get_collection_description)
- [Function `get_collection_uri`](#0x3_token_get_collection_uri)
- [Function `get_collection_maximum`](#0x3_token_get_collection_maximum)
- [Function `get_token_supply`](#0x3_token_get_token_supply)
- [Function `get_tokendata_largest_property_version`](#0x3_token_get_tokendata_largest_property_version)
- [Function `get_token_id`](#0x3_token_get_token_id)
Expand Down Expand Up @@ -1123,6 +1130,16 @@ The field is not mutable



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

Collection maximum must be larger than supply


<pre><code><b>const</b> <a href="token.md#0x3_token_EINVALID_COLLECTION_MAXIMUM">EINVALID_COLLECTION_MAXIMUM</a>: u64 = 36;
</code></pre>



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

Royalty invalid if the numerator is larger than the denominator
Expand Down Expand Up @@ -2026,6 +2043,119 @@ Burn a token by the token owner



</details>

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

## Function `assert_collection_exists`



<pre><code><b>fun</b> <a href="token.md#0x3_token_assert_collection_exists">assert_collection_exists</a>(creator_address: <b>address</b>, collection_name: <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/string.md#0x1_string_String">string::String</a>)
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>fun</b> <a href="token.md#0x3_token_assert_collection_exists">assert_collection_exists</a>(creator_address: <b>address</b>, collection_name: String) <b>acquires</b> <a href="token.md#0x3_token_Collections">Collections</a> {
<b>assert</b>!(<b>exists</b>&lt;<a href="token.md#0x3_token_Collections">Collections</a>&gt;(creator_address), <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/error.md#0x1_error_not_found">error::not_found</a>(<a href="token.md#0x3_token_ECOLLECTIONS_NOT_PUBLISHED">ECOLLECTIONS_NOT_PUBLISHED</a>));
<b>let</b> all_collection_data = &<b>borrow_global</b>&lt;<a href="token.md#0x3_token_Collections">Collections</a>&gt;(creator_address).collection_data;
<b>assert</b>!(<a href="../../aptos-framework/../aptos-stdlib/doc/table.md#0x1_table_contains">table::contains</a>(all_collection_data, collection_name), <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/error.md#0x1_error_not_found">error::not_found</a>(<a href="token.md#0x3_token_ECOLLECTION_NOT_PUBLISHED">ECOLLECTION_NOT_PUBLISHED</a>));
}
</code></pre>



</details>

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

## Function `mutate_collection_description`



<pre><code><b>public</b> <b>fun</b> <a href="token.md#0x3_token_mutate_collection_description">mutate_collection_description</a>(creator: &<a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>, collection_name: <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/string.md#0x1_string_String">string::String</a>, description: <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/string.md#0x1_string_String">string::String</a>)
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="token.md#0x3_token_mutate_collection_description">mutate_collection_description</a>(creator: &<a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>, collection_name: String, description: String) <b>acquires</b> <a href="token.md#0x3_token_Collections">Collections</a> {
<b>let</b> creator_address = <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer_address_of">signer::address_of</a>(creator);
<a href="token.md#0x3_token_assert_collection_exists">assert_collection_exists</a>(creator_address, collection_name);
<b>let</b> collection_data = <a href="../../aptos-framework/../aptos-stdlib/doc/table.md#0x1_table_borrow_mut">table::borrow_mut</a>(&<b>mut</b> <b>borrow_global_mut</b>&lt;<a href="token.md#0x3_token_Collections">Collections</a>&gt;(creator_address).collection_data, collection_name);
<b>assert</b>!(collection_data.mutability_config.description, <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/error.md#0x1_error_permission_denied">error::permission_denied</a>(<a href="token.md#0x3_token_EFIELD_NOT_MUTABLE">EFIELD_NOT_MUTABLE</a>));
collection_data.description = description;
}
</code></pre>



</details>

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

## Function `mutate_collection_uri`



<pre><code><b>public</b> <b>fun</b> <a href="token.md#0x3_token_mutate_collection_uri">mutate_collection_uri</a>(creator: &<a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>, collection_name: <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/string.md#0x1_string_String">string::String</a>, uri: <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/string.md#0x1_string_String">string::String</a>)
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="token.md#0x3_token_mutate_collection_uri">mutate_collection_uri</a>(creator: &<a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>, collection_name: String, uri: String) <b>acquires</b> <a href="token.md#0x3_token_Collections">Collections</a> {
<b>assert</b>!(<a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/string.md#0x1_string_length">string::length</a>(&uri) &lt;= <a href="token.md#0x3_token_MAX_URI_LENGTH">MAX_URI_LENGTH</a>, <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/error.md#0x1_error_invalid_argument">error::invalid_argument</a>(<a href="token.md#0x3_token_EURI_TOO_LONG">EURI_TOO_LONG</a>));
<b>let</b> creator_address = <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer_address_of">signer::address_of</a>(creator);
<a href="token.md#0x3_token_assert_collection_exists">assert_collection_exists</a>(creator_address, collection_name);
<b>let</b> collection_data = <a href="../../aptos-framework/../aptos-stdlib/doc/table.md#0x1_table_borrow_mut">table::borrow_mut</a>(&<b>mut</b> <b>borrow_global_mut</b>&lt;<a href="token.md#0x3_token_Collections">Collections</a>&gt;(creator_address).collection_data, collection_name);
<b>assert</b>!(collection_data.mutability_config.uri, <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/error.md#0x1_error_permission_denied">error::permission_denied</a>(<a href="token.md#0x3_token_EFIELD_NOT_MUTABLE">EFIELD_NOT_MUTABLE</a>));
collection_data.uri = uri;
}
</code></pre>



</details>

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

## Function `mutate_collection_maximum`



<pre><code><b>public</b> <b>fun</b> <a href="token.md#0x3_token_mutate_collection_maximum">mutate_collection_maximum</a>(creator: &<a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>, collection_name: <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/string.md#0x1_string_String">string::String</a>, maximum: u64)
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="token.md#0x3_token_mutate_collection_maximum">mutate_collection_maximum</a>(creator: &<a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>, collection_name: String, maximum: u64) <b>acquires</b> <a href="token.md#0x3_token_Collections">Collections</a> {
<b>let</b> creator_address = <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer_address_of">signer::address_of</a>(creator);
<b>let</b> supply = <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/option.md#0x1_option_extract">option::extract</a>(&<b>mut</b> <a href="token.md#0x3_token_get_collection_supply">get_collection_supply</a>(creator_address, collection_name));
<b>assert</b>!(maximum &gt; supply, <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/error.md#0x1_error_invalid_argument">error::invalid_argument</a>(<a href="token.md#0x3_token_EINVALID_COLLECTION_MAXIMUM">EINVALID_COLLECTION_MAXIMUM</a>));
<a href="token.md#0x3_token_assert_collection_exists">assert_collection_exists</a>(creator_address, collection_name);
<b>let</b> collection_data = <a href="../../aptos-framework/../aptos-stdlib/doc/table.md#0x1_table_borrow_mut">table::borrow_mut</a>(&<b>mut</b> <b>borrow_global_mut</b>&lt;<a href="token.md#0x3_token_Collections">Collections</a>&gt;(creator_address).collection_data, collection_name);
<b>assert</b>!(collection_data.mutability_config.maximum, <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/error.md#0x1_error_permission_denied">error::permission_denied</a>(<a href="token.md#0x3_token_EFIELD_NOT_MUTABLE">EFIELD_NOT_MUTABLE</a>));
collection_data.maximum = maximum;
}
</code></pre>



</details>

<a name="0x3_token_assert_tokendata_exists"></a>
Expand Down Expand Up @@ -2806,10 +2936,8 @@ return the number of distinct token_data_id created under this collection


<pre><code><b>public</b> <b>fun</b> <a href="token.md#0x3_token_get_collection_supply">get_collection_supply</a>(creator_address: <b>address</b>, collection_name: String): Option&lt;u64&gt; <b>acquires</b> <a href="token.md#0x3_token_Collections">Collections</a> {
<b>assert</b>!(<b>exists</b>&lt;<a href="token.md#0x3_token_Collections">Collections</a>&gt;(creator_address), <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/error.md#0x1_error_not_found">error::not_found</a>(<a href="token.md#0x3_token_ECOLLECTIONS_NOT_PUBLISHED">ECOLLECTIONS_NOT_PUBLISHED</a>));
<b>let</b> collections = &<b>borrow_global</b>&lt;<a href="token.md#0x3_token_Collections">Collections</a>&gt;(creator_address).collection_data;
<b>assert</b>!(<a href="../../aptos-framework/../aptos-stdlib/doc/table.md#0x1_table_contains">table::contains</a>(collections, collection_name), <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/error.md#0x1_error_not_found">error::not_found</a>(<a href="token.md#0x3_token_ECOLLECTION_NOT_PUBLISHED">ECOLLECTION_NOT_PUBLISHED</a>));
<b>let</b> collection_data = <a href="../../aptos-framework/../aptos-stdlib/doc/table.md#0x1_table_borrow">table::borrow</a>(collections, collection_name);
<a href="token.md#0x3_token_assert_collection_exists">assert_collection_exists</a>(creator_address, collection_name);
<b>let</b> collection_data = <a href="../../aptos-framework/../aptos-stdlib/doc/table.md#0x1_table_borrow_mut">table::borrow_mut</a>(&<b>mut</b> <b>borrow_global_mut</b>&lt;<a href="token.md#0x3_token_Collections">Collections</a>&gt;(creator_address).collection_data, collection_name);

<b>if</b> (collection_data.maximum &gt; 0) {
<a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/option.md#0x1_option_some">option::some</a>(collection_data.supply)
Expand All @@ -2821,6 +2949,84 @@ return the number of distinct token_data_id created under this collection



</details>

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

## Function `get_collection_description`



<pre><code><b>public</b> <b>fun</b> <a href="token.md#0x3_token_get_collection_description">get_collection_description</a>(creator_address: <b>address</b>, collection_name: <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/string.md#0x1_string_String">string::String</a>): <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/string.md#0x1_string_String">string::String</a>
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="token.md#0x3_token_get_collection_description">get_collection_description</a>(creator_address: <b>address</b>, collection_name: String): String <b>acquires</b> <a href="token.md#0x3_token_Collections">Collections</a> {
<a href="token.md#0x3_token_assert_collection_exists">assert_collection_exists</a>(creator_address, collection_name);
<b>let</b> collection_data = <a href="../../aptos-framework/../aptos-stdlib/doc/table.md#0x1_table_borrow_mut">table::borrow_mut</a>(&<b>mut</b> <b>borrow_global_mut</b>&lt;<a href="token.md#0x3_token_Collections">Collections</a>&gt;(creator_address).collection_data, collection_name);
collection_data.description
}
</code></pre>



</details>

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

## Function `get_collection_uri`



<pre><code><b>public</b> <b>fun</b> <a href="token.md#0x3_token_get_collection_uri">get_collection_uri</a>(creator_address: <b>address</b>, collection_name: <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/string.md#0x1_string_String">string::String</a>): <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/string.md#0x1_string_String">string::String</a>
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="token.md#0x3_token_get_collection_uri">get_collection_uri</a>(creator_address: <b>address</b>, collection_name: String): String <b>acquires</b> <a href="token.md#0x3_token_Collections">Collections</a> {
<a href="token.md#0x3_token_assert_collection_exists">assert_collection_exists</a>(creator_address, collection_name);
<b>let</b> collection_data = <a href="../../aptos-framework/../aptos-stdlib/doc/table.md#0x1_table_borrow_mut">table::borrow_mut</a>(&<b>mut</b> <b>borrow_global_mut</b>&lt;<a href="token.md#0x3_token_Collections">Collections</a>&gt;(creator_address).collection_data, collection_name);
collection_data.uri
}
</code></pre>



</details>

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

## Function `get_collection_maximum`



<pre><code><b>public</b> <b>fun</b> <a href="token.md#0x3_token_get_collection_maximum">get_collection_maximum</a>(creator_address: <b>address</b>, collection_name: <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/string.md#0x1_string_String">string::String</a>): u64
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="token.md#0x3_token_get_collection_maximum">get_collection_maximum</a>(creator_address: <b>address</b>, collection_name: String): u64 <b>acquires</b> <a href="token.md#0x3_token_Collections">Collections</a> {
<a href="token.md#0x3_token_assert_collection_exists">assert_collection_exists</a>(creator_address, collection_name);
<b>let</b> collection_data = <a href="../../aptos-framework/../aptos-stdlib/doc/table.md#0x1_table_borrow_mut">table::borrow_mut</a>(&<b>mut</b> <b>borrow_global_mut</b>&lt;<a href="token.md#0x3_token_Collections">Collections</a>&gt;(creator_address).collection_data, collection_name);
collection_data.maximum
}
</code></pre>



</details>

<a name="0x3_token_get_token_supply"></a>
Expand Down
Loading

0 comments on commit d054fe0

Please sign in to comment.