Skip to content

Commit

Permalink
[fa migration] refactor with coin withdraw event and bypass sanity ch…
Browse files Browse the repository at this point in the history
…eck (#15520)
  • Loading branch information
lightmark authored Dec 6, 2024
1 parent 5902ff0 commit 8a1016a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
14 changes: 11 additions & 3 deletions aptos-move/framework/aptos-framework/doc/coin.md
Original file line number Diff line number Diff line change
Expand Up @@ -2054,13 +2054,21 @@ or disallow upgradability of total supply.
deleted_withdraw_event_handle_creation_number: <a href="guid.md#0x1_guid_creation_num">guid::creation_num</a>(<a href="event.md#0x1_event_guid">event::guid</a>(&withdraw_events))
}
);
<a href="event.md#0x1_event_destroy_handle">event::destroy_handle</a>(deposit_events);
<a href="event.md#0x1_event_destroy_handle">event::destroy_handle</a>(withdraw_events);
<b>if</b> (<a href="coin.md#0x1_coin">coin</a>.value == 0) {
<a href="coin.md#0x1_coin_destroy_zero">destroy_zero</a>(<a href="coin.md#0x1_coin">coin</a>);
} <b>else</b> {
<a href="fungible_asset.md#0x1_fungible_asset_deposit">fungible_asset::deposit</a>(store, <a href="coin.md#0x1_coin_coin_to_fungible_asset">coin_to_fungible_asset</a>(<a href="coin.md#0x1_coin">coin</a>));
<b>if</b> (std::features::module_event_migration_enabled()) {
<a href="event.md#0x1_event_emit">event::emit</a>(<a href="coin.md#0x1_coin_CoinWithdraw">CoinWithdraw</a> { coin_type: type_name&lt;CoinType&gt;(), <a href="account.md#0x1_account">account</a>, amount: <a href="coin.md#0x1_coin">coin</a>.value });
} <b>else</b> {
<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> withdraw_events,
<a href="coin.md#0x1_coin_WithdrawEvent">WithdrawEvent</a> { amount: <a href="coin.md#0x1_coin">coin</a>.value },
);
};
<a href="fungible_asset.md#0x1_fungible_asset_deposit_internal">fungible_asset::deposit_internal</a>(object_address(&store), <a href="coin.md#0x1_coin_coin_to_fungible_asset">coin_to_fungible_asset</a>(<a href="coin.md#0x1_coin">coin</a>));
};
<a href="event.md#0x1_event_destroy_handle">event::destroy_handle</a>(deposit_events);
<a href="event.md#0x1_event_destroy_handle">event::destroy_handle</a>(withdraw_events);
// Note:
// It is possible the primary fungible store may already exist before this function call.
// In this case, <b>if</b> the <a href="account.md#0x1_account">account</a> owns a frozen <a href="coin.md#0x1_coin_CoinStore">CoinStore</a> and an unfrozen primary fungible store, this
Expand Down
14 changes: 11 additions & 3 deletions aptos-move/framework/aptos-framework/sources/coin.move
Original file line number Diff line number Diff line change
Expand Up @@ -581,13 +581,21 @@ module aptos_framework::coin {
deleted_withdraw_event_handle_creation_number: guid::creation_num(event::guid(&withdraw_events))
}
);
event::destroy_handle(deposit_events);
event::destroy_handle(withdraw_events);
if (coin.value == 0) {
destroy_zero(coin);
} else {
fungible_asset::deposit(store, coin_to_fungible_asset(coin));
if (std::features::module_event_migration_enabled()) {
event::emit(CoinWithdraw { coin_type: type_name<CoinType>(), account, amount: coin.value });
} else {
event::emit_event<WithdrawEvent>(
&mut withdraw_events,
WithdrawEvent { amount: coin.value },
);
};
fungible_asset::deposit_internal(object_address(&store), coin_to_fungible_asset(coin));
};
event::destroy_handle(deposit_events);
event::destroy_handle(withdraw_events);
// Note:
// It is possible the primary fungible store may already exist before this function call.
// In this case, if the account owns a frozen CoinStore and an unfrozen primary fungible store, this
Expand Down

0 comments on commit 8a1016a

Please sign in to comment.