moved serialization-specific adaptor-functions from wallet2 to base header file

This commit is contained in:
cryptozoidberg 2023-10-31 19:22:29 +01:00
parent d1dc240a73
commit cacdb4a4ce
No known key found for this signature in database
GPG key ID: 22DEB97A54C6FDEC
5 changed files with 32 additions and 28 deletions

View file

@ -408,4 +408,28 @@ namespace currency
#endif
}
//----------------------------------------------------------------------------------------------------
std::string wallet2::transform_tx_to_str(const currency::transaction& tx)
{
return currency::obj_to_json_str(tx);
}
//----------------------------------------------------------------------------------------------------
currency::transaction wallet2::transform_str_to_tx(const std::string& tx_str)
{
THROW_IF_TRUE_WALLET_INT_ERR_EX_NO_HANDLER(false, "transform_str_to_tx shoruld never be called");
return currency::transaction();
}
//----------------------------------------------------------------------------------------------------
const transaction_wallet_info& wallet2::transform_ptr_to_value(const std::shared_ptr<transaction_wallet_info>& a)
{
return *a;
}
//----------------------------------------------------------------------------------------------------
std::shared_ptr<transaction_wallet_info> wallet2::transform_value_to_ptr(const transaction_wallet_info& d)
{
THROW_IF_TRUE_WALLET_INT_ERR_EX_NO_HANDLER(false, "transform_value_to_ptr shoruld never be called");
return std::shared_ptr<transaction_wallet_info>();
}
}

View file

@ -329,5 +329,11 @@ namespace currency
}; // struct tx_generation_context
bool validate_tx_output_details_againt_tx_generation_context(const transaction& tx, const tx_generation_context& gen_context, const crypto::secret_key& onet_time_key);
std::string transform_tx_to_str(const transaction& tx);
transaction transform_str_to_tx(const std::string& tx_str);
const transaction_wallet_info& transform_ptr_to_value(const std::shared_ptr<transaction_wallet_info>& a);
std::shared_ptr<transaction_wallet_info> transform_value_to_ptr(const transaction_wallet_info& d);
} // namespace currency

View file

@ -133,17 +133,6 @@ std::string wallet2::transfer_flags_to_str(uint32_t flags)
return result;
}
//----------------------------------------------------------------------------------------------------
std::string wallet2::transform_tx_to_str(const currency::transaction& tx)
{
return currency::obj_to_json_str(tx);
}
//----------------------------------------------------------------------------------------------------
currency::transaction wallet2::transform_str_to_tx(const std::string& tx_str)
{
THROW_IF_TRUE_WALLET_INT_ERR_EX_NO_HANDLER(false, "transform_str_to_tx shoruld never be called");
return currency::transaction();
}
//----------------------------------------------------------------------------------------------------
uint64_t transfer_details_base_to_amount(const transfer_details_base& tdb)
{
return tdb.amount();
@ -153,17 +142,6 @@ std::string transfer_details_base_to_tx_hash(const transfer_details_base& tdb)
{
return epee::string_tools::pod_to_hex(currency::get_transaction_hash(tdb.m_ptx_wallet_info->m_tx));
}
//----------------------------------------------------------------------------------------------------
const transaction_wallet_info& wallet2::transform_ptr_to_value(const std::shared_ptr<transaction_wallet_info>& a)
{
return *a;
}
//----------------------------------------------------------------------------------------------------
std::shared_ptr<transaction_wallet_info> wallet2::transform_value_to_ptr(const transaction_wallet_info& d)
{
THROW_IF_TRUE_WALLET_INT_ERR_EX_NO_HANDLER(false, "transform_value_to_ptr shoruld never be called");
return std::shared_ptr<transaction_wallet_info>();
}
//----------------------------------------------------------------------------------------------------
void wallet2::init(const std::string& daemon_address)

View file

@ -224,11 +224,7 @@ namespace tools
wallet2();
static std::string transfer_flags_to_str(uint32_t flags);
static std::string transform_tx_to_str(const currency::transaction& tx);
static currency::transaction transform_str_to_tx(const std::string& tx_str);
static const transaction_wallet_info& transform_ptr_to_value(const std::shared_ptr<transaction_wallet_info>& a);
static std::shared_ptr<transaction_wallet_info> transform_value_to_ptr(const transaction_wallet_info& d);
static uint64_t transfer_details_base_to_amount(const transfer_details_base& tdb);
static std::string transfer_details_base_to_tx_hash(const transfer_details_base& tdb);

View file

@ -298,7 +298,7 @@ namespace tools
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(m_block_height)
KV_SERIALIZE(m_block_timestamp)
KV_SERIALIZE_CUSTOM(m_tx, std::string, tools::wallet2::transform_tx_to_str, tools::wallet2::transform_str_to_tx)
KV_SERIALIZE_CUSTOM(m_tx, std::string, currency::wallet2::transform_tx_to_str, currency::transform_str_to_tx)
END_KV_SERIALIZE_MAP()
BEGIN_BOOST_SERIALIZATION()
@ -366,7 +366,7 @@ namespace tools
}
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE_CUSTOM(m_ptx_wallet_info, const transaction_wallet_info&, tools::wallet2::transform_ptr_to_value, tools::wallet2::transform_value_to_ptr)
KV_SERIALIZE_CUSTOM(m_ptx_wallet_info, const transaction_wallet_info&, currency::transform_ptr_to_value, currency::transform_value_to_ptr)
KV_SERIALIZE(m_internal_output_index)
KV_SERIALIZE(m_spent_height)
KV_SERIALIZE(m_flags)