diff --git a/aptos-move/framework/aptos-framework/doc/coin.md b/aptos-move/framework/aptos-framework/doc/coin.md
index 054a7ffd57a30..98f56f007e8b3 100644
--- a/aptos-move/framework/aptos-framework/doc/coin.md
+++ b/aptos-move/framework/aptos-framework/doc/coin.md
@@ -73,7 +73,7 @@ This module provides the foundation for typesafe Coins.
- [Function `burn`](#0x1_coin_burn)
- [Function `burn_from`](#0x1_coin_burn_from)
- [Function `deposit`](#0x1_coin_deposit)
-- [Function `migrated_primary_fungible_store_exists`](#0x1_coin_migrated_primary_fungible_store_exists)
+- [Function `can_receive_paired_fungible_asset`](#0x1_coin_can_receive_paired_fungible_asset)
- [Function `force_deposit`](#0x1_coin_force_deposit)
- [Function `destroy_zero`](#0x1_coin_destroy_zero)
- [Function `extract`](#0x1_coin_extract)
@@ -2344,7 +2344,7 @@ Returns true
if account_addr
is registered to r
let paired_metadata_opt = paired_metadata<CoinType>();
(option::is_some(
&paired_metadata_opt
- ) && migrated_primary_fungible_store_exists(account_addr, option::destroy_some(paired_metadata_opt)))
+ ) && can_receive_paired_fungible_asset(account_addr, option::destroy_some(paired_metadata_opt)))
}
}
@@ -2620,7 +2620,7 @@ Deposit the coin balance into the recipient's account and emit an event.
merge(&mut coin_store.coin, coin);
} else {
let metadata = paired_metadata<CoinType>();
- if (option::is_some(&metadata) && migrated_primary_fungible_store_exists(
+ if (option::is_some(&metadata) && can_receive_paired_fungible_asset(
account_addr,
option::destroy_some(metadata)
)) {
@@ -2636,13 +2636,13 @@ Deposit the coin balance into the recipient's account and emit an event.
-
+
-## Function `migrated_primary_fungible_store_exists`
+## Function `can_receive_paired_fungible_asset`
-
fun migrated_primary_fungible_store_exists(account_address: address, metadata: object::Object<fungible_asset::Metadata>): bool
+fun can_receive_paired_fungible_asset(account_address: address, metadata: object::Object<fungible_asset::Metadata>): bool
@@ -2651,11 +2651,11 @@ Deposit the coin balance into the recipient's account and emit an event.
Implementation
-inline fun migrated_primary_fungible_store_exists(
+inline fun can_receive_paired_fungible_asset(
account_address: address,
metadata: Object<Metadata>
): bool {
- features::new_accounts_default_to_fa_apt_store_enabled() || {
+ (features::new_accounts_default_to_fa_apt_store_enabled() && object::object_address(&metadata) == @0xa) || {
let primary_store_address = primary_fungible_store::primary_store_address<Metadata>(
account_address,
metadata
@@ -2695,7 +2695,7 @@ This is for internal use only and doesn't emit an DepositEvent.
merge(&mut coin_store.coin, coin);
} else {
let metadata = paired_metadata<CoinType>();
- if (option::is_some(&metadata) && migrated_primary_fungible_store_exists(
+ if (option::is_some(&metadata) && can_receive_paired_fungible_asset(
account_addr,
option::destroy_some(metadata)
)) {
diff --git a/aptos-move/framework/aptos-framework/sources/coin.move b/aptos-move/framework/aptos-framework/sources/coin.move
index a7fda35ce3eeb..2ea6aca5762ec 100644
--- a/aptos-move/framework/aptos-framework/sources/coin.move
+++ b/aptos-move/framework/aptos-framework/sources/coin.move
@@ -695,7 +695,7 @@ module aptos_framework::coin {
let paired_metadata_opt = paired_metadata();
(option::is_some(
&paired_metadata_opt
- ) && migrated_primary_fungible_store_exists(account_addr, option::destroy_some(paired_metadata_opt)))
+ ) && can_receive_paired_fungible_asset(account_addr, option::destroy_some(paired_metadata_opt)))
}
}
@@ -814,7 +814,7 @@ module aptos_framework::coin {
merge(&mut coin_store.coin, coin);
} else {
let metadata = paired_metadata();
- if (option::is_some(&metadata) && migrated_primary_fungible_store_exists(
+ if (option::is_some(&metadata) && can_receive_paired_fungible_asset(
account_addr,
option::destroy_some(metadata)
)) {
@@ -825,11 +825,11 @@ module aptos_framework::coin {
}
}
- inline fun migrated_primary_fungible_store_exists(
+ inline fun can_receive_paired_fungible_asset(
account_address: address,
metadata: Object
): bool {
- features::new_accounts_default_to_fa_apt_store_enabled() || {
+ (features::new_accounts_default_to_fa_apt_store_enabled() && object::object_address(&metadata) == @0xa) || {
let primary_store_address = primary_fungible_store::primary_store_address(
account_address,
metadata
@@ -849,7 +849,7 @@ module aptos_framework::coin {
merge(&mut coin_store.coin, coin);
} else {
let metadata = paired_metadata();
- if (option::is_some(&metadata) && migrated_primary_fungible_store_exists(
+ if (option::is_some(&metadata) && can_receive_paired_fungible_asset(
account_addr,
option::destroy_some(metadata)
)) {
@@ -1924,6 +1924,7 @@ module aptos_framework::coin {
account::create_account_for_test(bob_addr);
let (burn_cap, freeze_cap, mint_cap) = initialize_and_register_fake_money(account, 1, true);
maybe_convert_to_fungible_store(aaron_addr);
+ maybe_convert_to_fungible_store(bob_addr);
deposit(aaron_addr, mint(1, &mint_cap));
force_deposit(account_addr, mint(100, &mint_cap));
@@ -1991,7 +1992,7 @@ module aptos_framework::coin {
});
}
- #[test(account = @aptos_framework, aaron = @0xaa10)]
+ #[test(account = @aptos_framework)]
fun test_migration_with_existing_primary_fungible_store(
account: &signer,
) acquires CoinConversionMap, CoinInfo, CoinStore, PairedCoinType {
@@ -2004,7 +2005,7 @@ module aptos_framework::coin {
assert!(coin_balance(account_addr) == 0, 0);
assert!(balance(account_addr) == 100, 0);
let coin = withdraw(account, 50);
- assert!(migrated_primary_fungible_store_exists(account_addr, ensure_paired_metadata()), 0);
+ assert!(can_receive_paired_fungible_asset(account_addr, ensure_paired_metadata()), 0);
maybe_convert_to_fungible_store(account_addr);
deposit(account_addr, coin);
assert!(coin_balance(account_addr) == 0, 0);
diff --git a/aptos-move/framework/aptos-framework/sources/resource_account.move b/aptos-move/framework/aptos-framework/sources/resource_account.move
index 4930be2ba4fd1..6b8362d0df0a6 100644
--- a/aptos-move/framework/aptos-framework/sources/resource_account.move
+++ b/aptos-move/framework/aptos-framework/sources/resource_account.move
@@ -229,7 +229,7 @@ module aptos_framework::resource_account {
}
#[test(framework = @0x1, user = @0x1234)]
- public entry fun with_coin(framework: signer, user: signer) acquires Container {
+ public entry fun with_coin_registered(framework: signer, user: signer) acquires Container {
let user_addr = signer::address_of(&user);
let (burn, mint) = aptos_framework::aptos_coin::initialize_for_test(&framework);
aptos_framework::aptos_account::create_account(copy user_addr);
@@ -248,7 +248,7 @@ module aptos_framework::resource_account {
}
#[test(framework = @0x1, user = @0x2345)]
- public entry fun without_coin(framework: signer, user: signer) acquires Container {
+ public entry fun without_coin_registered(framework: signer, user: signer) acquires Container {
let user_addr = signer::address_of(&user);
let (burn, mint) = aptos_framework::aptos_coin::initialize_for_test(&framework);
aptos_framework::aptos_account::create_account(user_addr);
diff --git a/execution/executor-benchmark/src/db_access.rs b/execution/executor-benchmark/src/db_access.rs
index a5eecba9251a8..02824455d97bd 100644
--- a/execution/executor-benchmark/src/db_access.rs
+++ b/execution/executor-benchmark/src/db_access.rs
@@ -10,7 +10,7 @@ use aptos_types::{
FungibleStoreResource, ObjectCoreResource, ObjectGroupResource, TypeInfoResource,
},
event::{EventHandle, EventKey},
- state_store::{state_key::StateKey, StateView},
+ state_store::{state_key::StateKey, StateView, TStateView},
write_set::TOTAL_SUPPLY_STATE_KEY,
AptosCoinType, CoinType,
};
@@ -22,7 +22,6 @@ use move_core_types::{
};
use serde::de::DeserializeOwned;
use std::{collections::BTreeMap, str::FromStr};
-use aptos_types::state_store::TStateView;
pub struct CommonStructTags {
pub account: StructTag,
@@ -130,7 +129,7 @@ impl DbAccessUtil {
&ObjectGroupResource::struct_tag(),
),
)
- .expect("account must exist in data store");
+ .expect("account must exist in data store");
let group: Option>> = bytes_opt
.map(|bytes| bcs::from_bytes(&bytes))
.transpose()
diff --git a/execution/executor-benchmark/src/db_reliable_submitter.rs b/execution/executor-benchmark/src/db_reliable_submitter.rs
index f716b77516c8c..5dc8237081a30 100644
--- a/execution/executor-benchmark/src/db_reliable_submitter.rs
+++ b/execution/executor-benchmark/src/db_reliable_submitter.rs
@@ -31,10 +31,13 @@ pub struct DbReliableTransactionSubmitter {
impl ReliableTransactionSubmitter for DbReliableTransactionSubmitter {
async fn get_account_balance(&self, account_address: AccountAddress) -> Result {
let db_state_view = self.db.reader.latest_state_checkpoint_view().unwrap();
- let sender_coin_store_key = DbAccessUtil::new_state_key_aptos_coin(account_address);
- let coin = DbAccessUtil::get_db_value::>(&sender_coin_store_key, &db_state_view)?
- .map(|x| x.coin)
- .unwrap_or(0);
+ let sender_coin_store_key = DbAccessUtil::new().new_state_key_aptos_coin(&account_address);
+ let coin = DbAccessUtil::get_value::>(
+ &sender_coin_store_key,
+ &db_state_view,
+ )?
+ .map(|x| x.coin())
+ .unwrap_or(0);
let fa = DbAccessUtil::get_fa_store(account_address, &db_state_view)
.map(|x| x.balance())
.unwrap_or(0);
diff --git a/execution/executor/tests/db_bootstrapper_test.rs b/execution/executor/tests/db_bootstrapper_test.rs
index 81514fd7e178f..d050e0b059ef3 100644
--- a/execution/executor/tests/db_bootstrapper_test.rs
+++ b/execution/executor/tests/db_bootstrapper_test.rs
@@ -183,29 +183,29 @@ fn get_balance(account: &AccountAddress, db: &DbReaderWriter) -> u64 {
.map(|x| x.coin())
.unwrap_or(0)
+ {
- let bytes_opt = TStateView::get_state_value_bytes(
- &db_state_view,
- &StateKey::resource_group(
- &get_apt_primary_store_address(*account),
- &ObjectGroupResource::struct_tag(),
- ),
- )
+ let bytes_opt = TStateView::get_state_value_bytes(
+ &db_state_view,
+ &StateKey::resource_group(
+ &get_apt_primary_store_address(*account),
+ &ObjectGroupResource::struct_tag(),
+ ),
+ )
.expect("account must exist in data store");
- let group: Option>> = bytes_opt
- .map(|bytes| bcs::from_bytes(&bytes))
- .transpose()
- .unwrap();
- group
- .and_then(|g| {
- g.get(&FungibleStoreResource::struct_tag())
- .map(|b| bcs::from_bytes(b))
- })
- .transpose()
- .unwrap()
- .map(|x: FungibleStoreResource| x.balance())
- .unwrap_or(0)
- }
+ let group: Option>> = bytes_opt
+ .map(|bytes| bcs::from_bytes(&bytes))
+ .transpose()
+ .unwrap();
+ group
+ .and_then(|g| {
+ g.get(&FungibleStoreResource::struct_tag())
+ .map(|b| bcs::from_bytes(b))
+ })
+ .transpose()
+ .unwrap()
+ .map(|x: FungibleStoreResource| x.balance())
+ .unwrap_or(0)
+ }
}
fn get_configuration(db: &DbReaderWriter) -> ConfigurationResource {
diff --git a/types/src/state_store/mod.rs b/types/src/state_store/mod.rs
index 7456b439d6287..8a20b09404e5e 100644
--- a/types/src/state_store/mod.rs
+++ b/types/src/state_store/mod.rs
@@ -14,6 +14,7 @@ use bytes::Bytes;
use move_core_types::move_resource::MoveResource;
#[cfg(any(test, feature = "testing"))]
use std::hash::Hash;
+#[cfg(any(test, feature = "testing"))]
use std::{collections::HashMap, ops::Deref};
pub mod errors;