1
0
Fork 0
forked from lthn/blockchain

better transfers logging and code clean-up

This commit is contained in:
sowle 2020-05-26 15:55:58 +03:00
parent 200494027f
commit 33cf01ff34
No known key found for this signature in database
GPG key ID: C07A24B2D89D49FC
3 changed files with 37 additions and 20 deletions

View file

@ -1,4 +1,4 @@
// Copyright (c) 2014-2018 Zano Project
// Copyright (c) 2014-2020 Zano Project
// Copyright (c) 2014-2018 The Louisdor Project
// Copyright (c) 2012-2013 The Cryptonote developers
// Copyright (c) 2012-2013 The Boolberry developers
@ -37,3 +37,21 @@ namespace std { \
} \
}; \
}
namespace std
{
// this allows using std::pair<> as a key in unordered std containers
template <class T1, class T2>
struct hash<pair<T1, T2>>
{
size_t operator()(const pair<T1, T2>& p) const
{
auto hash1 = hash<T1>{}(p.first);
auto hash2 = hash<T2>{}(p.second);
return hash1 ^ hash2;
}
};
} // namespace std

View file

@ -593,14 +593,28 @@ void simple_wallet::on_new_block(uint64_t height, const currency::block& block)
m_refresh_progress_reporter.update(height, false);
}
//----------------------------------------------------------------------------------------------------
std::string print_money_trailing_zeros_replaced_with_spaces(uint64_t amount)
{
std::string s = print_money(amount);
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, ' ');
}
return s;
}
//----------------------------------------------------------------------------------------------------
void simple_wallet::on_transfer2(const tools::wallet_public::wallet_transfer_info& wti, uint64_t balance, uint64_t unlocked_balance, uint64_t total_mined)
{
epee::log_space::console_colors color = wti.is_income ? epee::log_space::console_color_green : epee::log_space::console_color_magenta;
message_writer(color, false) <<
"height " << wti.height <<
", tx " << wti.tx_hash <<
(wti.is_income ? ", received " : ", spent ") << print_money_brief(wti.amount) <<
", balance: " << print_money_brief(balance);
" " << std::right << std::setw(18) << print_money_trailing_zeros_replaced_with_spaces(wti.amount) << (wti.is_income ? " received," : " spent, ") <<
" balance: " << print_money_brief(balance);
m_refresh_progress_reporter.update(wti.height, true);
}
//----------------------------------------------------------------------------------------------------

View file

@ -1,4 +1,4 @@
// Copyright (c) 2014-2018 Zano Project
// Copyright (c) 2014-2020 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
@ -24,6 +24,7 @@
#include "currency_core/account_boost_serialization.h"
#include "currency_core/currency_format_utils.h"
#include "common/make_hashable.h"
#include "wallet_public_structs_defs.h"
#include "currency_core/currency_format_utils.h"
#include "common/unordered_containers_boost_serialization.h"
@ -72,22 +73,6 @@ const uint64_t WALLET_MINIMUM_HEIGHT_UNSET_CONST = std::numeric_limits<uint64_t>
class test_generator;
namespace std
{
template <class T1, class T2>
struct hash<pair<T1, T2>>
{
size_t operator()(const pair<T1, T2>& p) const
{
auto hash1 = hash<T1>{}(p.first);
auto hash2 = hash<T2>{}(p.second);
return hash1 ^ hash2;
}
};
} // namespace std
namespace tools
{
#pragma pack(push, 1)