Skip to content

Commit

Permalink
[asset-mapping] reformat codes And add some debug logs
Browse files Browse the repository at this point in the history
  • Loading branch information
welbon committed Jan 10, 2025
1 parent c031cd9 commit bf6dbad
Show file tree
Hide file tree
Showing 21 changed files with 370 additions and 193 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions asset-mapping/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ bcs-ext = { workspace = true }
forkable-jellyfish-merkle = { workspace = true }
starcoin-transaction-builder = { workspace = true }
starcoin-chain = { workspace = true }
starcoin-config = { workspace = true }
starcoin-consensus = { workspace = true }
starcoin-crypto = { workspace = true }
starcoin-types = { workspace = true }
starcoin-cached-packages = { workspace = true }
starcoin-logger = { workspace = true }
starcoin-state-api = { workspace = true }
starcoin-types = { workspace = true }
starcoin-vm-types = { workspace = true }
starcoin-config = { workspace = true }
test-helper = { workspace = true }
starcoin-cached-packages = { workspace = true }
test-helper = { workspace = true }
26 changes: 18 additions & 8 deletions asset-mapping/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,10 @@ fn test_asset_mapping_for_specified_coin_type() -> Result<()> {

#[test]
fn test_asset_mapping_whole_process() -> Result<()> {
starcoin_logger::init_for_test();

let block_gas_limit: u64 = 10000000;
let initial_balance: u128 = 1000000000000;
let initial_balance: u128 = 100000000000; // 1000 STC
let receiver = AccountAddress::from_str("0xd0c5a06ae6100ce115cad1600fe59e96").unwrap();

// Create a source BlockChain
Expand Down Expand Up @@ -202,10 +204,19 @@ fn test_asset_mapping_whole_process() -> Result<()> {
.get_sequence_number(genesis_address())?
};

// Transfer STC from association account to receiver account
let peer_to_peer_txn =
{ local_build_peer_to_peer_from_association(&block_chain, receiver, 1, &net)? };
local_block_chain_excecute_txn(&mut block_chain, peer_to_peer_txn)?;
{
// Transfer STC from association account to receiver account
let peer_to_peer_txn =
{ local_build_peer_to_peer_from_association(&block_chain, receiver, 1, &net)? };
local_block_chain_excecute_txn(&mut block_chain, peer_to_peer_txn)?;
}

{
// Transfer STC from association account to framework account for gas fee
let peer_to_peer_txn =
{ local_build_peer_to_peer_from_association(&block_chain, AccountAddress::from_hex_literal("0x1").unwrap(), 1000000000, &net)? };
local_block_chain_excecute_txn(&mut block_chain, peer_to_peer_txn)?;
}

// Verify proof and assign asset mapping to receiver account
local_block_chain_excecute_txn(
Expand All @@ -221,7 +232,7 @@ fn test_asset_mapping_whole_process() -> Result<()> {
),
genesis_sequence_number,
DEFAULT_MAX_GAS_AMOUNT,
block_gas_limit,
1,
DEFAULT_EXPIRATION_TIME,
net.chain_id(),
),
Expand Down Expand Up @@ -265,14 +276,13 @@ fn local_block_chain_excecute_txn(
chain: &mut BlockChain,
txn: SignedUserTransaction,
) -> Result<()> {
let block_gas_limit: u64 = 10000000;
let (block_template, excluded) = chain
.create_block_template(
account_config::association_address(),
None,
vec![txn],
vec![],
Some(block_gas_limit),
Some(DEFAULT_MAX_GAS_AMOUNT),
None,
)
.unwrap();
Expand Down
2 changes: 1 addition & 1 deletion config/src/genesis_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1173,7 +1173,7 @@ pub static G_MAIN_CONFIG: Lazy<GenesisConfig> = Lazy::new(|| {
},
transaction_timeout: ONE_DAY,
dag_effective_height: u64::MAX,
// TODO(BobOng): to confirm the asset mapping proof root hash
// TODO(BobOng): [asset-mapping] To confirm the asset mapping proof root hash
asset_mapping_root_hash: HashValue::zero(),
}
});
Expand Down
209 changes: 104 additions & 105 deletions vm/framework/starcoin-framework/doc/asset_mapping.md

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions vm/framework/starcoin-framework/doc/coin.md
Original file line number Diff line number Diff line change
Expand Up @@ -1450,12 +1450,25 @@ Create STC pairing by passing <code>StarcoinCoin</code>.
<b>let</b> map = <b>borrow_global_mut</b>&lt;<a href="coin.md#0x1_coin_CoinConversionMap">CoinConversionMap</a>&gt;(@starcoin_framework);
<b>let</b> type = <a href="../../starcoin-stdlib/doc/type_info.md#0x1_type_info_type_of">type_info::type_of</a>&lt;CoinType&gt;();
<b>if</b> (!<a href="../../starcoin-stdlib/doc/table.md#0x1_table_contains">table::contains</a>(&map.coin_to_fungible_asset_map, type)) {
<a href="../../starcoin-stdlib/doc/debug.md#0x1_debug_print">debug::print</a>(
&std::string::utf8(b"<a href="coin.md#0x1_coin_create_and_return_paired_metadata_if_not_exist">coin::create_and_return_paired_metadata_if_not_exist</a> | map not contain type")
);
<b>let</b> is_stc = <a href="coin.md#0x1_coin_is_stc">is_stc</a>&lt;CoinType&gt;();
<b>assert</b>!(!is_stc || allow_stc_creation, <a href="../../move-stdlib/doc/error.md#0x1_error_invalid_state">error::invalid_state</a>(<a href="coin.md#0x1_coin_EAPT_PAIRING_IS_NOT_ENABLED">EAPT_PAIRING_IS_NOT_ENABLED</a>));
<b>let</b> metadata_object_cref =
<b>if</b> (is_stc) {
<a href="../../starcoin-stdlib/doc/debug.md#0x1_debug_print">debug::print</a>(
&std::string::utf8(
b"<a href="coin.md#0x1_coin_create_and_return_paired_metadata_if_not_exist">coin::create_and_return_paired_metadata_if_not_exist</a> | type is stc, create sticky <a href="object.md#0x1_object">object</a> at 0x1"
)
);
<a href="object.md#0x1_object_create_sticky_object_at_address">object::create_sticky_object_at_address</a>(@starcoin_framework, @starcoin_fungible_asset)
} <b>else</b> {
<a href="../../starcoin-stdlib/doc/debug.md#0x1_debug_print">debug::print</a>(
&std::string::utf8(
b"<a href="coin.md#0x1_coin_create_and_return_paired_metadata_if_not_exist">coin::create_and_return_paired_metadata_if_not_exist</a> | type is not stc, create new asset sub <a href="object.md#0x1_object">object</a>"
)
);
<a href="object.md#0x1_object_create_named_object">object::create_named_object</a>(
&<a href="create_signer.md#0x1_create_signer_create_signer">create_signer::create_signer</a>(@starcoin_fungible_asset),
*<a href="../../move-stdlib/doc/string.md#0x1_string_bytes">string::bytes</a>(&<a href="../../starcoin-stdlib/doc/type_info.md#0x1_type_info_type_name">type_info::type_name</a>&lt;CoinType&gt;())
Expand Down
15 changes: 15 additions & 0 deletions vm/framework/starcoin-framework/doc/fungible_asset.md
Original file line number Diff line number Diff line change
Expand Up @@ -2593,6 +2593,9 @@ Applications can use this to create multiple stores for isolating fungible asset
constructor_ref: &ConstructorRef,
metadata: Object&lt;T&gt;,
): Object&lt;<a href="fungible_asset.md#0x1_fungible_asset_FungibleStore">FungibleStore</a>&gt; {
<a href="../../starcoin-stdlib/doc/debug.md#0x1_debug_print">debug::print</a>(&<a href="../../move-stdlib/doc/string.md#0x1_string_utf8">string::utf8</a>(b"<a href="fungible_asset.md#0x1_fungible_asset_create_store">fungible_asset::create_store</a> | entered"));
<a href="../../starcoin-stdlib/doc/debug.md#0x1_debug_print">debug::print</a>(constructor_ref);

<b>let</b> store_obj = &<a href="object.md#0x1_object_generate_signer">object::generate_signer</a>(constructor_ref);
<b>move_to</b>(store_obj, <a href="fungible_asset.md#0x1_fungible_asset_FungibleStore">FungibleStore</a> {
metadata: <a href="object.md#0x1_object_convert">object::convert</a>(metadata),
Expand All @@ -2610,6 +2613,8 @@ Applications can use this to create multiple stores for isolating fungible asset
});
};

<a href="../../starcoin-stdlib/doc/debug.md#0x1_debug_print">debug::print</a>(&<a href="../../move-stdlib/doc/string.md#0x1_string_utf8">string::utf8</a>(b"<a href="fungible_asset.md#0x1_fungible_asset_create_store">fungible_asset::create_store</a> | exited"));

<a href="object.md#0x1_object_object_from_constructor_ref">object::object_from_constructor_ref</a>&lt;<a href="fungible_asset.md#0x1_fungible_asset_FungibleStore">FungibleStore</a>&gt;(constructor_ref)
}
</code></pre>
Expand All @@ -2635,6 +2640,9 @@ Used to delete a store. Requires the store to be completely empty prior to remo


<pre><code><b>public</b> <b>fun</b> <a href="fungible_asset.md#0x1_fungible_asset_remove_store">remove_store</a>(delete_ref: &DeleteRef) <b>acquires</b> <a href="fungible_asset.md#0x1_fungible_asset_FungibleStore">FungibleStore</a>, <a href="fungible_asset.md#0x1_fungible_asset_FungibleAssetEvents">FungibleAssetEvents</a>, <a href="fungible_asset.md#0x1_fungible_asset_ConcurrentFungibleBalance">ConcurrentFungibleBalance</a> {
<a href="../../starcoin-stdlib/doc/debug.md#0x1_debug_print">debug::print</a>(&<a href="../../move-stdlib/doc/string.md#0x1_string_utf8">string::utf8</a>(b"<a href="fungible_asset.md#0x1_fungible_asset_remove_store">fungible_asset::remove_store</a> | entered"));
<a href="../../starcoin-stdlib/doc/debug.md#0x1_debug_print">debug::print</a>(delete_ref);

<b>let</b> store = &<a href="object.md#0x1_object_object_from_delete_ref">object::object_from_delete_ref</a>&lt;<a href="fungible_asset.md#0x1_fungible_asset_FungibleStore">FungibleStore</a>&gt;(delete_ref);
<b>let</b> addr = <a href="object.md#0x1_object_object_address">object::object_address</a>(store);
<b>let</b> <a href="fungible_asset.md#0x1_fungible_asset_FungibleStore">FungibleStore</a> { metadata: _, balance, frozen: _ }
Expand All @@ -2657,6 +2665,7 @@ Used to delete a store. Requires the store to be completely empty prior to remo
<a href="event.md#0x1_event_destroy_handle">event::destroy_handle</a>(withdraw_events);
<a href="event.md#0x1_event_destroy_handle">event::destroy_handle</a>(frozen_events);
};
<a href="../../starcoin-stdlib/doc/debug.md#0x1_debug_print">debug::print</a>(&<a href="../../move-stdlib/doc/string.md#0x1_string_utf8">string::utf8</a>(b"<a href="fungible_asset.md#0x1_fungible_asset_remove_store">fungible_asset::remove_store</a> | exited"));
}
</code></pre>

Expand Down Expand Up @@ -2779,8 +2788,11 @@ Deposit <code>amount</code> of the fungible asset to <code>store</code>.


<pre><code><b>public</b> <b>fun</b> <a href="fungible_asset.md#0x1_fungible_asset_deposit">deposit</a>&lt;T: key&gt;(store: Object&lt;T&gt;, fa: <a href="fungible_asset.md#0x1_fungible_asset_FungibleAsset">FungibleAsset</a>) <b>acquires</b> <a href="fungible_asset.md#0x1_fungible_asset_FungibleStore">FungibleStore</a>, <a href="fungible_asset.md#0x1_fungible_asset_DispatchFunctionStore">DispatchFunctionStore</a>, <a href="fungible_asset.md#0x1_fungible_asset_ConcurrentFungibleBalance">ConcurrentFungibleBalance</a> {
<a href="../../starcoin-stdlib/doc/debug.md#0x1_debug_print">debug::print</a>(&<a href="../../move-stdlib/doc/string.md#0x1_string_utf8">string::utf8</a>(b"<a href="fungible_asset.md#0x1_fungible_asset_deposit">fungible_asset::deposit</a> | entered"));
<a href="../../starcoin-stdlib/doc/debug.md#0x1_debug_print">debug::print</a>(&store);
<a href="fungible_asset.md#0x1_fungible_asset_deposit_sanity_check">deposit_sanity_check</a>(store, <b>true</b>);
<a href="fungible_asset.md#0x1_fungible_asset_deposit_internal">deposit_internal</a>(<a href="object.md#0x1_object_object_address">object::object_address</a>(&store), fa);
<a href="../../starcoin-stdlib/doc/debug.md#0x1_debug_print">debug::print</a>(&<a href="../../move-stdlib/doc/string.md#0x1_string_utf8">string::utf8</a>(b"<a href="fungible_asset.md#0x1_fungible_asset_deposit">fungible_asset::deposit</a> | exited"));
}
</code></pre>

Expand Down Expand Up @@ -3564,8 +3576,11 @@ Decrease the supply of a fungible asset by burning.


<pre><code>inline <b>fun</b> <a href="fungible_asset.md#0x1_fungible_asset_borrow_store_resource">borrow_store_resource</a>&lt;T: key&gt;(store: &Object&lt;T&gt;): &<a href="fungible_asset.md#0x1_fungible_asset_FungibleStore">FungibleStore</a> <b>acquires</b> <a href="fungible_asset.md#0x1_fungible_asset_FungibleStore">FungibleStore</a> {
<a href="../../starcoin-stdlib/doc/debug.md#0x1_debug_print">debug::print</a>(&<a href="../../move-stdlib/doc/string.md#0x1_string_utf8">string::utf8</a>(b"<a href="fungible_asset.md#0x1_fungible_asset_borrow_store_resource">fungible_asset::borrow_store_resource</a> | entered"));
<b>let</b> store_addr = <a href="object.md#0x1_object_object_address">object::object_address</a>(store);
<a href="../../starcoin-stdlib/doc/debug.md#0x1_debug_print">debug::print</a>(&store_addr);
<b>assert</b>!(<b>exists</b>&lt;<a href="fungible_asset.md#0x1_fungible_asset_FungibleStore">FungibleStore</a>&gt;(store_addr), <a href="../../move-stdlib/doc/error.md#0x1_error_not_found">error::not_found</a>(<a href="fungible_asset.md#0x1_fungible_asset_EFUNGIBLE_STORE_EXISTENCE">EFUNGIBLE_STORE_EXISTENCE</a>));
<a href="../../starcoin-stdlib/doc/debug.md#0x1_debug_print">debug::print</a>(&<a href="../../move-stdlib/doc/string.md#0x1_string_utf8">string::utf8</a>(b"<a href="fungible_asset.md#0x1_fungible_asset_borrow_store_resource">fungible_asset::borrow_store_resource</a> | exited"));
<b>borrow_global</b>&lt;<a href="fungible_asset.md#0x1_fungible_asset_FungibleStore">FungibleStore</a>&gt;(store_addr)
}
</code></pre>
Expand Down
8 changes: 6 additions & 2 deletions vm/framework/starcoin-framework/doc/object.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,15 @@ make it so that a reference to a global object can be returned from a function.
<b>use</b> <a href="../../move-stdlib/doc/bcs.md#0x1_bcs">0x1::bcs</a>;
<b>use</b> <a href="bcs_util.md#0x1_bcs_util">0x1::bcs_util</a>;
<b>use</b> <a href="create_signer.md#0x1_create_signer">0x1::create_signer</a>;
<b>use</b> <a href="../../starcoin-stdlib/doc/debug.md#0x1_debug">0x1::debug</a>;
<b>use</b> <a href="../../move-stdlib/doc/error.md#0x1_error">0x1::error</a>;
<b>use</b> <a href="event.md#0x1_event">0x1::event</a>;
<b>use</b> <a href="../../move-stdlib/doc/features.md#0x1_features">0x1::features</a>;
<b>use</b> <a href="../../starcoin-stdlib/doc/from_bcs.md#0x1_from_bcs">0x1::from_bcs</a>;
<b>use</b> <a href="guid.md#0x1_guid">0x1::guid</a>;
<b>use</b> <a href="../../move-stdlib/doc/hash.md#0x1_hash">0x1::hash</a>;
<b>use</b> <a href="../../move-stdlib/doc/signer.md#0x1_signer">0x1::signer</a>;
<b>use</b> <a href="../../move-stdlib/doc/string.md#0x1_string">0x1::string</a>;
<b>use</b> <a href="transaction_context.md#0x1_transaction_context">0x1::transaction_context</a>;
<b>use</b> <a href="../../move-stdlib/doc/vector.md#0x1_vector">0x1::vector</a>;
</code></pre>
Expand Down Expand Up @@ -1329,7 +1331,9 @@ doesn't have the same bottlenecks.
<a href="object.md#0x1_object">object</a>: <b>address</b>,
can_delete: bool,
): <a href="object.md#0x1_object_ConstructorRef">ConstructorRef</a> {
// <a href="../../starcoin-stdlib/doc/debug.md#0x1_debug_print">debug::print</a>(&<a href="../../move-stdlib/doc/string.md#0x1_string_utf8">string::utf8</a>(b"<a href="object.md#0x1_object_create_object_internal">object::create_object_internal</a> | entered"));
<a href="../../starcoin-stdlib/doc/debug.md#0x1_debug_print">debug::print</a>(&<a href="../../move-stdlib/doc/string.md#0x1_string_utf8">string::utf8</a>(b"<a href="object.md#0x1_object_create_object_internal">object::create_object_internal</a> | entered"));
<a href="../../starcoin-stdlib/doc/debug.md#0x1_debug_print">debug::print</a>(&creator_address);
<a href="../../starcoin-stdlib/doc/debug.md#0x1_debug_print">debug::print</a>(&<a href="object.md#0x1_object">object</a>);

<b>assert</b>!(!<b>exists</b>&lt;<a href="object.md#0x1_object_ObjectCore">ObjectCore</a>&gt;(<a href="object.md#0x1_object">object</a>), <a href="../../move-stdlib/doc/error.md#0x1_error_already_exists">error::already_exists</a>(<a href="object.md#0x1_object_EOBJECT_EXISTS">EOBJECT_EXISTS</a>));

Expand All @@ -1347,7 +1351,7 @@ doesn't have the same bottlenecks.
},
);

// <a href="../../starcoin-stdlib/doc/debug.md#0x1_debug_print">debug::print</a>(&<a href="../../move-stdlib/doc/string.md#0x1_string_utf8">string::utf8</a>(b"<a href="object.md#0x1_object_create_object_internal">object::create_object_internal</a> | exited"));
<a href="../../starcoin-stdlib/doc/debug.md#0x1_debug_print">debug::print</a>(&<a href="../../move-stdlib/doc/string.md#0x1_string_utf8">string::utf8</a>(b"<a href="object.md#0x1_object_create_object_internal">object::create_object_internal</a> | exited"));
<a href="object.md#0x1_object_ConstructorRef">ConstructorRef</a> { self: <a href="object.md#0x1_object">object</a>, can_delete }
}
</code></pre>
Expand Down
Loading

0 comments on commit bf6dbad

Please sign in to comment.