Skip to content

Commit

Permalink
fixup! [FA] get rid of migration flag
Browse files Browse the repository at this point in the history
  • Loading branch information
lightmark committed Nov 28, 2024
1 parent def289d commit 8f6fd82
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 46 deletions.
18 changes: 9 additions & 9 deletions aptos-move/framework/aptos-framework/doc/coin.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -2344,7 +2344,7 @@ Returns <code><b>true</b></code> if <code>account_addr</code> is registered to r
<b>let</b> paired_metadata_opt = <a href="coin.md#0x1_coin_paired_metadata">paired_metadata</a>&lt;CoinType&gt;();
(<a href="../../aptos-stdlib/../move-stdlib/doc/option.md#0x1_option_is_some">option::is_some</a>(
&paired_metadata_opt
) && <a href="coin.md#0x1_coin_migrated_primary_fungible_store_exists">migrated_primary_fungible_store_exists</a>(account_addr, <a href="../../aptos-stdlib/../move-stdlib/doc/option.md#0x1_option_destroy_some">option::destroy_some</a>(paired_metadata_opt)))
) && <a href="coin.md#0x1_coin_can_receive_paired_fungible_asset">can_receive_paired_fungible_asset</a>(account_addr, <a href="../../aptos-stdlib/../move-stdlib/doc/option.md#0x1_option_destroy_some">option::destroy_some</a>(paired_metadata_opt)))
}
}
</code></pre>
Expand Down Expand Up @@ -2620,7 +2620,7 @@ Deposit the coin balance into the recipient's account and emit an event.
<a href="coin.md#0x1_coin_merge">merge</a>(&<b>mut</b> coin_store.<a href="coin.md#0x1_coin">coin</a>, <a href="coin.md#0x1_coin">coin</a>);
} <b>else</b> {
<b>let</b> metadata = <a href="coin.md#0x1_coin_paired_metadata">paired_metadata</a>&lt;CoinType&gt;();
<b>if</b> (<a href="../../aptos-stdlib/../move-stdlib/doc/option.md#0x1_option_is_some">option::is_some</a>(&metadata) && <a href="coin.md#0x1_coin_migrated_primary_fungible_store_exists">migrated_primary_fungible_store_exists</a>(
<b>if</b> (<a href="../../aptos-stdlib/../move-stdlib/doc/option.md#0x1_option_is_some">option::is_some</a>(&metadata) && <a href="coin.md#0x1_coin_can_receive_paired_fungible_asset">can_receive_paired_fungible_asset</a>(
account_addr,
<a href="../../aptos-stdlib/../move-stdlib/doc/option.md#0x1_option_destroy_some">option::destroy_some</a>(metadata)
)) {
Expand All @@ -2636,13 +2636,13 @@ Deposit the coin balance into the recipient's account and emit an event.

</details>

<a id="0x1_coin_migrated_primary_fungible_store_exists"></a>
<a id="0x1_coin_can_receive_paired_fungible_asset"></a>

## Function `migrated_primary_fungible_store_exists`
## Function `can_receive_paired_fungible_asset`



<pre><code><b>fun</b> <a href="coin.md#0x1_coin_migrated_primary_fungible_store_exists">migrated_primary_fungible_store_exists</a>(account_address: <b>address</b>, metadata: <a href="object.md#0x1_object_Object">object::Object</a>&lt;<a href="fungible_asset.md#0x1_fungible_asset_Metadata">fungible_asset::Metadata</a>&gt;): bool
<pre><code><b>fun</b> <a href="coin.md#0x1_coin_can_receive_paired_fungible_asset">can_receive_paired_fungible_asset</a>(account_address: <b>address</b>, metadata: <a href="object.md#0x1_object_Object">object::Object</a>&lt;<a href="fungible_asset.md#0x1_fungible_asset_Metadata">fungible_asset::Metadata</a>&gt;): bool
</code></pre>


Expand All @@ -2651,11 +2651,11 @@ Deposit the coin balance into the recipient's account and emit an event.
<summary>Implementation</summary>


<pre><code>inline <b>fun</b> <a href="coin.md#0x1_coin_migrated_primary_fungible_store_exists">migrated_primary_fungible_store_exists</a>(
<pre><code>inline <b>fun</b> <a href="coin.md#0x1_coin_can_receive_paired_fungible_asset">can_receive_paired_fungible_asset</a>(
account_address: <b>address</b>,
metadata: Object&lt;Metadata&gt;
): bool {
<a href="../../aptos-stdlib/../move-stdlib/doc/features.md#0x1_features_new_accounts_default_to_fa_apt_store_enabled">features::new_accounts_default_to_fa_apt_store_enabled</a>() || {
(<a href="../../aptos-stdlib/../move-stdlib/doc/features.md#0x1_features_new_accounts_default_to_fa_apt_store_enabled">features::new_accounts_default_to_fa_apt_store_enabled</a>() && <a href="object.md#0x1_object_object_address">object::object_address</a>(&metadata) == @0xa) || {
<b>let</b> primary_store_address = <a href="primary_fungible_store.md#0x1_primary_fungible_store_primary_store_address">primary_fungible_store::primary_store_address</a>&lt;Metadata&gt;(
account_address,
metadata
Expand Down Expand Up @@ -2695,7 +2695,7 @@ This is for internal use only and doesn't emit an DepositEvent.
<a href="coin.md#0x1_coin_merge">merge</a>(&<b>mut</b> coin_store.<a href="coin.md#0x1_coin">coin</a>, <a href="coin.md#0x1_coin">coin</a>);
} <b>else</b> {
<b>let</b> metadata = <a href="coin.md#0x1_coin_paired_metadata">paired_metadata</a>&lt;CoinType&gt;();
<b>if</b> (<a href="../../aptos-stdlib/../move-stdlib/doc/option.md#0x1_option_is_some">option::is_some</a>(&metadata) && <a href="coin.md#0x1_coin_migrated_primary_fungible_store_exists">migrated_primary_fungible_store_exists</a>(
<b>if</b> (<a href="../../aptos-stdlib/../move-stdlib/doc/option.md#0x1_option_is_some">option::is_some</a>(&metadata) && <a href="coin.md#0x1_coin_can_receive_paired_fungible_asset">can_receive_paired_fungible_asset</a>(
account_addr,
<a href="../../aptos-stdlib/../move-stdlib/doc/option.md#0x1_option_destroy_some">option::destroy_some</a>(metadata)
)) {
Expand Down
15 changes: 8 additions & 7 deletions aptos-move/framework/aptos-framework/sources/coin.move
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ module aptos_framework::coin {
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)))
}
}

Expand Down Expand Up @@ -814,7 +814,7 @@ module aptos_framework::coin {
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)
)) {
Expand All @@ -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<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
Expand All @@ -849,7 +849,7 @@ module aptos_framework::coin {
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)
)) {
Expand Down Expand Up @@ -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<FakeMoney>(aaron_addr);
maybe_convert_to_fungible_store<FakeMoney>(bob_addr);
deposit(aaron_addr, mint<FakeMoney>(1, &mint_cap));

force_deposit(account_addr, mint<FakeMoney>(100, &mint_cap));
Expand Down Expand Up @@ -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 {
Expand All @@ -2004,7 +2005,7 @@ module aptos_framework::coin {
assert!(coin_balance<FakeMoney>(account_addr) == 0, 0);
assert!(balance<FakeMoney>(account_addr) == 100, 0);
let coin = withdraw<FakeMoney>(account, 50);
assert!(migrated_primary_fungible_store_exists(account_addr, ensure_paired_metadata<FakeMoney>()), 0);
assert!(can_receive_paired_fungible_asset(account_addr, ensure_paired_metadata<FakeMoney>()), 0);
maybe_convert_to_fungible_store<FakeMoney>(account_addr);
deposit(account_addr, coin);
assert!(coin_balance<FakeMoney>(account_addr) == 0, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
5 changes: 2 additions & 3 deletions execution/executor-benchmark/src/db_access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand All @@ -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,
Expand Down Expand Up @@ -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<BTreeMap<StructTag, Vec<u8>>> = bytes_opt
.map(|bytes| bcs::from_bytes(&bytes))
.transpose()
Expand Down
11 changes: 7 additions & 4 deletions execution/executor-benchmark/src/db_reliable_submitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,13 @@ pub struct DbReliableTransactionSubmitter {
impl ReliableTransactionSubmitter for DbReliableTransactionSubmitter {
async fn get_account_balance(&self, account_address: AccountAddress) -> Result<u64> {
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::<CoinStoreResource<AptosCoinType>>(&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::<CoinStoreResource<AptosCoinType>>(
&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);
Expand Down
42 changes: 21 additions & 21 deletions execution/executor/tests/db_bootstrapper_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<BTreeMap<StructTag, Vec<u8>>> = 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<BTreeMap<StructTag, Vec<u8>>> = 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 {
Expand Down
1 change: 1 addition & 0 deletions types/src/state_store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 8f6fd82

Please sign in to comment.