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
37 changes: 37 additions & 0 deletions 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
16 changes: 16 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 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