1
0
Fork 0
forked from lthn/blockchain

fixed compilation issues regarding asset_descriptors

This commit is contained in:
cryptozoidberg 2022-09-30 21:23:06 +02:00
parent c61149f480
commit 5ab9a2b974
No known key found for this signature in database
GPG key ID: 22DEB97A54C6FDEC
6 changed files with 55 additions and 10 deletions

View file

@ -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;
}
//------------------------------------------------------------------

View file

@ -489,7 +489,7 @@ namespace currency
typedef tools::db::cached_key_value_accessor<uint64_t, uint64_t, false, true> solo_options_container;
typedef tools::db::basic_key_value_accessor<uint32_t, block_gindex_increments, true> per_block_gindex_increments_container; // height => [(amount, gindex_increment), ...]
typedef tools::db::cached_key_value_accessor<crypto::hash, std::list<asset_descriptor_base>, true, false> assets_container;
typedef tools::db::cached_key_value_accessor<crypto::hash, std::list<asset_descriptor_operation>, true, false> assets_container;
//-----------------------------------------

View file

@ -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<crypto::hash>("CC608F59F8080E2FBFE3C8C80EB6E6A953D47CF2D6AEBD345BADA3A1CAB99852");
const static crypto::hash ffff_hash = epee::string_tools::hex_to_pod<crypto::hash>("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
typedef std::string payment_id_t;

View file

@ -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<const extra_alias_entry&>(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)

View file

@ -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;
};
//---------------------------------------------------------------------------------------------------------------

View file

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