1
0
Fork 0
forked from lthn/blockchain

simplewallet: display own assets with correct decimal point, get_asset_info() knows own assets, + minor fixes

This commit is contained in:
sowle 2024-06-22 20:25:04 +02:00
parent 6408ea007f
commit 3882d024cb
No known key found for this signature in database
GPG key ID: C07A24B2D89D49FC
4 changed files with 51 additions and 36 deletions

View file

@ -816,38 +816,45 @@ void simple_wallet::on_new_block(uint64_t height, const currency::block& block)
//----------------------------------------------------------------------------------------------------
std::string print_money_trailing_zeros_replaced_with_spaces(uint64_t amount, size_t decimal_point = CURRENCY_DISPLAY_DECIMAL_POINT)
{
std::string s = print_money(amount);
std::string s = print_money(amount, decimal_point);
size_t p = s.find_last_not_of('0');
if (p != std::string::npos)
{
if (s[p] == '.')
++p;
size_t l = s.length() - p - 1;
return s.replace(p + 1, l, l, ' ');
s.replace(p + 1, l, l, ' ');
if (decimal_point < CURRENCY_DISPLAY_DECIMAL_POINT)
s += std::string(CURRENCY_DISPLAY_DECIMAL_POINT - decimal_point, ' ');
}
return s;
}
//----------------------------------------------------------------------------------------------------
std::string simple_wallet::get_tocken_info_string(const crypto::public_key& asset_id, uint64_t& decimal_points)
std::string simple_wallet::get_token_info_string(const crypto::public_key& asset_id, uint64_t& decimal_points)
{
std::string token_info = "ZANO";
decimal_points = CURRENCY_DISPLAY_DECIMAL_POINT;
if (asset_id != currency::native_coin_asset_id)
{
currency::asset_descriptor_base adb = AUTO_VAL_INIT(adb);
bool whitelisted = false;
if (!m_wallet->get_asset_id_info(asset_id, adb, whitelisted))
uint32_t asset_info_flags{};
if (!m_wallet->get_asset_info(asset_id, adb, asset_info_flags))
{
token_info = "!UNKNOWN!";
}
else {
else
{
decimal_points = adb.decimal_point;
token_info = adb.ticker;
if (whitelisted)
if (asset_info_flags & tools::wallet2::aif_whitelisted)
{
token_info += "[*]";
}
else if (asset_info_flags & tools::wallet2::aif_own)
{
token_info += "[$]";
}
else
{
token_info += std::string("[") + epee::string_tools::pod_to_hex(asset_id) + "]";
@ -864,7 +871,7 @@ void simple_wallet::on_transfer2(const tools::wallet_public::wallet_transfer_inf
{
epee::log_space::console_colors color = !wti.has_outgoing_entries() ? epee::log_space::console_color_green : epee::log_space::console_color_magenta;
uint64_t decimal_points = CURRENCY_DISPLAY_DECIMAL_POINT;
std::string token_info = get_tocken_info_string(wti.subtransfers[0].asset_id, decimal_points);
std::string token_info = get_token_info_string(wti.subtransfers[0].asset_id, decimal_points);
message_writer(color, false) <<
"height " << wti.height <<
", tx " << wti.tx_hash <<
@ -879,10 +886,10 @@ void simple_wallet::on_transfer2(const tools::wallet_public::wallet_transfer_inf
{
epee::log_space::console_colors color = st.is_income ? epee::log_space::console_color_green : epee::log_space::console_color_magenta;
uint64_t decimal_points = CURRENCY_DISPLAY_DECIMAL_POINT;
std::string token_info = get_tocken_info_string(st.asset_id, decimal_points);
std::string token_info = get_token_info_string(st.asset_id, decimal_points);
message_writer(epee::log_space::console_color_cyan, false) << " "
<< std::right << std::setw(18) << print_money_trailing_zeros_replaced_with_spaces(st.amount, decimal_points) << (st.is_income ? " received," : " spent") << " " << token_info;
message_writer(epee::log_space::console_color_cyan, false) << " "
<< std::right << std::setw(24) << print_money_trailing_zeros_replaced_with_spaces(st.amount, decimal_points) << std::left << (st.is_income ? " received," : " spent") << " " << token_info;
}
}
@ -1059,7 +1066,7 @@ bool simple_wallet::print_wti(const tools::wallet_public::wallet_transfer_info&
{
epee::log_space::console_colors cl = st.is_income ? epee::log_space::console_color_green: epee::log_space::console_color_magenta;
uint64_t decimal_points = CURRENCY_DISPLAY_DECIMAL_POINT;
std::string token_info = get_tocken_info_string(st.asset_id, decimal_points);
std::string token_info = get_token_info_string(st.asset_id, decimal_points);
success_msg_writer(cl)
<< (st.is_income ? "Received " : "Sent ")

View file

@ -110,7 +110,7 @@ namespace currency
uint64_t get_daemon_blockchain_height(std::string& err);
bool try_connect_to_daemon();
std::string get_tocken_info_string(const crypto::public_key& asset_id, uint64_t& decimal_point);
std::string get_token_info_string(const crypto::public_key& asset_id, uint64_t& decimal_point);
bool print_wti(const tools::wallet_public::wallet_transfer_info& wti);
bool check_password_for_operation();
crypto::hash get_hash_from_pass_and_salt(const std::string& pass, uint64_t salt);

View file

@ -3813,37 +3813,42 @@ bool wallet2::balance(std::list<wallet_public::asset_balance_entry>& balances, u
return true;
}
//----------------------------------------------------------------------------------------------------
bool wallet2::get_asset_id_info(const crypto::public_key& asset_id, currency::asset_descriptor_base& asset_info, bool& whitelist_) const
bool wallet2::get_asset_info(const crypto::public_key& asset_id, currency::asset_descriptor_base& asset_info, uint32_t& asset_flags) const
{
asset_flags = aif_none;
if (asset_id == currency::native_coin_asset_id)
{
asset_info = currency::get_native_coin_asset_descriptor();
whitelist_ = true;
asset_flags |= aif_whitelisted;
return true;
}
//check if asset is whitelisted or customly added
whitelist_ = false;
// whitelisted?
auto it_white = m_whitelisted_assets.find(asset_id);
if (it_white == m_whitelisted_assets.end())
{
//check if it custom asset
auto it_cust = m_custom_assets.find(asset_id);
if (it_cust == m_custom_assets.end())
{
return false;
}
else
{
asset_info = it_cust->second;
}
}
else
if (it_white != m_whitelisted_assets.end())
{
asset_info = it_white->second;
whitelist_ = true;
asset_flags |= aif_whitelisted;
return true;
}
return true;
// custom asset?
auto it_cust = m_custom_assets.find(asset_id);
if (it_cust != m_custom_assets.end())
{
asset_info = it_cust->second;
return true;
}
auto it_own = m_own_asset_descriptors.find(asset_id);
if (it_own != m_own_asset_descriptors.end())
{
asset_info = it_own->second;
asset_flags |= aif_own;
return true;
}
return false;
}
//----------------------------------------------------------------------------------------------------
@ -3965,8 +3970,8 @@ std::string wallet2::get_transfers_str(bool include_spent /*= true*/, bool inclu
bool native_coin = td.is_native_coin();
asset_descriptor_base adb{};
bool whitelisted = false;
if (get_asset_id_info(td.get_asset_id(), adb, whitelisted) == show_only_unknown)
uint32_t asset_info_flags{};
if (get_asset_info(td.get_asset_id(), adb, asset_info_flags) == show_only_unknown)
{
if (!show_only_unknown)
++unknown_assets_outs_count;

View file

@ -441,7 +441,10 @@ namespace tools
uint64_t balance(uint64_t& unloked) const;
uint64_t unlocked_balance() const;
bool get_asset_id_info(const crypto::public_key& asset_id, currency::asset_descriptor_base& asset_info, bool& whitelist_) const;
enum asset_info_flags_t : uint32_t { aif_none = 0, aif_whitelisted = 1 << 0, aif_own = 1 << 1 };
bool get_asset_info(const crypto::public_key& asset_id, currency::asset_descriptor_base& asset_info, uint32_t& asset_flags) const;
void transfer(uint64_t amount, const currency::account_public_address& acc, const crypto::public_key& asset_id = currency::native_coin_asset_id);
void transfer(uint64_t amount, size_t fake_outs_count, const currency::account_public_address& acc, uint64_t fee = TX_DEFAULT_FEE, const crypto::public_key& asset_id = currency::native_coin_asset_id);
void transfer(uint64_t amount, const currency::account_public_address& acc, currency::transaction& result_tx, const crypto::public_key& asset_id = currency::native_coin_asset_id);