From 7456ac5d800b60b8a08fdfd0f0c4d85c117ee54d Mon Sep 17 00:00:00 2001 From: Aaron Gao Date: Thu, 5 Dec 2024 18:30:57 -0600 Subject: [PATCH] [fa migration] refactor with coin withdraw event and bypass sanity check --- aptos-move/framework/aptos-framework/doc/coin.md | 14 +++++++++++--- .../framework/aptos-framework/sources/coin.move | 14 +++++++++++--- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/aptos-move/framework/aptos-framework/doc/coin.md b/aptos-move/framework/aptos-framework/doc/coin.md index 98f56f007e8b3..0b5b91cec523c 100644 --- a/aptos-move/framework/aptos-framework/doc/coin.md +++ b/aptos-move/framework/aptos-framework/doc/coin.md @@ -2054,13 +2054,21 @@ or disallow upgradability of total supply. 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 diff --git a/aptos-move/framework/aptos-framework/sources/coin.move b/aptos-move/framework/aptos-framework/sources/coin.move index 2ea6aca5762ec..3887fe31c8f76 100644 --- a/aptos-move/framework/aptos-framework/sources/coin.move +++ b/aptos-move/framework/aptos-framework/sources/coin.move @@ -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(), account, amount: coin.value }); + } else { + event::emit_event( + &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