1
0
Fork 0
forked from lthn/blockchain

minor operator<< refactoring & related stuff

This commit is contained in:
sowle 2019-05-01 16:03:12 +02:00
parent 976ed481d0
commit 02576ab740
5 changed files with 52 additions and 41 deletions

View file

@ -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<typename T>
std::ostream& print_container_content(std::ostream& out, const T& v);
template<typename T>
std::ostream& operator<< (std::ostream& out, const std::vector<T>& v)
namespace std
{
return print_container_content(out, v);
}
template<typename T>
std::ostream& operator<< (std::ostream& out, const std::list<T>& v)
{
return print_container_content(out, v);
}
template<typename T>
std::ostream& operator<< (std::ostream& out, const std::vector<T>& v)
{
return print_container_content(out, v);
}
template<typename T>
std::ostream& operator<< (std::ostream& out, const std::list<T>& v)
{
return print_container_content(out, v);
}
} // namespace std
template<typename T>
std::ostream& print_container_content(std::ostream& out, const T& v)

View file

@ -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<char *>(&hash), sizeof(crypto::hash));
return true;
}

View file

@ -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 <class T>
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 <class T>
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 <class T>
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); }
}
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

View file

@ -2625,7 +2625,7 @@ bool blockchain_storage::find_blockchain_supplement(const std::list<crypto::hash
blocks.back().first = m_db_blocks[i];
std::list<crypto::hash> 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;
}

View file

@ -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<char *>(&hash), sizeof(crypto::hash));
return true;
}
}