From 5ab9a2b9743d202db05f3d10335ba51ee5aab372 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Fri, 30 Sep 2022 21:23:06 +0200 Subject: [PATCH] fixed compilation issues regarding asset_descriptors --- src/currency_core/blockchain_storage.cpp | 32 +++++++++++++++++---- src/currency_core/blockchain_storage.h | 2 +- src/currency_core/currency_basic.h | 2 ++ src/currency_core/currency_format_utils.cpp | 22 ++++++++++++-- src/currency_core/currency_format_utils.h | 1 + src/wallet/wallet2.cpp | 6 ++-- 6 files changed, 55 insertions(+), 10 deletions(-) diff --git a/src/currency_core/blockchain_storage.cpp b/src/currency_core/blockchain_storage.cpp index ba711c66..e805b0cb 100644 --- a/src/currency_core/blockchain_storage.cpp +++ b/src/currency_core/blockchain_storage.cpp @@ -3501,6 +3501,22 @@ bool blockchain_storage::unprocess_blockchain_tx_extra(const transaction& tx) r = pop_alias_info(ei.m_alias); CHECK_AND_ASSERT_MES(r, false, "failed to pop_alias_info"); } + + if (ei.m_asset_operation.operation_type != ASSET_DESCRIPTOR_OPERATION_UNDEFINED) + { + crypto::hash asset_id = currency::null_hash; + if (ei.m_asset_operation.operation_type == ASSET_DESCRIPTOR_OPERATION_REGISTER) + { + asset_id = get_asset_id_from_descriptor(ei.m_asset_operation.descriptor); + } + else + { + CHECK_AND_ASSERT_MES(ei.m_asset_operation.asset_id.size() == 1, false, "Unexpected asset_id in operation"); + asset_id = ei.m_asset_operation.asset_id.back(); + } + r = pop_asset_info(asset_id); + CHECK_AND_ASSERT_MES(r, false, "failed to pop_alias_info"); + } return true; } //------------------------------------------------------------------ @@ -3533,7 +3549,7 @@ bool blockchain_storage::get_asset_info(const crypto::hash& asset_id, asset_desc { if (as_ptr->size()) { - info = as_ptr->back(); + info = as_ptr->back().descriptor; return true; } } @@ -3738,9 +3754,9 @@ bool blockchain_storage::pop_asset_info(const crypto::hash& asset_id) assets_container::t_value_type local_asset_hist = *asset_history_ptr; local_asset_hist.pop_back(); if (local_asset_hist.size()) - m_db_aliases.set(asset_id, local_asset_hist); + m_db_assets.set(asset_id, local_asset_hist); else - m_db_aliases.erase(asset_id); + m_db_assets.erase(asset_id); LOG_PRINT_MAGENTA("[ASSET_POP]: " << asset_id << ": " << (!local_asset_hist.empty() ? "(prev)" : "(erased)"), LOG_LEVEL_1); return true; @@ -3752,10 +3768,10 @@ bool blockchain_storage::put_asset_info(const transaction & tx, asset_descriptor if (ado.operation_type == ASSET_DESCRIPTOR_OPERATION_REGISTER) { crypto::hash asset_id = get_asset_id_from_descriptor(ado.descriptor); - auto asset_history_ptr = m_db_aliases.find(asset_id); + auto asset_history_ptr = m_db_assets.find(asset_id); CHECK_AND_ASSERT_MES(!asset_history_ptr, false, "Asset id already existing"); assets_container::t_value_type local_asset_history = AUTO_VAL_INIT(local_asset_history); - local_asset_history.push_back(ado.descriptor); + local_asset_history.push_back(ado); m_db_assets.set(asset_id, local_asset_history); LOG_PRINT_MAGENTA("[ASSET_REGISTERED]: " << asset_id << ": " << ado.descriptor.full_name, LOG_LEVEL_1); //TODO: @@ -3860,6 +3876,12 @@ bool blockchain_storage::process_blockchain_tx_extra(const transaction& tx) r = put_alias_info(tx, ei.m_alias); CHECK_AND_ASSERT_MES(r, false, "failed to put_alias_info"); } + if (ei.m_asset_operation.operation_type != ASSET_DESCRIPTOR_OPERATION_UNDEFINED) + { + r = put_asset_info(tx, ei.m_asset_operation); + CHECK_AND_ASSERT_MES(r, false, "failed to put_asset_info"); + } + return true; } //------------------------------------------------------------------ diff --git a/src/currency_core/blockchain_storage.h b/src/currency_core/blockchain_storage.h index 92ab3049..14f74a4a 100644 --- a/src/currency_core/blockchain_storage.h +++ b/src/currency_core/blockchain_storage.h @@ -489,7 +489,7 @@ namespace currency typedef tools::db::cached_key_value_accessor solo_options_container; typedef tools::db::basic_key_value_accessor per_block_gindex_increments_container; // height => [(amount, gindex_increment), ...] - typedef tools::db::cached_key_value_accessor, true, false> assets_container; + typedef tools::db::cached_key_value_accessor, true, false> assets_container; //----------------------------------------- diff --git a/src/currency_core/currency_basic.h b/src/currency_core/currency_basic.h index ae103568..1faaf62f 100644 --- a/src/currency_core/currency_basic.h +++ b/src/currency_core/currency_basic.h @@ -53,6 +53,8 @@ namespace currency const static crypto::key_derivation null_derivation = AUTO_VAL_INIT(null_derivation); const static crypto::hash gdefault_genesis = epee::string_tools::hex_to_pod("CC608F59F8080E2FBFE3C8C80EB6E6A953D47CF2D6AEBD345BADA3A1CAB99852"); + const static crypto::hash ffff_hash = epee::string_tools::hex_to_pod("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); + typedef std::string payment_id_t; diff --git a/src/currency_core/currency_format_utils.cpp b/src/currency_core/currency_format_utils.cpp index e69415d0..c40d41be 100644 --- a/src/currency_core/currency_format_utils.cpp +++ b/src/currency_core/currency_format_utils.cpp @@ -346,8 +346,16 @@ namespace currency { if (tx.version > TRANSACTION_VERSION_PRE_HF4) { + //@#@ TODO: This is just a temporary code + uint64_t assets_emmited = 0; + asset_descriptor_operation ado = AUTO_VAL_INIT(ado); + if (get_type_in_variant_container(tx.extra, ado) && ado.operation_type == ASSET_DESCRIPTOR_OPERATION_REGISTER) + { + assets_emmited += ado.descriptor.current_supply; + } + size_t zc_inputs_count = 0; - uint64_t bare_inputs_sum = additional_inputs_amount_and_fees_for_mining_tx; + uint64_t bare_inputs_sum = additional_inputs_amount_and_fees_for_mining_tx + assets_emmited; for(auto& vin : tx.vin) { VARIANT_SWITCH_BEGIN(vin); @@ -671,6 +679,7 @@ namespace currency mutable bool was_attachment; mutable bool was_userdata; mutable bool was_alias; + mutable bool was_asset; tx_extra_info& rei; const transaction& rtx; @@ -701,6 +710,12 @@ namespace currency rei.m_alias = ae; return true; } + bool operator()(const asset_descriptor_operation & ado) const + { + ENSURE_ONETIME(was_asset, "asset"); + rei.m_asset_operation = ado; + return true; + } bool operator()(const extra_alias_entry_old& ae) const { return operator()(static_cast(ae)); @@ -1949,7 +1964,10 @@ namespace currency //must be asset publication for (auto& item : shuffled_dsts) { - item.asset_id = asset_id_for_destinations; + if (item.asset_id == currency::ffff_hash) + { + item.asset_id = asset_id_for_destinations; + } } } if (shuffle) diff --git a/src/currency_core/currency_format_utils.h b/src/currency_core/currency_format_utils.h index 17e5e251..639ae636 100644 --- a/src/currency_core/currency_format_utils.h +++ b/src/currency_core/currency_format_utils.h @@ -70,6 +70,7 @@ namespace currency extra_alias_entry m_alias; std::string m_user_data_blob; extra_attachment_info m_attachment_info; + asset_descriptor_operation m_asset_operation; }; //--------------------------------------------------------------------------------------------------------------- diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 97f9f9e2..6a78f757 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -4180,9 +4180,8 @@ void wallet2::publish_new_asset(const currency::asset_descriptor_base& asset_inf asset_descriptor_operation asset_reg_info = AUTO_VAL_INIT(asset_reg_info); asset_reg_info.descriptor = asset_info; asset_reg_info.operation_type = ASSET_DESCRIPTOR_OPERATION_REGISTER; - construct_tx_param ctp = get_default_construct_tx_param(); - //ctp.dsts = destinations; + ctp.dsts = destinations; ctp.extra.push_back(asset_reg_info); finalized_tx ft = AUTO_VAL_INIT(ft); @@ -4988,6 +4987,9 @@ assets_selection_context wallet2::get_needed_money(uint64_t fee, const std::vect amounts_map[currency::null_hash].needed_amount = fee; BOOST_FOREACH(auto& dt, dsts) { + if(dt.asset_id == currency::ffff_hash) + continue; //this destination for emmition only + THROW_IF_TRUE_WALLET_EX(0 == dt.amount, error::zero_destination); uint64_t money_to_add = dt.amount; if (dt.amount_to_provide)