1
0
Fork 0
forked from lthn/blockchain

initial code for introducing asset descriptor for wallet

This commit is contained in:
cryptozoidberg 2022-09-28 22:06:07 +02:00
parent a718895fd7
commit 1fd6e08e5c
No known key found for this signature in database
GPG key ID: 22DEB97A54C6FDEC
6 changed files with 30 additions and 10 deletions

View file

@ -1200,7 +1200,6 @@ namespace crypto
{
// hs won't touch memory if size is 0, so it's safe
return hash_helper_t::hs(data(), sizeof(scalar_t) * size());
}
}
} // namespace crypto

View file

@ -807,12 +807,12 @@ namespace currency
return derive_public_key_from_target_address(destination_addr, tx_sec_key, index, out_eph_public_key, derivation);
}
//---------------------------------------------------------------
bool derive_key_pair_from_key_pair(const crypto::public_key& src_pub_key, const crypto::secret_key& src_sec_key, crypto::public_key& derived_sec_key, crypto::public_key& derived_pub_key, const char(&hs_domain)[32], uint64_t index)
bool derive_key_pair_from_key_pair(const crypto::public_key& src_pub_key, const crypto::secret_key& src_sec_key, crypto::secret_key& derived_sec_key, crypto::public_key& derived_pub_key, const char(&hs_domain)[32], uint64_t index)
{
crypto::key_derivation derivation = AUTO_VAL_INIT(derivation);
bool r = crypto::generate_key_derivation(src_pub_key, src_sec_key, derivation);
CHECK_AND_ASSERT_MES(r, false, "at creation outs: failed to generate_key_derivation(" << src_pub_key << ", " << src_sec_key << ")");
scalar_t sec_key = crypto::hash_helper_t::hs(hs_domain, derivation, index);
crypto::scalar_t sec_key = crypto::hash_helper_t::hs(hs_domain, derivation, index);
derived_sec_key = sec_key.as_secret_key();
derived_pub_key = (sec_key * crypto::c_point_G).to_public_key();
return true;

View file

@ -315,7 +315,7 @@ namespace currency
bool generate_key_image_helper(const account_keys& ack, const crypto::public_key& tx_public_key, size_t real_output_index, keypair& in_ephemeral, crypto::key_image& ki);
bool derive_public_key_from_target_address(const account_public_address& destination_addr, const crypto::secret_key& tx_sec_key, size_t index, crypto::public_key& out_eph_public_key, crypto::key_derivation& derivation);
bool derive_public_key_from_target_address(const account_public_address& destination_addr, const crypto::secret_key& tx_sec_key, size_t index, crypto::public_key& out_eph_public_key);
bool derive_key_pair_from_key_pair(const crypto::public_key& src_pub_key, const crypto::secret_key& src_sec_key, crypto::public_key& derived_sec_key, crypto::public_key& derived_pub_key, const char(&hs_domain)[32], uint64_t index = 0);
bool derive_key_pair_from_key_pair(const crypto::public_key& src_pub_key, const crypto::secret_key& src_sec_key, crypto::secret_key& derived_sec_key, crypto::public_key& derived_pub_key, const char(&hs_domain)[32], uint64_t index = 0);
std::string short_hash_str(const crypto::hash& h);
bool is_mixattr_applicable_for_fake_outs_counter(uint8_t mix_attr, uint64_t fake_attr_count);

View file

@ -353,6 +353,26 @@ namespace currency
size_t get_object_blobsize(const transaction& t, uint64_t prefix_blob_size);
inline
void put_t_to_buff(std::string& buff)
{}
template <typename T, typename... Types>
void put_t_to_buff(std::string& buff, const T& var1, Types&... var2)
{
static_assert(std::is_pod<T>::value, "T must be a POD type.");
buff.append((const char*)&var1, sizeof(var1));
put_t_to_buff(buff, var2...);
}
template <typename... Types>
crypto::hash get_hash_from_POD_objects(Types&... var1)
{
std::string buff;
put_t_to_buff(buff, var1...);
return crypto::cn_fast_hash(buff.data(), buff.size());
}
#define CHECKED_GET_SPECIFIC_VARIANT(variant_var, specific_type, variable_name, fail_return_val) \
CHECK_AND_ASSERT_MES(variant_var.type() == typeid(specific_type), fail_return_val, "wrong variant type: " << variant_var.type().name() << ", expected " << typeid(specific_type).name()); \

View file

@ -776,7 +776,8 @@ void wallet2::process_new_transaction(const currency::transaction& tx, uint64_t
}
else
{
wallet_own_asset_context& asset_context = m_own_asset_descriptors[hash_helper_t::hs(CRYPTO_HDS_ASSET_ID, ado.descriptor.owner), 0];
wallet_own_asset_context& asset_context = m_own_asset_descriptors[get_hash_from_POD_objects(CRYPTO_HDS_ASSET_ID, ado.descriptor.owner)];
asset_context.asset_descriptor = ado.descriptor;
std::stringstream ss;
ss << "New Asset Registered:"
@ -786,7 +787,7 @@ void wallet2::process_new_transaction(const currency::transaction& tx, uint64_t
<< ENDL << "Current Supply: " << print_asset_money(asset_context.asset_descriptor.current_supply, asset_context.asset_descriptor.decimal_point)
<< ENDL << "DecimalPoint: " << asset_context.asset_descriptor.decimal_point;
WLT_LOG_MAGENTA(ss.str() << , LOG_LEVEL_0);
WLT_LOG_MAGENTA(ss.str(), LOG_LEVEL_0);
if (m_wcallback)
m_wcallback->on_message(i_wallet2_callback::ms_yellow, ss.str());
}
@ -4165,7 +4166,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 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)
{
asset_descriptor_operation asset_reg_info = AUTO_VAL_INIT(asset_reg_info);
asset_reg_info.descriptor = asset_info;

View file

@ -508,7 +508,7 @@ namespace tools
struct wallet_own_asset_context
{
asset_descriptor_base asset_descriptor;
currency::asset_descriptor_base asset_descriptor;
crypto::secret_key control_key;
BEGIN_BOOST_SERIALIZATION()
@ -563,7 +563,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 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);
bool set_core_proxy(const std::shared_ptr<i_core_proxy>& proxy);
void set_pos_mint_packing_size(uint64_t new_size);