From 399656746207f155136fad901c13d3aa9cc977ec Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Thu, 17 Aug 2023 21:00:59 +0200 Subject: [PATCH] fixed few errors discovered by multiasset_test, still problem with emmit --- src/currency_core/blockchain_storage.cpp | 17 +++++++++++------ src/currency_core/currency_basic.h | 2 ++ src/currency_core/currency_format_utils.cpp | 5 +++-- src/wallet/wallet2.cpp | 4 ++++ tests/core_tests/multiassets_test.cpp | 8 ++++---- 5 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/currency_core/blockchain_storage.cpp b/src/currency_core/blockchain_storage.cpp index db7e829b..1fbc228f 100644 --- a/src/currency_core/blockchain_storage.cpp +++ b/src/currency_core/blockchain_storage.cpp @@ -3865,11 +3865,12 @@ bool blockchain_storage::put_asset_info(const transaction& tx, const crypto::has } avc.amout_to_validate = 0; - //validate balance proof + bool need_to_validate_balance_proof = true; if (ado.operation_type == ASSET_DESCRIPTOR_OPERATION_UPDATE) { //check that total current_supply haven't changed - CHECK_AND_ASSERT_MES(ado.descriptor.current_supply != avc.asset_op_history->back().descriptor.current_supply, false, "update operation actually try to change emission, failed"); + CHECK_AND_ASSERT_MES(ado.descriptor.current_supply == avc.asset_op_history->back().descriptor.current_supply, false, "update operation actually try to change emission, failed"); + need_to_validate_balance_proof = false; } else if (ado.operation_type == ASSET_DESCRIPTOR_OPERATION_EMMIT) { @@ -3886,13 +3887,17 @@ bool blockchain_storage::put_asset_info(const transaction& tx, const crypto::has LOG_ERROR("Unknown operation type: " << ado.operation_type); return false; } - bool r = validate_asset_operation_balance_proof(avc); - CHECK_AND_ASSERT_MES(r, false, "Balance proof validation failed for asset_descriptor_operation"); + if (need_to_validate_balance_proof) + { + bool r = validate_asset_operation_balance_proof(avc); + CHECK_AND_ASSERT_MES(r, false, "Balance proof validation failed for asset_descriptor_operation"); + } + assets_container::t_value_type local_asset_history = *avc.asset_op_history; local_asset_history.push_back(ado); - m_db_assets.set(avc.asset_id, local_asset_history); - LOG_PRINT_MAGENTA("[ASSET_UPDATED]: " << avc.asset_id << ": " << ado.descriptor.full_name, LOG_LEVEL_1); + m_db_assets.set(*avc.ado.opt_asset_id, local_asset_history); + LOG_PRINT_MAGENTA("[ASSET_UPDATED]: " << *avc.ado.opt_asset_id << ": " << ado.descriptor.full_name, LOG_LEVEL_1); //TODO: //rise_core_event(CORE_EVENT_ADD_ASSET, alias_info_to_rpc_alias_info(ai)); diff --git a/src/currency_core/currency_basic.h b/src/currency_core/currency_basic.h index d7c5b538..0816f5ad 100644 --- a/src/currency_core/currency_basic.h +++ b/src/currency_core/currency_basic.h @@ -769,6 +769,7 @@ namespace currency BOOST_SERIALIZE(full_name) BOOST_SERIALIZE(meta_info) BOOST_SERIALIZE(owner) + BOOST_SERIALIZE(hidden_supply) END_BOOST_SERIALIZATION() BEGIN_KV_SERIALIZE_MAP() @@ -779,6 +780,7 @@ namespace currency KV_SERIALIZE(full_name) KV_SERIALIZE(meta_info) KV_SERIALIZE_POD_AS_HEX_STRING(owner) + KV_SERIALIZE(hidden_supply) END_KV_SERIALIZE_MAP() }; diff --git a/src/currency_core/currency_format_utils.cpp b/src/currency_core/currency_format_utils.cpp index e59e5b3b..137898fa 100644 --- a/src/currency_core/currency_format_utils.cpp +++ b/src/currency_core/currency_format_utils.cpp @@ -2133,9 +2133,10 @@ namespace currency uint64_t amount_of_emitted_asset = 0; for (auto& item : shuffled_dsts) { - if (item.asset_id == gen_context.ao_asset_id) + if (item.asset_id == currency::null_pkey) { amount_of_emitted_asset += item.amount; + item.asset_id = gen_context.ao_asset_id; } } ado.descriptor.current_supply += amount_of_emitted_asset; // TODO: consider setting current_supply beforehand, not setting it hear in ad-hoc manner -- sowle @@ -2147,7 +2148,7 @@ namespace currency else if (ado.operation_type == ASSET_DESCRIPTOR_OPERATION_UPDATE) { CHECK_AND_ASSERT_MES(ado.opt_asset_id, false, "ado.opt_asset_id is not found at ado.operation_type == ASSET_DESCRIPTOR_OPERATION_EMMIT/UPDATE"); - CHECK_AND_ASSERT_MES(ado.opt_proof, false, "ado.opt_asset_id is not found at ado.operation_type == ASSET_DESCRIPTOR_OPERATION_EMMIT/UPDATE"); + //CHECK_AND_ASSERT_MES(ado.opt_proof, false, "ado.opt_asset_id is not found at ado.operation_type == ASSET_DESCRIPTOR_OPERATION_EMMIT/UPDATE"); CHECK_AND_ASSERT_MES(!ado.opt_amount_commitment, false, "ado.opt_asset_id is not found at ado.operation_type == ASSET_DESCRIPTOR_OPERATION_EMMIT/UPDATE"); //fields that not supposed to be changed? diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 75e05230..7d9951ae 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -443,6 +443,7 @@ void wallet2::process_ado_in_new_transaction(const currency::asset_descriptor_op WLT_THROW_IF_FALSE_WALLET_CMN_ERR_EX(m_own_asset_descriptors.count(asset_id) == 0, "asset with asset_id " << asset_id << " has already been registered in the wallet as own asset"); wallet_own_asset_context& asset_context = m_own_asset_descriptors[asset_id]; asset_context.asset_descriptor = ado.descriptor; + asset_context.control_key = asset_control_key; std::stringstream ss; ss << "New Asset Registered:" @@ -4725,6 +4726,7 @@ void wallet2::emmit_asset(const crypto::public_key asset_id, std::vectorsecond.asset_descriptor; asset_emmit_info.operation_type = ASSET_DESCRIPTOR_OPERATION_EMMIT; + asset_emmit_info.opt_asset_id = asset_id; construct_tx_param ctp = get_default_construct_tx_param(); ctp.dsts = destinations; ctp.extra.push_back(asset_emmit_info); @@ -4744,6 +4746,7 @@ void wallet2::update_asset(const crypto::public_key asset_id, const currency::as asset_descriptor_operation asset_update_info = AUTO_VAL_INIT(asset_update_info); asset_update_info.descriptor = new_descriptor; asset_update_info.operation_type = ASSET_DESCRIPTOR_OPERATION_UPDATE; + asset_update_info.opt_asset_id = asset_id; construct_tx_param ctp = get_default_construct_tx_param(); ctp.extra.push_back(asset_update_info); ctp.need_at_least_1_zc = true; @@ -4769,6 +4772,7 @@ void wallet2::burn_asset(const crypto::public_key asset_id, uint64_t amount_to_b dst_to_burn.asset_id = asset_id; asset_burn_info.operation_type = ASSET_DESCRIPTOR_OPERATION_PUBLIC_BURN; + asset_burn_info.opt_asset_id = asset_id; construct_tx_param ctp = get_default_construct_tx_param(); ctp.extra.push_back(asset_burn_info); ctp.need_at_least_1_zc = true; diff --git a/tests/core_tests/multiassets_test.cpp b/tests/core_tests/multiassets_test.cpp index e269dbd5..f629d0af 100644 --- a/tests/core_tests/multiassets_test.cpp +++ b/tests/core_tests/multiassets_test.cpp @@ -120,10 +120,6 @@ bool multiassets_basic_test::c1(currency::core& c, size_t ev_index, const std::v - miner_wlt->refresh(); - uint64_t last_miner_balance = miner_wlt->balance(asset_id, mined); - - { try { @@ -138,6 +134,10 @@ bool multiassets_basic_test::c1(currency::core& c, size_t ev_index, const std::v } } + miner_wlt->refresh(); + uint64_t last_miner_balance = miner_wlt->balance(asset_id, mined); + + asset_descriptor_base asset_info = AUTO_VAL_INIT(asset_info); /* adb.total_max_supply = 1000000000000000000; //1M coins