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

Add create_token method in token.move #8825

Merged
merged 11 commits into from
Jun 26, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ With an existing collection, directly mint a soul bound token into the recipient
property_types: <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/vector.md#0x1_vector">vector</a>&lt;String&gt;,
property_values: <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/vector.md#0x1_vector">vector</a>&lt;<a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/vector.md#0x1_vector">vector</a>&lt;u8&gt;&gt;,
): ConstructorRef <b>acquires</b> <a href="aptos_token.md#0x4_aptos_token_AptosCollection">AptosCollection</a> {
<b>let</b> constructor_ref = <a href="token.md#0x4_token_create_from_account">token::create_from_account</a>(
<b>let</b> constructor_ref = <a href="token.md#0x4_token_create_token">token::create_token</a>(
creator,
<a href="collection.md#0x4_collection">collection</a>,
description,
Expand Down
40 changes: 39 additions & 1 deletion aptos-move/framework/aptos-token-objects/doc/token.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ token are:
- [Struct `MutationEvent`](#0x4_token_MutationEvent)
- [Constants](#@Constants_0)
- [Function `create_common`](#0x4_token_create_common)
- [Function `create_token`](#0x4_token_create_token)
- [Function `create_named_token`](#0x4_token_create_named_token)
- [Function `create_from_account`](#0x4_token_create_from_account)
- [Function `create_token_address`](#0x4_token_create_token_address)
Expand Down Expand Up @@ -361,6 +362,42 @@ The token name is over the maximum length



</details>

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

## Function `create_token`

Creates a new token object with a unique address and returns the ConstructorRef
for additional specialization.


<pre><code><b>public</b> <b>fun</b> <a href="token.md#0x4_token_create_token">create_token</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>, name: <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/string.md#0x1_string_String">string::String</a>, <a href="royalty.md#0x4_royalty">royalty</a>: <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/option.md#0x1_option_Option">option::Option</a>&lt;<a href="royalty.md#0x4_royalty_Royalty">royalty::Royalty</a>&gt;, uri: <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/string.md#0x1_string_String">string::String</a>): <a href="../../aptos-framework/doc/object.md#0x1_object_ConstructorRef">object::ConstructorRef</a>
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="token.md#0x4_token_create_token">create_token</a>(
creator: &<a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>,
collection_name: String,
description: String,
name: String,
<a href="royalty.md#0x4_royalty">royalty</a>: Option&lt;Royalty&gt;,
uri: String,
): ConstructorRef {
<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> constructor_ref = <a href="../../aptos-framework/doc/object.md#0x1_object_create_object">object::create_object</a>(creator_address);
<a href="token.md#0x4_token_create_common">create_common</a>(&constructor_ref, creator_address, collection_name, description, name, <a href="royalty.md#0x4_royalty">royalty</a>, uri);
constructor_ref
}
</code></pre>



</details>

<a name="0x4_token_create_named_token"></a>
Expand Down Expand Up @@ -409,7 +446,8 @@ Creates a new token object from an account GUID and returns the ConstructorRef f
additional specialization.


<pre><code><b>public</b> <b>fun</b> <a href="token.md#0x4_token_create_from_account">create_from_account</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>, name: <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/string.md#0x1_string_String">string::String</a>, <a href="royalty.md#0x4_royalty">royalty</a>: <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/option.md#0x1_option_Option">option::Option</a>&lt;<a href="royalty.md#0x4_royalty_Royalty">royalty::Royalty</a>&gt;, uri: <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/string.md#0x1_string_String">string::String</a>): <a href="../../aptos-framework/doc/object.md#0x1_object_ConstructorRef">object::ConstructorRef</a>
<pre><code>#[deprecated]
<b>public</b> <b>fun</b> <a href="token.md#0x4_token_create_from_account">create_from_account</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>, name: <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/string.md#0x1_string_String">string::String</a>, <a href="royalty.md#0x4_royalty">royalty</a>: <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/option.md#0x1_option_Option">option::Option</a>&lt;<a href="royalty.md#0x4_royalty_Royalty">royalty::Royalty</a>&gt;, uri: <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/string.md#0x1_string_String">string::String</a>): <a href="../../aptos-framework/doc/object.md#0x1_object_ConstructorRef">object::ConstructorRef</a>
</code></pre>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ module aptos_token_objects::aptos_token {
property_types: vector<String>,
property_values: vector<vector<u8>>,
): ConstructorRef acquires AptosCollection {
let constructor_ref = token::create_from_account(
let constructor_ref = token::create_token(
Copy link
Contributor

Choose a reason for hiding this comment

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

This needs to be behind the same feature flag as create_guid otherwise this would always fail before the flag is enabled

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If auids are enabled, I am now calling create method. If auids are disabled, I am calling create_from_account method. Is that okay?

creator,
collection,
description,
Expand Down
17 changes: 17 additions & 0 deletions aptos-move/framework/aptos-token-objects/sources/token.move
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,22 @@ module aptos_token_objects::token {
};
}

/// Creates a new token object with a unique address and returns the ConstructorRef
/// for additional specialization.
public fun create_token(
Copy link
Contributor

Choose a reason for hiding this comment

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

Mark create_from_account as deprecated

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: How about just name this "create"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

creator: &signer,
collection_name: String,
description: String,
name: String,
royalty: Option<Royalty>,
uri: String,
): ConstructorRef {
let creator_address = signer::address_of(creator);
let constructor_ref = object::create_object(creator_address);
create_common(&constructor_ref, creator_address, collection_name, description, name, royalty, uri);
constructor_ref
}

/// Creates a new token object from a token name and returns the ConstructorRef for
/// additional specialization.
public fun create_named_token(
Expand All @@ -124,6 +140,7 @@ module aptos_token_objects::token {
constructor_ref
}

#[deprecated]
/// Creates a new token object from an account GUID and returns the ConstructorRef for
/// additional specialization.
public fun create_from_account(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ module token_objects::ambassador {
// is used to generate the refs of the token.
let uri = base_uri;
string::append(&mut uri, string::utf8(RANK_BRONZE));
let constructor_ref = token::create_named_token(
let constructor_ref = token::create_token(
creator,
collection,
description,
Expand Down