diff --git a/src/currency_core/blockchain_storage.cpp b/src/currency_core/blockchain_storage.cpp index e805b0cb..202983f1 100644 --- a/src/currency_core/blockchain_storage.cpp +++ b/src/currency_core/blockchain_storage.cpp @@ -3776,7 +3776,6 @@ bool blockchain_storage::put_asset_info(const transaction & tx, asset_descriptor LOG_PRINT_MAGENTA("[ASSET_REGISTERED]: " << asset_id << ": " << ado.descriptor.full_name, LOG_LEVEL_1); //TODO: //rise_core_event(CORE_EVENT_ADD_ASSET, alias_info_to_rpc_alias_info(ai)); - } else { diff --git a/src/currency_core/currency_format_utils.cpp b/src/currency_core/currency_format_utils.cpp index c40d41be..d04df21f 100644 --- a/src/currency_core/currency_format_utils.cpp +++ b/src/currency_core/currency_format_utils.cpp @@ -1816,18 +1816,19 @@ namespace currency uint64_t summary_inputs_money = 0; crypto::hash asset_id_for_destinations = currency::null_hash; + asset_descriptor_operation* pado = nullptr; if (tx.version > TRANSACTION_VERSION_PRE_HF4) { - asset_descriptor_operation ado = AUTO_VAL_INIT(ado); - if (get_type_in_variant_container(tx.extra, ado)) + pado = get_type_in_variant_container(tx.extra); + if (pado) { crypto::secret_key stub = AUTO_VAL_INIT(stub); - bool r = derive_key_pair_from_key_pair(sender_account_keys.account_address.spend_public_key, one_time_secret_key, stub, ado.descriptor.owner, CRYPTO_HDS_ASSET_CONTROL_KEY); + bool r = derive_key_pair_from_key_pair(sender_account_keys.account_address.spend_public_key, one_time_secret_key, stub, pado.descriptor.owner, CRYPTO_HDS_ASSET_CONTROL_KEY); CHECK_AND_ASSERT_MES(r, false, "Failed to derive_public_key_from_tx_and_account_pub_key()"); //also assign this asset id to destinations - asset_id_for_destinations = get_asset_id_from_descriptor(ado.descriptor); + asset_id_for_destinations = get_asset_id_from_descriptor(pado.descriptor); //TODO: temporary - summary_inputs_money += ado.descriptor.current_supply; + summary_inputs_money += pado.descriptor.current_supply; } } @@ -1957,19 +1958,25 @@ namespace currency tx.vin.push_back(ins_zc); }*/ - // "Shuffle" outs std::vector shuffled_dsts(destinations); if (asset_id_for_destinations != currency::null_hash) { + uint64_t amount_of_assets = 0; //must be asset publication for (auto& item : shuffled_dsts) { if (item.asset_id == currency::ffff_hash) { item.asset_id = asset_id_for_destinations; + amount_of_assets += item.amount; } } + CHECK_AND_ASSERT_MES(pado, false, "pado is null ??"); + pado->descriptor.current_supply = amount_of_assets; } + + + // "Shuffle" outs if (shuffle) std::sort(shuffled_dsts.begin(), shuffled_dsts.end(), [](const tx_destination_entry& de1, const tx_destination_entry& de2) { return de1.amount < de2.amount; }); diff --git a/src/currency_core/currency_format_utils_abstract.h b/src/currency_core/currency_format_utils_abstract.h index b26e906f..56fe20de 100644 --- a/src/currency_core/currency_format_utils_abstract.h +++ b/src/currency_core/currency_format_utils_abstract.h @@ -96,17 +96,41 @@ namespace currency template bool get_type_in_variant_container(variant_t_container& av, specific_type_t& a) { - for (auto& ai : av) + const specific_type_t* pa = get_type_in_variant_container(av); + if (pa) { - if (ai.type() == typeid(specific_type_t)) - { - a = boost::get(ai); - return true; - } + a = *pa; + return true; } return false; } //--------------------------------------------------------------- + //--------------------------------------------------------------- + template + specific_type_t* get_type_in_variant_container(variant_t_container& av) + { + for (auto& ai : av) + { + if (ai.type() == typeid(specific_type_t)) + { + return &boost::get(ai); + } + } + return nullptr; + } + //--------------------------------------------------------------- + template + specific_type_t& get_type_in_variant_container_by_ref(variant_t_container& av) + { + for (auto& ai : av) + { + if (ai.type() == typeid(specific_type_t)) + { + return boost::get(ai); + } + } + ASSERT_MES_AND_THROW("Objec not found"); + } // if cb returns true, it means "continue", false -- means "stop" template bool process_type_in_variant_container(const variant_container_t& av, callback_t& cb, bool return_value_if_none_found = true) diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 6a78f757..5d1dfc89 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -4175,7 +4175,7 @@ void wallet2::request_alias_registration(currency::extra_alias_entry& ai, curren transfer(destinations, 0, 0, fee, extra, attachments, get_current_split_strategy(), tx_dust_policy(DEFAULT_DUST_THRESHOLD), res_tx, CURRENCY_TO_KEY_OUT_RELAXED, false); } //---------------------------------------------------------------------------------------------------- -void wallet2::publish_new_asset(const currency::asset_descriptor_base& asset_info, const std::vector& destinations, currency::transaction& result_tx) +void wallet2::publish_new_asset(const currency::asset_descriptor_base& asset_info, const std::vector& destinations, currency::transaction& result_tx, crypto::hash& asset_id) { asset_descriptor_operation asset_reg_info = AUTO_VAL_INIT(asset_reg_info); asset_reg_info.descriptor = asset_info; @@ -4187,6 +4187,11 @@ void wallet2::publish_new_asset(const currency::asset_descriptor_base& asset_inf finalized_tx ft = AUTO_VAL_INIT(ft); this->transfer(ctp, ft, true, nullptr); result_tx = ft.tx; + //get generated asset id + currency::asset_descriptor_operation ado = AUTO_VAL_INIT(ado); + bool r = get_type_in_variant_container(result_tx.extra, ado); + CHECK_AND_ASSERT_THROW_MES(r, "Failed find asset info in tx"); + asset_id = get_asset_id_from_descriptor(ado.descriptor); } //---------------------------------------------------------------------------------------------------- void wallet2::request_alias_update(currency::extra_alias_entry& ai, currency::transaction& res_tx, uint64_t fee, uint64_t reward) diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 2d45cc8c..7c50704f 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -565,7 +565,7 @@ namespace tools void request_alias_update(currency::extra_alias_entry& ai, currency::transaction& res_tx, uint64_t fee, uint64_t reward); bool check_available_sources(std::list& amounts); - void publish_new_asset(const currency::asset_descriptor_base& asset_info, const std::vector& destinations, currency::transaction& result_tx); + void publish_new_asset(const currency::asset_descriptor_base& asset_info, const std::vector& destinations, currency::transaction& result_tx, crypto::hash& asset_id); bool set_core_proxy(const std::shared_ptr& proxy); void set_pos_mint_packing_size(uint64_t new_size);