From 4de088dab67ccde6c90a8543f6ca6988073ea965 Mon Sep 17 00:00:00 2001 From: Greg Nazario Date: Tue, 14 Jan 2025 14:28:10 -0500 Subject: [PATCH] [framework] Replace coin store deletion event with coin type The original event didn't have the coin type which made it very hard for indexing. This replaces it. --- .../framework/aptos-framework/doc/coin.md | 75 ++++++++++++++++++- .../aptos-framework/sources/coin.move | 15 +++- 2 files changed, 88 insertions(+), 2 deletions(-) diff --git a/aptos-move/framework/aptos-framework/doc/coin.md b/aptos-move/framework/aptos-framework/doc/coin.md index bbd15e38568ae..4c82eabb2d92b 100644 --- a/aptos-move/framework/aptos-framework/doc/coin.md +++ b/aptos-move/framework/aptos-framework/doc/coin.md @@ -18,6 +18,7 @@ This module provides the foundation for typesafe Coins. - [Struct `DepositEvent`](#0x1_coin_DepositEvent) - [Struct `WithdrawEvent`](#0x1_coin_WithdrawEvent) - [Struct `CoinEventHandleDeletion`](#0x1_coin_CoinEventHandleDeletion) +- [Struct `CoinStoreDeletion`](#0x1_coin_CoinStoreDeletion) - [Struct `PairCreation`](#0x1_coin_PairCreation) - [Struct `MintCapability`](#0x1_coin_MintCapability) - [Struct `FreezeCapability`](#0x1_coin_FreezeCapability) @@ -555,8 +556,11 @@ Event emitted when some amount of a coin is withdrawn from an account. Module event emitted when the event handles related to coin store is deleted. +Deprecated: replaced with CoinStoreDeletion +
#[event]
+#[deprecated]
 struct CoinEventHandleDeletion has drop, store
 
@@ -588,6 +592,53 @@ Module event emitted when the event handles related to coin store is deleted. + + + + +## Struct `CoinStoreDeletion` + +Module event emitted when the event handles related to coin store is deleted. + + +
#[event]
+struct CoinStoreDeletion has drop, store
+
+ + + +
+Fields + + +
+
+coin_type: string::String +
+
+ +
+
+event_handle_creation_address: address +
+
+ +
+
+deleted_deposit_event_handle_creation_number: u64 +
+
+ +
+
+deleted_withdraw_event_handle_creation_number: u64 +
+
+ +
+
+ +
@@ -2046,7 +2097,8 @@ or disallow upgradability of total supply. account ); event::emit( - CoinEventHandleDeletion { + CoinStoreDeletion { + coin_type: type_info::type_name<CoinType>(), event_handle_creation_address: guid::creator_address( event::guid(&deposit_events) ), @@ -4228,6 +4280,27 @@ The creator of CoinType must be @aptos_framework. +Make sure name and symbol are legal length. +Only the creator of CoinType can initialize. + + + + + +
schema InitializeInternalSchema<CoinType> {
+    account: signer;
+    name: vector<u8>;
+    symbol: vector<u8>;
+    let account_addr = signer::address_of(account);
+    let coin_address = type_info::type_of<CoinType>().account_address;
+    aborts_if coin_address != account_addr;
+    aborts_if exists<CoinInfo<CoinType>>(account_addr);
+    aborts_if len(name) > MAX_COIN_NAME_LENGTH;
+    aborts_if len(symbol) > MAX_COIN_SYMBOL_LENGTH;
+}
+
+ + diff --git a/aptos-move/framework/aptos-framework/sources/coin.move b/aptos-move/framework/aptos-framework/sources/coin.move index ce9d5b8230ca9..a396b121b82de 100644 --- a/aptos-move/framework/aptos-framework/sources/coin.move +++ b/aptos-move/framework/aptos-framework/sources/coin.move @@ -206,14 +206,26 @@ module aptos_framework::coin { } + #[deprecated] #[event] /// Module event emitted when the event handles related to coin store is deleted. + /// + /// Deprecated: replaced with CoinStoreDeletion struct CoinEventHandleDeletion has drop, store { event_handle_creation_address: address, deleted_deposit_event_handle_creation_number: u64, deleted_withdraw_event_handle_creation_number: u64, } + #[event] + /// Module event emitted when the event handles related to coin store is deleted. + struct CoinStoreDeletion has drop, store { + coin_type: String, + event_handle_creation_address: address, + deleted_deposit_event_handle_creation_number: u64, + deleted_withdraw_event_handle_creation_number: u64, + } + #[event] /// Module event emitted when a new pair of coin and fungible asset is created. struct PairCreation has drop, store { @@ -573,7 +585,8 @@ module aptos_framework::coin { account ); event::emit( - CoinEventHandleDeletion { + CoinStoreDeletion { + coin_type: type_info::type_name(), event_handle_creation_address: guid::creator_address( event::guid(&deposit_events) ),