Skip to content

Commit

Permalink
[framework] Copy the CoinInfo and keep global CoinMetadata (#3135)
Browse files Browse the repository at this point in the history
* [framework] Copy the CoinInfo and keep global CoinMetadata

* update docs

* add doc updates

* [framework] Rename register to registry
  • Loading branch information
jolestar authored Jan 2, 2025
1 parent 7a67f76 commit c97a1db
Show file tree
Hide file tree
Showing 5 changed files with 302 additions and 11 deletions.
8 changes: 4 additions & 4 deletions frameworks/rooch-framework/doc/bitcoin_address.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,20 @@ We just keep the raw bytes of the address and do care about the network.
## Constants


<a name="0x3_bitcoin_address_ErrorArgNotVectorU8"></a>
<a name="0x3_bitcoin_address_ErrorDeprecated"></a>



<pre><code><b>const</b> <a href="bitcoin_address.md#0x3_bitcoin_address_ErrorArgNotVectorU8">ErrorArgNotVectorU8</a>: u64 = 2;
<pre><code><b>const</b> <a href="bitcoin_address.md#0x3_bitcoin_address_ErrorDeprecated">ErrorDeprecated</a>: u64 = 6;
</code></pre>



<a name="0x3_bitcoin_address_ErrorDeprecated"></a>
<a name="0x3_bitcoin_address_ErrorArgNotVectorU8"></a>



<pre><code><b>const</b> <a href="bitcoin_address.md#0x3_bitcoin_address_ErrorDeprecated">ErrorDeprecated</a>: u64 = 6;
<pre><code><b>const</b> <a href="bitcoin_address.md#0x3_bitcoin_address_ErrorArgNotVectorU8">ErrorArgNotVectorU8</a>: u64 = 2;
</code></pre>


Expand Down
137 changes: 137 additions & 0 deletions frameworks/rooch-framework/doc/coin.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,27 @@ This module provides the foundation for typesafe Coins.

- [Struct `Coin`](#0x3_coin_Coin)
- [Resource `CoinInfo`](#0x3_coin_CoinInfo)
- [Resource `CoinMetadata`](#0x3_coin_CoinMetadata)
- [Resource `CoinRegistry`](#0x3_coin_CoinRegistry)
- [Struct `MintEvent`](#0x3_coin_MintEvent)
- [Struct `BurnEvent`](#0x3_coin_BurnEvent)
- [Constants](#@Constants_0)
- [Function `genesis_init`](#0x3_coin_genesis_init)
- [Function `init_coin_registry`](#0x3_coin_init_coin_registry)
- [Function `coin_address`](#0x3_coin_coin_address)
- [Function `check_coin_info_registered`](#0x3_coin_check_coin_info_registered)
- [Function `is_registered`](#0x3_coin_is_registered)
- [Function `coin_info_id`](#0x3_coin_coin_info_id)
- [Function `name`](#0x3_coin_name)
- [Function `name_by_type`](#0x3_coin_name_by_type)
- [Function `symbol`](#0x3_coin_symbol)
- [Function `symbol_by_type`](#0x3_coin_symbol_by_type)
- [Function `decimals`](#0x3_coin_decimals)
- [Function `decimals_by_type`](#0x3_coin_decimals_by_type)
- [Function `supply`](#0x3_coin_supply)
- [Function `supply_by_type`](#0x3_coin_supply_by_type)
- [Function `icon_url`](#0x3_coin_icon_url)
- [Function `icon_url_by_type`](#0x3_coin_icon_url_by_type)
- [Function `is_same_coin`](#0x3_coin_is_same_coin)
- [Function `destroy_zero`](#0x3_coin_destroy_zero)
- [Function `extract`](#0x3_coin_extract)
Expand All @@ -31,6 +39,7 @@ This module provides the foundation for typesafe Coins.
- [Function `coin_info`](#0x3_coin_coin_info)
- [Function `upsert_icon_url`](#0x3_coin_upsert_icon_url)
- [Function `register_extend`](#0x3_coin_register_extend)
- [Function `init_metadata`](#0x3_coin_init_metadata)
- [Function `mint`](#0x3_coin_mint)
- [Function `mint_extend`](#0x3_coin_mint_extend)
- [Function `burn`](#0x3_coin_burn)
Expand Down Expand Up @@ -77,6 +86,30 @@ CoinInfo<CoinType> is a named Object, the <code>coin_type</code> is the unique k



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

## Resource `CoinMetadata`

Coin metadata is copied from CoinInfo, and stored as dynamic field of CoinRegistry


<pre><code><b>struct</b> <a href="coin.md#0x3_coin_CoinMetadata">CoinMetadata</a> <b>has</b> store, key
</code></pre>



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

## Resource `CoinRegistry`

The registry of all coin types.


<pre><code><b>struct</b> <a href="coin.md#0x3_coin_CoinRegistry">CoinRegistry</a> <b>has</b> key
</code></pre>



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

## Struct `MintEvent`
Expand Down Expand Up @@ -175,6 +208,16 @@ Name of the coin is too long



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

CoinRegister is already initialized


<pre><code><b>const</b> <a href="coin.md#0x3_coin_ErrorCoinRegisterAlreadyInitialized">ErrorCoinRegisterAlreadyInitialized</a>: u64 = 9;
</code></pre>



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

Symbol of the coin is too long
Expand All @@ -185,6 +228,16 @@ Symbol of the coin is too long



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

The function is deprecated


<pre><code><b>const</b> <a href="coin.md#0x3_coin_ErrorDeprecated">ErrorDeprecated</a>: u64 = 10;
</code></pre>



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

Cannot destroy non-zero coins
Expand Down Expand Up @@ -244,6 +297,18 @@ Coin amount cannot be zero



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

## Function `init_coin_registry`

Initialize the CoinRegistry, this function is for framework upgrade.


<pre><code>entry <b>fun</b> <a href="coin.md#0x3_coin_init_coin_registry">init_coin_registry</a>()
</code></pre>



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

## Function `coin_address`
Expand Down Expand Up @@ -304,6 +369,18 @@ Returns the name of the coin.



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

## Function `name_by_type`

Returns the name of the coin by the type <code>CoinType</code>


<pre><code><b>public</b> <b>fun</b> <a href="coin.md#0x3_coin_name_by_type">name_by_type</a>&lt;CoinType: key&gt;(): <a href="_String">string::String</a>
</code></pre>



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

## Function `symbol`
Expand All @@ -316,6 +393,18 @@ Returns the symbol of the coin, usually a shorter version of the name.



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

## Function `symbol_by_type`

Returns the symbol of the coin by the type <code>CoinType</code>


<pre><code><b>public</b> <b>fun</b> <a href="coin.md#0x3_coin_symbol_by_type">symbol_by_type</a>&lt;CoinType: key&gt;(): <a href="_String">string::String</a>
</code></pre>



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

## Function `decimals`
Expand All @@ -330,6 +419,18 @@ be displayed to a user as <code>5.05</code> (<code>505 / 10 ** 2</code>).



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

## Function `decimals_by_type`

Returns the decimals of the coin by the type <code>CoinType</code>


<pre><code><b>public</b> <b>fun</b> <a href="coin.md#0x3_coin_decimals_by_type">decimals_by_type</a>&lt;CoinType: key&gt;(): u8
</code></pre>



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

## Function `supply`
Expand All @@ -342,6 +443,18 @@ Returns the amount of coin in existence.



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

## Function `supply_by_type`

Returns the amount of coin in existence by the type <code>CoinType</code>


<pre><code><b>public</b> <b>fun</b> <a href="coin.md#0x3_coin_supply_by_type">supply_by_type</a>&lt;CoinType: key&gt;(): <a href="">u256</a>
</code></pre>



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

## Function `icon_url`
Expand All @@ -354,6 +467,18 @@ Returns the icon url of coin.



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

## Function `icon_url_by_type`

Returns the icon url of coin by the type <code>CoinType</code>


<pre><code><b>public</b> <b>fun</b> <a href="coin.md#0x3_coin_icon_url_by_type">icon_url_by_type</a>&lt;CoinType: key&gt;(): <a href="_Option">option::Option</a>&lt;<a href="_String">string::String</a>&gt;
</code></pre>



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

## Function `is_same_coin`
Expand Down Expand Up @@ -479,6 +604,18 @@ This function is protected by <code>private_generics</code>, so it can only be c



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

## Function `init_metadata`

This function for the old code to initialize the CoinMetadata


<pre><code><b>public</b> <b>fun</b> <a href="coin.md#0x3_coin_init_metadata">init_metadata</a>&lt;CoinType: key&gt;(coin_info: &<a href="_Object">object::Object</a>&lt;<a href="coin.md#0x3_coin_CoinInfo">coin::CoinInfo</a>&lt;CoinType&gt;&gt;)
</code></pre>



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

## Function `mint`
Expand Down
Loading

0 comments on commit c97a1db

Please sign in to comment.