Skip to content

Commit

Permalink
[event v2] double emitting in account, coin, fungible asset and object
Browse files Browse the repository at this point in the history
  • Loading branch information
lightmark committed Oct 16, 2023
1 parent c531dbe commit e4a02ff
Show file tree
Hide file tree
Showing 10 changed files with 439 additions and 20 deletions.
87 changes: 87 additions & 0 deletions aptos-move/framework/aptos-framework/doc/account.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@



- [Struct `KeyRotation`](#0x1_account_KeyRotation)
- [Struct `CoinRegister`](#0x1_account_CoinRegister)
- [Resource `Account`](#0x1_account_Account)
- [Struct `KeyRotationEvent`](#0x1_account_KeyRotationEvent)
- [Struct `CoinRegisterEvent`](#0x1_account_CoinRegisterEvent)
Expand Down Expand Up @@ -108,6 +110,80 @@



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

## Struct `KeyRotation`



<pre><code>#[<a href="event.md#0x1_event">event</a>]
<b>struct</b> <a href="account.md#0x1_account_KeyRotation">KeyRotation</a> <b>has</b> drop, store
</code></pre>



<details>
<summary>Fields</summary>


<dl>
<dt>
<code><a href="account.md#0x1_account">account</a>: <b>address</b></code>
</dt>
<dd>

</dd>
<dt>
<code>old_authentication_key: <a href="../../aptos-stdlib/../move-stdlib/doc/vector.md#0x1_vector">vector</a>&lt;u8&gt;</code>
</dt>
<dd>

</dd>
<dt>
<code>new_authentication_key: <a href="../../aptos-stdlib/../move-stdlib/doc/vector.md#0x1_vector">vector</a>&lt;u8&gt;</code>
</dt>
<dd>

</dd>
</dl>


</details>

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

## Struct `CoinRegister`



<pre><code>#[<a href="event.md#0x1_event">event</a>]
<b>struct</b> <a href="account.md#0x1_account_CoinRegister">CoinRegister</a> <b>has</b> drop, store
</code></pre>



<details>
<summary>Fields</summary>


<dl>
<dt>
<code><a href="account.md#0x1_account">account</a>: <b>address</b></code>
</dt>
<dd>

</dd>
<dt>
<code><a href="../../aptos-stdlib/doc/type_info.md#0x1_type_info">type_info</a>: <a href="../../aptos-stdlib/doc/type_info.md#0x1_type_info_TypeInfo">type_info::TypeInfo</a></code>
</dt>
<dd>

</dd>
</dl>


</details>

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

## Resource `Account`
Expand Down Expand Up @@ -1742,6 +1818,11 @@ in the event of key recovery.
<b>let</b> new_auth_key = <a href="../../aptos-stdlib/doc/from_bcs.md#0x1_from_bcs_to_address">from_bcs::to_address</a>(new_auth_key_vector);
<a href="../../aptos-stdlib/doc/table.md#0x1_table_add">table::add</a>(address_map, new_auth_key, originating_addr);

<a href="event.md#0x1_event_emit">event::emit</a>&lt;<a href="account.md#0x1_account_KeyRotation">KeyRotation</a>&gt;(<a href="account.md#0x1_account_KeyRotation">KeyRotation</a> {
<a href="account.md#0x1_account">account</a>: originating_addr,
old_authentication_key: account_resource.authentication_key,
new_authentication_key: new_auth_key_vector,
});
<a href="event.md#0x1_event_emit_event">event::emit_event</a>&lt;<a href="account.md#0x1_account_KeyRotationEvent">KeyRotationEvent</a>&gt;(
&<b>mut</b> account_resource.key_rotation_events,
<a href="account.md#0x1_account_KeyRotationEvent">KeyRotationEvent</a> {
Expand Down Expand Up @@ -1961,6 +2042,12 @@ Coin management methods.

<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="account.md#0x1_account_register_coin">register_coin</a>&lt;CoinType&gt;(account_addr: <b>address</b>) <b>acquires</b> <a href="account.md#0x1_account_Account">Account</a> {
<b>let</b> <a href="account.md#0x1_account">account</a> = <b>borrow_global_mut</b>&lt;<a href="account.md#0x1_account_Account">Account</a>&gt;(account_addr);
<a href="event.md#0x1_event_emit">event::emit</a>&lt;<a href="account.md#0x1_account_CoinRegister">CoinRegister</a>&gt;(
<a href="account.md#0x1_account_CoinRegister">CoinRegister</a> {
<a href="account.md#0x1_account">account</a>: account_addr,
<a href="../../aptos-stdlib/doc/type_info.md#0x1_type_info">type_info</a>: <a href="../../aptos-stdlib/doc/type_info.md#0x1_type_info_type_of">type_info::type_of</a>&lt;CoinType&gt;(),
},
);
<a href="event.md#0x1_event_emit_event">event::emit_event</a>&lt;<a href="account.md#0x1_account_CoinRegisterEvent">CoinRegisterEvent</a>&gt;(
&<b>mut</b> <a href="account.md#0x1_account">account</a>.coin_register_events,
<a href="account.md#0x1_account_CoinRegisterEvent">CoinRegisterEvent</a> {
Expand Down
40 changes: 39 additions & 1 deletion aptos-move/framework/aptos-framework/doc/aptos_account.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@


- [Resource `DirectTransferConfig`](#0x1_aptos_account_DirectTransferConfig)
- [Struct `DirectCoinTransferConfigUpdated`](#0x1_aptos_account_DirectCoinTransferConfigUpdated)
- [Struct `DirectCoinTransferConfigUpdatedEvent`](#0x1_aptos_account_DirectCoinTransferConfigUpdatedEvent)
- [Constants](#@Constants_0)
- [Function `create_account`](#0x1_aptos_account_create_account)
Expand Down Expand Up @@ -76,13 +77,46 @@ By default, this is enabled. Users can opt-out by disabling at any time.
</dl>


</details>

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

## Struct `DirectCoinTransferConfigUpdated`



<pre><code>#[<a href="event.md#0x1_event">event</a>]
<b>struct</b> <a href="aptos_account.md#0x1_aptos_account_DirectCoinTransferConfigUpdated">DirectCoinTransferConfigUpdated</a> <b>has</b> drop, store
</code></pre>



<details>
<summary>Fields</summary>


<dl>
<dt>
<code><a href="account.md#0x1_account">account</a>: <b>address</b></code>
</dt>
<dd>

</dd>
<dt>
<code>new_allow_direct_transfers: bool</code>
</dt>
<dd>

</dd>
</dl>


</details>

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

## Struct `DirectCoinTransferConfigUpdatedEvent`

Event emitted when an account's direct coins transfer config is updated.


<pre><code><b>struct</b> <a href="aptos_account.md#0x1_aptos_account_DirectCoinTransferConfigUpdatedEvent">DirectCoinTransferConfigUpdatedEvent</a> <b>has</b> drop, store
Expand Down Expand Up @@ -432,6 +466,8 @@ Set whether <code><a href="account.md#0x1_account">account</a></code> can receiv
};

direct_transfer_config.allow_arbitrary_coin_transfers = allow;
emit(
<a href="aptos_account.md#0x1_aptos_account_DirectCoinTransferConfigUpdated">DirectCoinTransferConfigUpdated</a>{ <a href="account.md#0x1_account">account</a>: addr, new_allow_direct_transfers: allow });
emit_event(
&<b>mut</b> direct_transfer_config.update_coin_transfer_events,
<a href="aptos_account.md#0x1_aptos_account_DirectCoinTransferConfigUpdatedEvent">DirectCoinTransferConfigUpdatedEvent</a> { new_allow_direct_transfers: allow });
Expand All @@ -440,6 +476,8 @@ Set whether <code><a href="account.md#0x1_account">account</a></code> can receiv
allow_arbitrary_coin_transfers: allow,
update_coin_transfer_events: new_event_handle&lt;<a href="aptos_account.md#0x1_aptos_account_DirectCoinTransferConfigUpdatedEvent">DirectCoinTransferConfigUpdatedEvent</a>&gt;(<a href="account.md#0x1_account">account</a>),
};
emit(
<a href="aptos_account.md#0x1_aptos_account_DirectCoinTransferConfigUpdated">DirectCoinTransferConfigUpdated</a>{ <a href="account.md#0x1_account">account</a>: addr, new_allow_direct_transfers: allow });
emit_event(
&<b>mut</b> direct_transfer_config.update_coin_transfer_events,
<a href="aptos_account.md#0x1_aptos_account_DirectCoinTransferConfigUpdatedEvent">DirectCoinTransferConfigUpdatedEvent</a> { new_allow_direct_transfers: allow });
Expand Down
90 changes: 83 additions & 7 deletions aptos-move/framework/aptos-framework/doc/coin.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ This module provides the foundation for typesafe Coins.
- [Resource `CoinStore`](#0x1_coin_CoinStore)
- [Resource `SupplyConfig`](#0x1_coin_SupplyConfig)
- [Resource `CoinInfo`](#0x1_coin_CoinInfo)
- [Struct `Deposit`](#0x1_coin_Deposit)
- [Struct `DepositEvent`](#0x1_coin_DepositEvent)
- [Struct `Withdraw`](#0x1_coin_Withdraw)
- [Struct `WithdrawEvent`](#0x1_coin_WithdrawEvent)
- [Struct `MintCapability`](#0x1_coin_MintCapability)
- [Struct `FreezeCapability`](#0x1_coin_FreezeCapability)
Expand Down Expand Up @@ -292,13 +294,46 @@ Information about a specific coin type. Stored on the creator of the coin's acco
</dl>


</details>

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

## Struct `Deposit`



<pre><code>#[<a href="event.md#0x1_event">event</a>]
<b>struct</b> <a href="coin.md#0x1_coin_Deposit">Deposit</a> <b>has</b> drop, store
</code></pre>



<details>
<summary>Fields</summary>


<dl>
<dt>
<code><a href="account.md#0x1_account">account</a>: <b>address</b></code>
</dt>
<dd>

</dd>
<dt>
<code>amount: u64</code>
</dt>
<dd>

</dd>
</dl>


</details>

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

## Struct `DepositEvent`

Event emitted when some amount of a coin is deposited into an account.


<pre><code><b>struct</b> <a href="coin.md#0x1_coin_DepositEvent">DepositEvent</a> <b>has</b> drop, store
Expand All @@ -320,13 +355,46 @@ Event emitted when some amount of a coin is deposited into an account.
</dl>


</details>

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

## Struct `Withdraw`



<pre><code>#[<a href="event.md#0x1_event">event</a>]
<b>struct</b> <a href="coin.md#0x1_coin_Withdraw">Withdraw</a> <b>has</b> drop, store
</code></pre>



<details>
<summary>Fields</summary>


<dl>
<dt>
<code><a href="account.md#0x1_account">account</a>: <b>address</b></code>
</dt>
<dd>

</dd>
<dt>
<code>amount: u64</code>
</dt>
<dd>

</dd>
</dl>


</details>

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

## Struct `WithdrawEvent`

Event emitted when some amount of a coin is withdrawn from an account.


<pre><code><b>struct</b> <a href="coin.md#0x1_coin_WithdrawEvent">WithdrawEvent</a> <b>has</b> drop, store
Expand Down Expand Up @@ -826,7 +894,10 @@ Merges <code><a href="coin.md#0x1_coin">coin</a></code> into aggregatable coin (
<summary>Implementation</summary>


<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="coin.md#0x1_coin_merge_aggregatable_coin">merge_aggregatable_coin</a>&lt;CoinType&gt;(dst_coin: &<b>mut</b> <a href="coin.md#0x1_coin_AggregatableCoin">AggregatableCoin</a>&lt;CoinType&gt;, <a href="coin.md#0x1_coin">coin</a>: <a href="coin.md#0x1_coin_Coin">Coin</a>&lt;CoinType&gt;) {
<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="coin.md#0x1_coin_merge_aggregatable_coin">merge_aggregatable_coin</a>&lt;CoinType&gt;(
dst_coin: &<b>mut</b> <a href="coin.md#0x1_coin_AggregatableCoin">AggregatableCoin</a>&lt;CoinType&gt;,
<a href="coin.md#0x1_coin">coin</a>: <a href="coin.md#0x1_coin_Coin">Coin</a>&lt;CoinType&gt;
) {
<b>spec</b> {
<b>update</b> <a href="coin.md#0x1_coin_supply">supply</a>&lt;CoinType&gt; = <a href="coin.md#0x1_coin_supply">supply</a>&lt;CoinType&gt; - <a href="coin.md#0x1_coin">coin</a>.value;
};
Expand Down Expand Up @@ -979,8 +1050,8 @@ Returns <code><b>true</b></code> is account_addr has frozen the CoinStore or if


<pre><code><b>public</b> <b>fun</b> <a href="coin.md#0x1_coin_is_coin_store_frozen">is_coin_store_frozen</a>&lt;CoinType&gt;(account_addr: <b>address</b>): bool <b>acquires</b> <a href="coin.md#0x1_coin_CoinStore">CoinStore</a> {
<b>if</b>(!<a href="coin.md#0x1_coin_is_account_registered">is_account_registered</a>&lt;CoinType&gt;(account_addr)) {
<b>return</b> <b>true</b>
<b>if</b> (!<a href="coin.md#0x1_coin_is_account_registered">is_account_registered</a>&lt;CoinType&gt;(account_addr)) {
<b>return</b> <b>true</b>
};

<b>let</b> coin_store = <b>borrow_global</b>&lt;<a href="coin.md#0x1_coin_CoinStore">CoinStore</a>&lt;CoinType&gt;&gt;(account_addr);
Expand Down Expand Up @@ -1238,7 +1309,7 @@ Deposit the coin balance into the recipient's account and emit an event.
!coin_store.frozen,
<a href="../../aptos-stdlib/../move-stdlib/doc/error.md#0x1_error_permission_denied">error::permission_denied</a>(<a href="coin.md#0x1_coin_EFROZEN">EFROZEN</a>),
);

<a href="event.md#0x1_event_emit">event::emit</a>&lt;<a href="coin.md#0x1_coin_Deposit">Deposit</a>&gt;(<a href="coin.md#0x1_coin_Deposit">Deposit</a> { <a href="account.md#0x1_account">account</a>: account_addr, amount: <a href="coin.md#0x1_coin">coin</a>.value });
<a href="event.md#0x1_event_emit_event">event::emit_event</a>&lt;<a href="coin.md#0x1_coin_DepositEvent">DepositEvent</a>&gt;(
&<b>mut</b> coin_store.deposit_events,
<a href="coin.md#0x1_coin_DepositEvent">DepositEvent</a> { amount: <a href="coin.md#0x1_coin">coin</a>.value },
Expand Down Expand Up @@ -1597,7 +1668,11 @@ Same as <code>initialize</code> but supply can be initialized to parallelizable
name,
symbol,
decimals,
<a href="coin.md#0x1_coin_supply">supply</a>: <b>if</b> (monitor_supply) { <a href="../../aptos-stdlib/../move-stdlib/doc/option.md#0x1_option_some">option::some</a>(<a href="optional_aggregator.md#0x1_optional_aggregator_new">optional_aggregator::new</a>(<a href="coin.md#0x1_coin_MAX_U128">MAX_U128</a>, parallelizable)) } <b>else</b> { <a href="../../aptos-stdlib/../move-stdlib/doc/option.md#0x1_option_none">option::none</a>() },
<a href="coin.md#0x1_coin_supply">supply</a>: <b>if</b> (monitor_supply) {
<a href="../../aptos-stdlib/../move-stdlib/doc/option.md#0x1_option_some">option::some</a>(
<a href="optional_aggregator.md#0x1_optional_aggregator_new">optional_aggregator::new</a>(<a href="coin.md#0x1_coin_MAX_U128">MAX_U128</a>, parallelizable)
)
} <b>else</b> { <a href="../../aptos-stdlib/../move-stdlib/doc/option.md#0x1_option_none">option::none</a>() },
};
<b>move_to</b>(<a href="account.md#0x1_account">account</a>, coin_info);

Expand Down Expand Up @@ -1813,6 +1888,7 @@ Withdraw specifed <code>amount</code> of coin <code>CoinType</code> from the sig
<a href="../../aptos-stdlib/../move-stdlib/doc/error.md#0x1_error_permission_denied">error::permission_denied</a>(<a href="coin.md#0x1_coin_EFROZEN">EFROZEN</a>),
);

<a href="event.md#0x1_event_emit">event::emit</a>&lt;<a href="coin.md#0x1_coin_Withdraw">Withdraw</a>&gt;(<a href="coin.md#0x1_coin_Withdraw">Withdraw</a> { <a href="account.md#0x1_account">account</a>: account_addr, amount }, );
<a href="event.md#0x1_event_emit_event">event::emit_event</a>&lt;<a href="coin.md#0x1_coin_WithdrawEvent">WithdrawEvent</a>&gt;(
&<b>mut</b> coin_store.withdraw_events,
<a href="coin.md#0x1_coin_WithdrawEvent">WithdrawEvent</a> { amount },
Expand Down
Loading

0 comments on commit e4a02ff

Please sign in to comment.