1
0
Fork 0
forked from lthn/blockchain

added core test for multiasset(never tried yet)

This commit is contained in:
cryptozoidberg 2022-10-03 22:03:54 +02:00
parent 5ab9a2b974
commit 51d8c85540
No known key found for this signature in database
GPG key ID: 22DEB97A54C6FDEC
5 changed files with 50 additions and 15 deletions

View file

@ -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
{

View file

@ -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<asset_descriptor_operation>(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<tx_destination_entry> 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; });

View file

@ -96,17 +96,41 @@ namespace currency
template<typename specific_type_t, typename variant_t_container>
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<const specific_type_t>(av);
if (pa)
{
if (ai.type() == typeid(specific_type_t))
{
a = boost::get<specific_type_t>(ai);
return true;
}
a = *pa;
return true;
}
return false;
}
//---------------------------------------------------------------
//---------------------------------------------------------------
template<typename specific_type_t, typename variant_t_container>
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<specific_type_t>(ai);
}
}
return nullptr;
}
//---------------------------------------------------------------
template<typename specific_type_t, typename variant_t_container>
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<specific_type_t>(ai);
}
}
ASSERT_MES_AND_THROW("Objec not found");
}
// if cb returns true, it means "continue", false -- means "stop"
template<typename specific_type_t, typename variant_container_t, typename callback_t>
bool process_type_in_variant_container(const variant_container_t& av, callback_t& cb, bool return_value_if_none_found = true)

View file

@ -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<currency::tx_destination_entry>& destinations, currency::transaction& result_tx)
void wallet2::publish_new_asset(const currency::asset_descriptor_base& asset_info, const std::vector<currency::tx_destination_entry>& 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)

View file

@ -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<uint64_t>& amounts);
void publish_new_asset(const currency::asset_descriptor_base& asset_info, const std::vector<currency::tx_destination_entry>& destinations, currency::transaction& result_tx);
void publish_new_asset(const currency::asset_descriptor_base& asset_info, const std::vector<currency::tx_destination_entry>& destinations, currency::transaction& result_tx, crypto::hash& asset_id);
bool set_core_proxy(const std::shared_ptr<i_core_proxy>& proxy);
void set_pos_mint_packing_size(uint64_t new_size);