added asset_type handling to TX outputs

This commit is contained in:
Some Random Crypto Guy
2023-07-16 22:00:53 +01:00
parent 18ec1ad834
commit dac963ca27
11 changed files with 52 additions and 14 deletions
+6
View File
@@ -89,10 +89,14 @@ namespace cryptonote
txout_to_tagged_key(const crypto::public_key &_key, const crypto::view_tag &_view_tag) : key(_key), view_tag(_view_tag) { }
crypto::public_key key;
crypto::view_tag view_tag; // optimization to reduce scanning time
std::string asset_type;
uint64_t unlock_time;
BEGIN_SERIALIZE_OBJECT()
FIELD(key)
FIELD(view_tag)
FIELD(asset_type)
FIELD(unlock_time)
END_SERIALIZE()
};
@@ -140,11 +144,13 @@ namespace cryptonote
uint64_t amount;
std::vector<uint64_t> key_offsets;
crypto::key_image k_image; // double spending protection
std::string asset_type;
BEGIN_SERIALIZE_OBJECT()
VARINT_FIELD(amount)
FIELD(key_offsets)
FIELD(k_image)
FIELD(asset_type)
END_SERIALIZE()
};
@@ -930,6 +930,34 @@ namespace cryptonote
: boost::optional<crypto::view_tag>();
}
//---------------------------------------------------------------
bool get_output_asset_type(const cryptonote::tx_out& out, std::string& output_asset_type)
{
// after HF_VERSION_VIEW_TAGS, outputs with public keys are of type txout_to_tagged_key
if (out.target.type() == typeid(txout_to_tagged_key))
output_asset_type = boost::get< txout_to_tagged_key >(out.target).asset_type;
else
{
LOG_ERROR("Unexpected output target type found: " << out.target.type().name());
return false;
}
return true;
}
//---------------------------------------------------------------
bool get_output_unlock_time(const cryptonote::tx_out& out, uint64_t& output_unlock_time)
{
// after HF_VERSION_VIEW_TAGS, outputs with public keys are of type txout_to_tagged_key
if (out.target.type() == typeid(txout_to_tagged_key))
output_unlock_time = boost::get< txout_to_tagged_key >(out.target).unlock_time;
else
{
LOG_ERROR("Unexpected output target type found: " << out.target.type().name());
return false;
}
return true;
}
//---------------------------------------------------------------
std::string short_hash_str(const crypto::hash& h)
{
std::string res = string_tools::pod_to_hex(h);
@@ -939,7 +967,7 @@ namespace cryptonote
return res;
}
//---------------------------------------------------------------
void set_tx_out(const uint64_t amount, const crypto::public_key& output_public_key, const bool use_view_tags, const crypto::view_tag& view_tag, tx_out& out)
void set_tx_out(const uint64_t amount, const crypto::public_key& output_public_key, const bool use_view_tags, const crypto::view_tag& view_tag, const std::string& asset_type, const uint64_t unlock_time, tx_out& out)
{
out.amount = amount;
if (use_view_tags)
@@ -947,6 +975,8 @@ namespace cryptonote
txout_to_tagged_key ttk;
ttk.key = output_public_key;
ttk.view_tag = view_tag;
ttk.asset_type = asset_type;
ttk.unlock_time = unlock_time;
out.target = ttk;
}
else
@@ -89,7 +89,7 @@ namespace cryptonote
void set_encrypted_payment_id_to_tx_extra_nonce(blobdata& extra_nonce, const crypto::hash8& payment_id);
bool get_payment_id_from_tx_extra_nonce(const blobdata& extra_nonce, crypto::hash& payment_id);
bool get_encrypted_payment_id_from_tx_extra_nonce(const blobdata& extra_nonce, crypto::hash8& payment_id);
void set_tx_out(const uint64_t amount, const crypto::public_key& output_public_key, const bool use_view_tags, const crypto::view_tag& view_tag, tx_out& out);
void set_tx_out(const uint64_t amount, const crypto::public_key& output_public_key, const bool use_view_tags, const crypto::view_tag& view_tag, const std::string& asset_type, const uint64_t unlock_time, tx_out& out);
bool check_output_types(const transaction& tx, const uint8_t hf_version);
bool out_can_be_to_acc(const boost::optional<crypto::view_tag>& view_tag_opt, const crypto::key_derivation& derivation, const size_t output_index, hw::device *hwdev = nullptr);
bool is_out_to_acc(const account_keys& acc, const crypto::public_key& output_public_key, const crypto::public_key& tx_pub_key, const std::vector<crypto::public_key>& additional_tx_public_keys, size_t output_index, const boost::optional<crypto::view_tag>& view_tag_opt = boost::optional<crypto::view_tag>());
@@ -131,6 +131,8 @@ namespace cryptonote
uint64_t get_outs_money_amount(const transaction& tx);
bool get_output_public_key(const cryptonote::tx_out& out, crypto::public_key& output_public_key);
boost::optional<crypto::view_tag> get_output_view_tag(const cryptonote::tx_out& out);
bool get_output_asset_type(const cryptonote::tx_out& out, std::string& output_asset_type);
bool get_output_unlock_time(const cryptonote::tx_out& out, uint64_t& output_unlock_time);
bool check_inputs_types_supported(const transaction& tx);
bool check_outs_valid(const transaction& tx);
bool parse_amount(uint64_t& amount, const std::string& str_amount);