1
0
Fork 0
forked from lthn/blockchain

simplewallet & wallet: printing balance unlocked + disabling tor by default

This commit is contained in:
sowle 2023-05-26 22:01:01 +02:00
parent dbd8c39fe2
commit 943e234a3d
No known key found for this signature in database
GPG key ID: C07A24B2D89D49FC
4 changed files with 65 additions and 29 deletions

View file

@ -1,4 +1,4 @@
// Copyright (c) 2014-2018 Zano Project
// Copyright (c) 2014-2023 Zano Project
// Copyright (c) 2014-2018 The Louisdor Project
// Copyright (c) 2012-2013 The Cryptonote developers
// Copyright (c) 2012-2013 The Boolberry developers
@ -556,12 +556,23 @@ namespace currency
return true;
}
//---------------------------------------------------------------
// outputs "1391306.970000000000"
template<typename t_number>
std::string print_fixed_decimal_point(t_number amount, size_t decimal_point)
{
return epee::string_tools::print_fixed_decimal_point(amount, decimal_point);
}
//---------------------------------------------------------------
// outputs "1391306.97 "
template<typename t_number>
std::string print_fixed_decimal_point_with_trailing_spaces(t_number amount, size_t decimal_point)
{
std::string s = epee::string_tools::print_fixed_decimal_point(amount, decimal_point);
for(size_t n = s.size() - 1; n != 0 && s[n] == '0'; --n)
s[n] = ' ';
return s;
}
//---------------------------------------------------------------
template<typename t_number>
std::string print_money(t_number amount)
{

View file

@ -1,4 +1,4 @@
// Copyright (c) 2014-2019 Zano Project
// Copyright (c) 2014-2023 Zano Project
// Copyright (c) 2014-2018 The Louisdor Project
// Copyright (c) 2012-2013 The Cryptonote developers
// Distributed under the MIT/X11 software license, see the accompanying
@ -857,15 +857,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>()*/)
{
std::list<tools::wallet_public::asset_balance_entry> balances;
uint64_t mined = 0;
m_wallet->balance(balances, mined);
std::stringstream ss;
for (const tools::wallet_public::asset_balance_entry& b : balances)
{
ss << std::setw(21) << print_fixed_decimal_point(b.total, b.asset_info.decimal_point) << "\t" << b.asset_info.ticker << "\t" << b.asset_info.asset_id << ENDL;
}
success_msg_writer() << "Balance: " << ENDL << ss.str();
success_msg_writer() << m_wallet->get_balance_str();
return true;
}
//----------------------------------------------------------------------------------------------------

View file

@ -1,4 +1,4 @@
// Copyright (c) 2014-2022 Zano Project
// Copyright (c) 2014-2023 Zano Project
// Copyright (c) 2014-2018 The Louisdor Project
// Copyright (c) 2012-2013 The Cryptonote developers
// Distributed under the MIT/X11 software license, see the accompanying
@ -53,22 +53,27 @@ using namespace currency;
ENABLE_CHANNEL_BY_DEFAULT("wallet")
namespace tools
{
wallet2::wallet2() : m_stop(false),
m_wcallback(new i_wallet2_callback()), //stub
m_core_proxy(new default_http_core_proxy()),
m_upper_transaction_size_limit(0),
m_height_of_start_sync(0),
m_last_sync_percent(0),
m_fake_outputs_count(0),
m_do_rise_transfer(false),
m_log_prefix("???"),
m_watch_only(false),
m_last_pow_block_h(0),
m_minimum_height(WALLET_MINIMUM_HEIGHT_UNSET_CONST),
m_pos_mint_packing_size(WALLET_DEFAULT_POS_MINT_PACKING_SIZE),
m_current_wallet_file_size(0),
m_use_deffered_global_outputs(false),
m_disable_tor_relay(false)
wallet2::wallet2()
: m_stop(false)
, m_wcallback(new i_wallet2_callback()) //stub
, m_core_proxy(new default_http_core_proxy())
, m_upper_transaction_size_limit(0)
, m_height_of_start_sync(0)
, m_last_sync_percent(0)
, m_fake_outputs_count(0)
, m_do_rise_transfer(false)
, m_log_prefix("???")
, m_watch_only(false)
, m_last_pow_block_h(0)
, m_minimum_height(WALLET_MINIMUM_HEIGHT_UNSET_CONST)
, m_pos_mint_packing_size(WALLET_DEFAULT_POS_MINT_PACKING_SIZE)
, m_current_wallet_file_size(0)
, m_use_deffered_global_outputs(false)
#ifdef DISABLE_TOR
, m_disable_tor_relay(true)
#else
, m_disable_tor_relay(false)
#endif
{
m_core_runtime_config = currency::get_default_core_runtime_config();
}
@ -3413,6 +3418,33 @@ std::string wallet2::get_transfers_str(bool include_spent /*= true*/, bool inclu
return ss.str();
}
//----------------------------------------------------------------------------------------------------
std::string wallet2::get_balance_str() const
{
// balance unlocked / [balance total] ticker asset id
// 1391306.970000000000 / 1391306.970000000000 ZANO d6329b5b1f7c0805b5c345f4957554002a2f557845f64d7645dae0e051a6498a
// 1391306.97 ZANO d6329b5b1f7c0805b5c345f4957554002a2f557845f64d7645dae0e051a6498a
// 106.971 / 206.4 ZANO d6329b5b1f7c0805b5c345f4957554002a2f557845f64d7645dae0e051a6498a
static const char* header = " balance unlocked / [balance total] ticker asset id";
std::stringstream ss;
ss << header << ENDL;
std::list<tools::wallet_public::asset_balance_entry> balances;
uint64_t mined = 0;
balance(balances, mined);
for (const tools::wallet_public::asset_balance_entry& b : balances)
{
ss << " " << std::setw(20) << print_fixed_decimal_point_with_trailing_spaces(b.unlocked, b.asset_info.decimal_point);
if (b.total == b.unlocked)
ss << " ";
else
ss << " / " << std::setw(20) << print_fixed_decimal_point_with_trailing_spaces(b.total, b.asset_info.decimal_point);
ss << " " << std::setw(8) << std::left << b.asset_info.ticker << " " << b.asset_info.asset_id << ENDL;
}
return ss.str();
}
//----------------------------------------------------------------------------------------------------
void wallet2::get_payments(const std::string& payment_id, std::list<wallet2::payment_details>& payments, uint64_t min_height) const
{
auto range = m_payments.equal_range(payment_id);

View file

@ -1,4 +1,4 @@
// Copyright (c) 2014-2022 Zano Project
// Copyright (c) 2014-2023 Zano Project
// Copyright (c) 2014-2018 The Louisdor Project
// Copyright (c) 2012-2013 The Cryptonote developers
// Distributed under the MIT/X11 software license, see the accompanying
@ -743,6 +743,7 @@ namespace tools
void get_transfers(wallet2::transfer_container& incoming_transfers) const;
std::string get_transfers_str(bool include_spent = true, bool include_unspent = true) const;
std::string wallet2::get_balance_str() const;
// Returns all payments by given id in unspecified order
void get_payments(const std::string& payment_id, std::list<payment_details>& payments, uint64_t min_height = 0) const;