diff --git a/contrib/epee/include/misc_language.h b/contrib/epee/include/misc_language.h index b70052c7..225b8c1e 100644 --- a/contrib/epee/include/misc_language.h +++ b/contrib/epee/include/misc_language.h @@ -389,22 +389,27 @@ namespace misc_utils auto res = container.insert(typename t_container_type::value_type(key, AUTO_VAL_INIT(typename t_container_type::mapped_type()))); return res.first->second; } -} -} +} // namespace misc_utils +} // namespace epee template std::ostream& print_container_content(std::ostream& out, const T& v); -template -std::ostream& operator<< (std::ostream& out, const std::vector& v) +namespace std { - return print_container_content(out, v); -} -template -std::ostream& operator<< (std::ostream& out, const std::list& v) -{ - return print_container_content(out, v); -} + template + std::ostream& operator<< (std::ostream& out, const std::vector& v) + { + return print_container_content(out, v); + } + + template + std::ostream& operator<< (std::ostream& out, const std::list& v) + { + return print_container_content(out, v); + } + +} // namespace std template std::ostream& print_container_content(std::ostream& out, const T& v) diff --git a/src/common/crypto_stream_operators.cpp b/src/common/crypto_stream_operators.cpp new file mode 100644 index 00000000..cc87dd37 --- /dev/null +++ b/src/common/crypto_stream_operators.cpp @@ -0,0 +1,18 @@ +// Copyright (c) 2018-2019 Zano Project +// Distributed under the MIT/X11 software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. +#include "crypto_stream_operators.h" + +bool parse_hash256(const std::string str_hash, crypto::hash& hash) +{ + std::string buf; + bool res = epee::string_tools::parse_hexstr_to_binbuff(str_hash, buf); + if (!res || buf.size() != sizeof(crypto::hash)) + { + std::cout << "invalid hash format: <" << str_hash << '>' << std::endl; + return false; + } + + buf.copy(reinterpret_cast(&hash), sizeof(crypto::hash)); + return true; +} diff --git a/src/common/crypto_stream_operators.h b/src/common/crypto_stream_operators.h index 8ae7f53a..5aaf545c 100644 --- a/src/common/crypto_stream_operators.h +++ b/src/common/crypto_stream_operators.h @@ -8,29 +8,34 @@ #include "include_base_utils.h" #include "crypto/crypto.h" #include "crypto/hash.h" -//------ + bool parse_hash256(const std::string str_hash, crypto::hash& hash); + template -std::ostream &print256(std::ostream &o, const T &v) { +std::ostream &print256(std::ostream &o, const T &v) +{ return o << "<" << epee::string_tools::pod_to_hex(v) << ">"; } template -std::ostream &print16(std::ostream &o, const T &v) { +std::ostream &print16(std::ostream &o, const T &v) +{ return o << "<" << epee::string_tools::pod_to_hex(v).substr(0, 5) << "..>"; } template -std::string print16(const T &v) { +std::string print16(const T &v) +{ return std::string("<") + epee::string_tools::pod_to_hex(v).substr(0, 5) + "..>"; } -namespace crypto { - inline std::ostream &operator <<(std::ostream &o, const crypto::public_key &v) { return print256(o, v); } - inline std::ostream &operator <<(std::ostream &o, const crypto::secret_key &v) { return print256(o, v); } - inline std::ostream &operator <<(std::ostream &o, const crypto::key_derivation &v) { return print256(o, v); } - inline std::ostream &operator <<(std::ostream &o, const crypto::key_image &v) { return print256(o, v); } - inline std::ostream &operator <<(std::ostream &o, const crypto::signature &v) { return print256(o, v); } - inline std::ostream &operator <<(std::ostream &o, const crypto::hash &v) { return print256(o, v); } -} \ No newline at end of file +namespace crypto +{ + inline std::ostream &operator <<(std::ostream &o, const crypto::public_key &v) { return print256(o, v); } + inline std::ostream &operator <<(std::ostream &o, const crypto::secret_key &v) { return print256(o, v); } + inline std::ostream &operator <<(std::ostream &o, const crypto::key_derivation &v) { return print256(o, v); } + inline std::ostream &operator <<(std::ostream &o, const crypto::key_image &v) { return print256(o, v); } + inline std::ostream &operator <<(std::ostream &o, const crypto::signature &v) { return print256(o, v); } + inline std::ostream &operator <<(std::ostream &o, const crypto::hash &v) { return print256(o, v); } +} // namespace crypto diff --git a/src/currency_core/blockchain_storage.cpp b/src/currency_core/blockchain_storage.cpp index 5e2569be..d2d40df8 100644 --- a/src/currency_core/blockchain_storage.cpp +++ b/src/currency_core/blockchain_storage.cpp @@ -2625,7 +2625,7 @@ bool blockchain_storage::find_blockchain_supplement(const std::list mis; get_transactions_direct(m_db_blocks[i]->bl.tx_hashes, blocks.back().second, mis); - CHECK_AND_ASSERT_MES(!mis.size(), false, "internal error, transaction from block " << get_block_hash(m_db_blocks[i]->bl) << "[" << i << "] not found" ); + CHECK_AND_ASSERT_MES(!mis.size(), false, "internal error, block " << get_block_hash(m_db_blocks[i]->bl) << " [" << i << "] contains missing transactions: " << mis); } return true; } diff --git a/src/currency_core/currency_format_utils.cpp b/src/currency_core/currency_format_utils.cpp index 57b9a8d2..a2c019d3 100644 --- a/src/currency_core/currency_format_utils.cpp +++ b/src/currency_core/currency_format_utils.cpp @@ -2665,20 +2665,3 @@ namespace currency } } // namespace currency - - -bool parse_hash256(const std::string str_hash, crypto::hash& hash) -{ - std::string buf; - bool res = epee::string_tools::parse_hexstr_to_binbuff(str_hash, buf); - if (!res || buf.size() != sizeof(crypto::hash)) - { - std::cout << "invalid hash format: <" << str_hash << '>' << std::endl; - return false; - } - else - { - buf.copy(reinterpret_cast(&hash), sizeof(crypto::hash)); - return true; - } -}