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

[Feature] Public Native name_of function #107

Merged
merged 3 commits into from
Sep 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion build/StarcoinFramework/BuildInfo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,9 @@ compiled_package_info:
? address: "0x00000000000000000000000000000001"
name: TreasuryWithdrawDaoProposal
: StarcoinFramework
? address: "0x00000000000000000000000000000001"
name: TypeInfo
: StarcoinFramework
? address: "0x00000000000000000000000000000001"
name: U256
: StarcoinFramework
Expand All @@ -303,7 +306,7 @@ compiled_package_info:
? address: "0x00000000000000000000000000000001"
name: YieldFarmingV2
: StarcoinFramework
source_digest: 2F6686B5BAFFE5E5DEB6F001CD6D0D8FA93121DB944E71F0E3DCBAB51D81FA90
source_digest: 695F4208154FB109E223367B79D9AD3C30261C91BF6F595A3B9D2226BC5103B0
build_flags:
dev_mode: false
test_mode: false
Expand Down
Binary file modified build/StarcoinFramework/bytecode_modules/Token.mv
Binary file not shown.
1 change: 1 addition & 0 deletions build/StarcoinFramework/docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ This is the root document for the Move StarcoinFramework module documentation. T
- [`0x1::Treasury`](Treasury.md#0x1_Treasury)
- [`0x1::TreasuryScripts`](TreasuryScripts.md#0x1_TreasuryScripts)
- [`0x1::TreasuryWithdrawDaoProposal`](TreasuryWithdrawDaoProposal.md#0x1_TreasuryWithdrawDaoProposal)
- [`0x1::TypeInfo`](TypeInfo.md#0x1_TypeInfo)
- [`0x1::U256`](U256.md#0x1_U256)
- [`0x1::UpgradeModuleDaoProposal`](UpgradeModuleDaoProposal.md#0x1_UpgradeModuleDaoProposal)
- [`0x1::VMConfig`](VMConfig.md#0x1_VMConfig)
Expand Down
29 changes: 27 additions & 2 deletions build/StarcoinFramework/docs/Token.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Token implementation of Starcoin.
- [Function `is_same_token`](#0x1_Token_is_same_token)
- [Function `token_address`](#0x1_Token_token_address)
- [Function `token_code`](#0x1_Token_token_code)
- [Function `type_of`](#0x1_Token_type_of)
- [Function `name_of`](#0x1_Token_name_of)
- [Function `name_of_token`](#0x1_Token_name_of_token)
- [Module Specification](#@Module_Specification_1)
Expand Down Expand Up @@ -1709,6 +1710,30 @@ does not matter for the verification of callers.



</details>

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

## Function `type_of`



<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="Token.md#0x1_Token_type_of">type_of</a>&lt;T&gt;(): (<b>address</b>, vector&lt;u8&gt;, vector&lt;u8&gt;)
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> (<b>friend</b>) <b>fun</b> <a href="Token.md#0x1_Token_type_of">type_of</a>&lt;T&gt;(): (<b>address</b>, vector&lt;u8&gt;, vector&lt;u8&gt;){
<a href="Token.md#0x1_Token_name_of">name_of</a>&lt;T&gt;()
}
</code></pre>



</details>

<a name="0x1_Token_name_of"></a>
Expand All @@ -1718,7 +1743,7 @@ does not matter for the verification of callers.
Return Token's module address, module name, and type name of <code>TokenType</code>.


<pre><code><b>fun</b> <a href="Token.md#0x1_Token_name_of">name_of</a>&lt;TokenType: store&gt;(): (<b>address</b>, vector&lt;u8&gt;, vector&lt;u8&gt;)
<pre><code><b>fun</b> <a href="Token.md#0x1_Token_name_of">name_of</a>&lt;TokenType&gt;(): (<b>address</b>, vector&lt;u8&gt;, vector&lt;u8&gt;)
</code></pre>


Expand All @@ -1727,7 +1752,7 @@ Return Token's module address, module name, and type name of <code>TokenType</co
<summary>Implementation</summary>


<pre><code><b>native</b> <b>fun</b> <a href="Token.md#0x1_Token_name_of">name_of</a>&lt;TokenType: store&gt;(): (<b>address</b>, vector&lt;u8&gt;, vector&lt;u8&gt;);
<pre><code><b>native</b> <b>fun</b> <a href="Token.md#0x1_Token_name_of">name_of</a>&lt;TokenType&gt;(): (<b>address</b>, vector&lt;u8&gt;, vector&lt;u8&gt;);
</code></pre>


Expand Down
Binary file modified build/StarcoinFramework/source_maps/Token.mvsm
Binary file not shown.
7 changes: 6 additions & 1 deletion sources/Token.move
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module Token {
use StarcoinFramework::Errors;
use StarcoinFramework::Math;

friend StarcoinFramework::TypeInfo;
spec module {
pragma verify;
pragma aborts_if_is_strict;
Expand Down Expand Up @@ -504,8 +505,12 @@ module Token {
/// does not matter for the verification of callers.
spec fun spec_token_code<TokenType>(): TokenCode;

public (friend) fun type_of<T>(): (address, vector<u8>, vector<u8>){
name_of<T>()
}

/// Return Token's module address, module name, and type name of `TokenType`.
native fun name_of<TokenType: store>(): (address, vector<u8>, vector<u8>);
native fun name_of<TokenType>(): (address, vector<u8>, vector<u8>);

spec name_of {
pragma opaque = true;
Expand Down
30 changes: 30 additions & 0 deletions sources/TypeInfo.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module StarcoinFramework::TypeInfo{
use StarcoinFramework::Token;

struct TypeInfo has copy, drop, store{
account_address: address,
module_name: vector<u8>,
struct_name: vector<u8>
}

public fun account_address(type_info: &TypeInfo):address{
type_info.account_address
}

public fun module_name(type_info: &TypeInfo):vector<u8>{
*&type_info.module_name
}

public fun struct_name(type_info: &TypeInfo):vector<u8>{
*&type_info.struct_name
}

public fun type_of<T>():TypeInfo{
let (account_address, module_name, struct_name) = Token::type_of<T>();
TypeInfo {
account_address,
module_name,
struct_name
}
}
}