1
0
Fork 0
forked from lthn/blockchain

wallet: various minor improvements (balance, balance raw, unknown asset)

This commit is contained in:
sowle 2025-07-11 21:45:24 +03:00
parent eed7d9e3af
commit d241861d86
No known key found for this signature in database
GPG key ID: C07A24B2D89D49FC
3 changed files with 38 additions and 24 deletions

View file

@ -293,7 +293,7 @@ simple_wallet::simple_wallet()
m_cmd_binder.set_handler("stop_mining", boost::bind(&simple_wallet::stop_mining, this, ph::_1), "Stop mining in daemon");
#endif // #ifdef CPU_MINING_ENABLED
m_cmd_binder.set_handler("refresh", boost::bind(&simple_wallet::refresh, this, ph::_1), "Resynchronize transactions and balance");
m_cmd_binder.set_handler("balance", boost::bind(&simple_wallet::show_balance, this, ph::_1), "[raw] Show current wallet balance, with 'raw' param it displays all assets without filtering against whitelists");
m_cmd_binder.set_handler("balance", boost::bind(&simple_wallet::show_balance, this, ph::_1), "[r,raw] Show current wallet balance, with 'raw' param it displays all assets without filtering against whitelists");
m_cmd_binder.set_handler("show_staking_history", boost::bind(&simple_wallet::show_staking_history, this, ph::_1), "show_staking_history [2] - Show staking transfers, if option provided - number of days for history to display");
m_cmd_binder.set_handler("incoming_transfers", boost::bind(&simple_wallet::show_incoming_transfers, this, ph::_1), "incoming_transfers [available|unavailable] - Show incoming transfers - all of them or filter them by availability");
m_cmd_binder.set_handler("incoming_counts", boost::bind(&simple_wallet::show_incoming_transfers_counts, this, ph::_1), "incoming_transfers counts");
@ -886,7 +886,7 @@ void simple_wallet::on_transfer2(const tools::wallet_public::wallet_transfer_inf
message_writer(color, false) <<
"height " << wti.height <<
", tx " << wti.tx_hash <<
" " << std::right << std::setw(18) << print_money_trailing_zeros_replaced_with_spaces(wti.subtransfers[0].amount, decimal_points) << (wti.subtransfers[0].is_income ? " received," : " spent") << " " << token_info;
" " << std::right << std::setw(18) << print_money_trailing_zeros_replaced_with_spaces(wti.subtransfers[0].amount, decimal_points) << (wti.subtransfers[0].is_income ? " received" : " spent") << " " << token_info;
}
else
{
@ -900,7 +900,7 @@ void simple_wallet::on_transfer2(const tools::wallet_public::wallet_transfer_inf
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(24) << print_money_trailing_zeros_replaced_with_spaces(st.amount, decimal_points) << std::left << (st.is_income ? " received," : " spent") << " " << token_info;
<< 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;
}
}
@ -1025,7 +1025,7 @@ bool simple_wallet::refresh(const std::vector<std::string>& args)
//----------------------------------------------------------------------------------------------------
bool simple_wallet::show_balance(const std::vector<std::string>& args /* = std::vector<std::string>()*/)
{
if (args.size() == 1 && args[0] == "raw")
if (args.size() == 1 && (args[0] == "raw" || args[0] == "r"))
{
success_msg_writer() << m_wallet->get_balance_str_raw();
}

View file

@ -3940,13 +3940,13 @@ bool wallet2::balance(std::list<wallet_public::asset_balance_entry>& balances, u
return true;
}
//----------------------------------------------------------------------------------------------------
bool wallet2::get_asset_info(const crypto::public_key& asset_id, currency::asset_descriptor_base& asset_info, uint32_t& asset_flags) const
bool wallet2::get_asset_info(const crypto::public_key& asset_id, currency::asset_descriptor_base& asset_info, uint32_t& asset_flags, bool ask_daemon_for_unknown /* = false */) const
{
asset_flags = aif_none;
if (asset_id == currency::native_coin_asset_id)
{
asset_info = currency::get_native_coin_asset_descriptor();
asset_flags |= aif_whitelisted;
asset_flags |= (aif_native_coin | aif_whitelisted);
return true;
}
@ -3973,9 +3973,19 @@ bool wallet2::get_asset_info(const crypto::public_key& asset_id, currency::asset
if (it_cust != m_custom_assets.end())
{
asset_info = it_cust->second;
asset_flags |= aif_custom;
return true;
}
if (ask_daemon_for_unknown)
{
if (daemon_get_asset_info(asset_id, asset_info))
{
asset_flags |= aif_unknown;
return true;
}
}
return false;
}
//----------------------------------------------------------------------------------------------------
@ -4132,7 +4142,8 @@ std::string wallet2::get_transfers_str(bool include_spent /*= true*/, bool inclu
bool native_coin = td.is_native_coin();
asset_descriptor_base adb{};
uint32_t asset_info_flags{};
if (get_asset_info(td.get_asset_id(), adb, asset_info_flags) == show_only_unknown)
bool unknown_asset = !get_asset_info(td.get_asset_id(), adb, asset_info_flags, show_only_unknown) || (asset_info_flags & aif_unknown);
if (unknown_asset != show_only_unknown)
{
if (!show_only_unknown)
++unknown_assets_outs_count;
@ -4172,11 +4183,11 @@ std::string wallet2::get_transfers_str(bool include_spent /*= true*/, bool inclu
//----------------------------------------------------------------------------------------------------
std::string wallet2::get_balance_str() const
{
// balance unlocked / [balance total] ticker asset id
// 0.21 / 98.51 DP2 a6974d5874e97e5f4ed5ad0a62f0975edbccb1bb55502fc75c7fe808f12f44d3
// 190.123456789012 / 199.123456789012 ZANO d6329b5b1f7c0805b5c345f4957554002a2f557845f64d7645dae0e051a6498a
// 98.0 BGTVUW af2b12f3033337f9aea1845a6bc3fc966ed4d13227a3ace7706fca7dbcdaa7e2
// 1000.034 DP3 d4aba1020f26927571771e04b585b4ffb211f52708d5e4c465bbdfa4a12e6271
// balance unlocked / [balance total] ticker asset id
// 0.21 / 98.51 DP2 a6974d5874e97e5f4ed5ad0a62f0975edbccb1bb55502fc75c7fe808f12f44d3
// 190.123456789012 / 199.123456789012 ZANO d6329b5b1f7c0805b5c345f4957554002a2f557845f64d7645dae0e051a6498a NATIVE
// 98.0 BGTVUW af2b12f3033337f9aea1845a6bc3fc966ed4d13227a3ace7706fca7dbcdaa7e2
// 1000.034 DP3 d4aba1020f26927571771e04b585b4ffb211f52708d5e4c465bbdfa4a12e6271
static const char* header = " balance unlocked / [balance total] ticker asset id";
std::stringstream ss;
@ -4211,13 +4222,12 @@ std::string wallet2::get_balance_str() const
//----------------------------------------------------------------------------------------------------
std::string wallet2::get_balance_str_raw() const
{
// balance unlocked / [balance total] DP asset id
// 0.21 / 98.51 2 a6974d5874e97e5f4ed5ad0a62f0975edbccb1bb55502fc75c7fe808f12f44d3
// 190.123456789012 / 199.123456789012 12 d6329b5b1f7c0805b5c345f4957554002a2f557845f64d7645dae0e051a6498a
// 98.0 12 af2b12f3033337f9aea1845a6bc3fc966ed4d13227a3ace7706fca7dbcdaa7e2
// 1000.034 3 d4aba1020f26927571771e04b585b4ffb211f52708d5e4c465bbdfa4a12e6271
// balance unlocked / [balance total] ticker asset id DP flags
// 0.21 / 98.51 ZANO d6329b5b1f7c0805b5c345f4957554002a2f557845f64d7645dae0e051a6498a 12 NATIVE
// 2.0 MYFB 13615ffdfbdc09275a1dfc0fbdaf6a9b07849b835ffdfed0b9e1478ea8924774 1 custom
// 1000.0 BurnCT 14608811180d4bbad96a6b91405e329e4f2a10519e6dcea644f83b9f8ccb5863 12 unknown asset
//WHITELIST:
// 7d3f348fbebfffc4e61a3686189cf870ea393e1c88b8f636acbfdacf9e4b2db2 CT
// a7e8e5b31c24f2d6a07e141701237b136d704c9a89f9a5d1ca4a8290df0b9edc WETH
// ...
static const char* header = " balance unlocked / [balance total] ticker asset id DP flags";
@ -4234,7 +4244,7 @@ std::string wallet2::get_balance_str_raw() const
{
uint32_t asset_flags = 0;
asset_descriptor_base asset_info{};
bool has_info = get_asset_info(entry.first, asset_info, asset_flags);
bool has_info = get_asset_info(entry.first, asset_info, asset_flags, true);
ss << " " << std::left << std::setw(21) << print_fixed_decimal_point_with_trailing_spaces(entry.second.unlocked, asset_info.decimal_point);
if (entry.second.total == entry.second.unlocked)
ss << std::string(21 + 3, ' ');
@ -4251,7 +4261,7 @@ std::string wallet2::get_balance_str_raw() const
ss << " ";
if (entry.first == native_coin_asset_id)
if (asset_flags & aif_native_coin)
{
ss << "NATIVE";
}
@ -4261,6 +4271,10 @@ std::string wallet2::get_balance_str_raw() const
ss << "own,";
if (asset_flags & aif_whitelisted)
ss << "whitelisted,";
if (asset_flags & aif_custom)
ss << "custom,";
if (asset_flags & aif_unknown)
ss << "unknown asset,";
ss.seekp(-1, ss.cur); // trim comma
}
ss << ENDL;
@ -5813,7 +5827,7 @@ void wallet2::burn_asset(const crypto::public_key& asset_id, uint64_t amount_to_
result_tx = ft.tx;
}
//----------------------------------------------------------------------------------------------------
bool wallet2::daemon_get_asset_info(const crypto::public_key& asset_id, currency::asset_descriptor_base& adb)
bool wallet2::daemon_get_asset_info(const crypto::public_key& asset_id, currency::asset_descriptor_base& adb) const
{
COMMAND_RPC_GET_ASSET_INFO::request req;
req.asset_id = asset_id;

View file

@ -449,7 +449,7 @@ namespace tools
void burn_asset(const crypto::public_key& asset_id, uint64_t amount_to_burn, currency::finalized_tx& ft, const std::vector<currency::tx_service_attachment>& service_entries = std::vector<currency::tx_service_attachment>(), const std::string& address_to_point = std::string(), uint64_t native_amount_to_point = 0);
void transfer_asset_ownership(const crypto::public_key& asset_id, const currency::asset_owner_pub_key_v& new_owner_v, currency::finalized_tx& ft);
bool daemon_get_asset_info(const crypto::public_key& asset_id, currency::asset_descriptor_base& adb);
bool daemon_get_asset_info(const crypto::public_key& asset_id, currency::asset_descriptor_base& adb) const;
bool set_core_proxy(const std::shared_ptr<i_core_proxy>& proxy);
void set_defragmentation_tx_settings(bool enabled, uint64_t min_outs, uint64_t max_outs, uint64_t max_allowed_amount = CURRENCY_BLOCK_REWARD, size_t decoys_count = SIZE_MAX);
void set_pos_required_decoys_count(size_t v) { m_required_decoys_count = v; }
@ -466,8 +466,8 @@ namespace tools
uint64_t unlocked_balance() 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;
enum asset_info_flags_t : uint32_t { aif_none = 0, aif_native_coin = 1 << 0, aif_whitelisted = 1 << 1, aif_own = 1 << 2, aif_custom = 1 << 3, aif_unknown = 1 << 4 };
bool get_asset_info(const crypto::public_key& asset_id, currency::asset_descriptor_base& asset_info, uint32_t& asset_flags, bool ask_daemon_for_unknown = false) const;
size_t get_asset_decimal_point(const crypto::public_key& asset_id, size_t result_if_not_found = 0) const;
bool get_asset_decimal_point(const crypto::public_key& asset_id, size_t* p_decimal_point_result) const;