diff --git a/nano/core_test/block.cpp b/nano/core_test/block.cpp index fe90835fea..8ee0c9a503 100644 --- a/nano/core_test/block.cpp +++ b/nano/core_test/block.cpp @@ -186,73 +186,6 @@ TEST (block, change_serialize_json) ASSERT_EQ (*block1, block2); } -TEST (uint512_union, parse_zero) -{ - nano::uint512_union input (nano::uint512_t (0)); - std::string text; - input.encode_hex (text); - nano::uint512_union output; - auto error (output.decode_hex (text)); - ASSERT_FALSE (error); - ASSERT_EQ (input, output); - ASSERT_TRUE (output.number ().is_zero ()); -} - -TEST (uint512_union, parse_zero_short) -{ - std::string text ("0"); - nano::uint512_union output; - auto error (output.decode_hex (text)); - ASSERT_FALSE (error); - ASSERT_TRUE (output.number ().is_zero ()); -} - -TEST (uint512_union, parse_one) -{ - nano::uint512_union input (nano::uint512_t (1)); - std::string text; - input.encode_hex (text); - nano::uint512_union output; - auto error (output.decode_hex (text)); - ASSERT_FALSE (error); - ASSERT_EQ (input, output); - ASSERT_EQ (1, output.number ()); -} - -TEST (uint512_union, parse_error_symbol) -{ - nano::uint512_union input (nano::uint512_t (1000)); - std::string text; - input.encode_hex (text); - text[5] = '!'; - nano::uint512_union output; - auto error (output.decode_hex (text)); - ASSERT_TRUE (error); -} - -TEST (uint512_union, max) -{ - nano::uint512_union input (std::numeric_limits::max ()); - std::string text; - input.encode_hex (text); - nano::uint512_union output; - auto error (output.decode_hex (text)); - ASSERT_FALSE (error); - ASSERT_EQ (input, output); - ASSERT_EQ (nano::uint512_t ("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"), output.number ()); -} - -TEST (uint512_union, parse_error_overflow) -{ - nano::uint512_union input (std::numeric_limits::max ()); - std::string text; - input.encode_hex (text); - text.push_back (0); - nano::uint512_union output; - auto error (output.decode_hex (text)); - ASSERT_TRUE (error); -} - TEST (send_block, deserialize) { nano::block_builder builder; diff --git a/nano/core_test/numbers.cpp b/nano/core_test/numbers.cpp index 7b6e77015e..fd43f75865 100644 --- a/nano/core_test/numbers.cpp +++ b/nano/core_test/numbers.cpp @@ -345,8 +345,7 @@ TEST (uint256_union, decode_empty) TEST (uint256_union, parse_zero) { nano::uint256_union input (nano::uint256_t (0)); - std::string text; - input.encode_hex (text); + std::string text = input.to_string (); nano::uint256_union output; auto error (output.decode_hex (text)); ASSERT_FALSE (error); @@ -366,8 +365,7 @@ TEST (uint256_union, parse_zero_short) TEST (uint256_union, parse_one) { nano::uint256_union input (nano::uint256_t (1)); - std::string text; - input.encode_hex (text); + std::string text = input.to_string (); nano::uint256_union output; auto error (output.decode_hex (text)); ASSERT_FALSE (error); @@ -378,8 +376,7 @@ TEST (uint256_union, parse_one) TEST (uint256_union, parse_error_symbol) { nano::uint256_union input (nano::uint256_t (1000)); - std::string text; - input.encode_hex (text); + std::string text = input.to_string (); text[5] = '!'; nano::uint256_union output; auto error (output.decode_hex (text)); @@ -389,8 +386,7 @@ TEST (uint256_union, parse_error_symbol) TEST (uint256_union, max_hex) { nano::uint256_union input (std::numeric_limits::max ()); - std::string text; - input.encode_hex (text); + std::string text = input.to_string (); nano::uint256_union output; auto error (output.decode_hex (text)); ASSERT_FALSE (error); @@ -409,8 +405,7 @@ TEST (uint256_union, decode_dec) TEST (uint256_union, max_dec) { nano::uint256_union input (std::numeric_limits::max ()); - std::string text; - input.encode_dec (text); + std::string text = input.to_string_dec (); nano::uint256_union output; auto error (output.decode_dec (text)); ASSERT_FALSE (error); @@ -445,8 +440,7 @@ TEST (uint256_union, decode_dec_leading_zero) TEST (uint256_union, parse_error_overflow) { nano::uint256_union input (std::numeric_limits::max ()); - std::string text; - input.encode_hex (text); + std::string text = input.to_string (); text.push_back (0); nano::uint256_union output; auto error (output.decode_hex (text)); @@ -650,6 +644,68 @@ TEST (uint512_union, hash) } } +TEST (uint512_union, parse_zero) +{ + nano::uint512_union input (nano::uint512_t (0)); + std::string text = input.to_string (); + nano::uint512_union output; + auto error (output.decode_hex (text)); + ASSERT_FALSE (error); + ASSERT_EQ (input, output); + ASSERT_TRUE (output.number ().is_zero ()); +} + +TEST (uint512_union, parse_zero_short) +{ + std::string text ("0"); + nano::uint512_union output; + auto error (output.decode_hex (text)); + ASSERT_FALSE (error); + ASSERT_TRUE (output.number ().is_zero ()); +} + +TEST (uint512_union, parse_one) +{ + nano::uint512_union input (nano::uint512_t (1)); + std::string text = input.to_string (); + nano::uint512_union output; + auto error (output.decode_hex (text)); + ASSERT_FALSE (error); + ASSERT_EQ (input, output); + ASSERT_EQ (1, output.number ()); +} + +TEST (uint512_union, parse_error_symbol) +{ + nano::uint512_union input (nano::uint512_t (1000)); + std::string text = input.to_string (); + text[5] = '!'; + nano::uint512_union output; + auto error (output.decode_hex (text)); + ASSERT_TRUE (error); +} + +TEST (uint512_union, max) +{ + nano::uint512_union input (std::numeric_limits::max ()); + std::string text = input.to_string (); + nano::uint512_union output; + auto error (output.decode_hex (text)); + ASSERT_FALSE (error); + ASSERT_EQ (input, output); + ASSERT_EQ (nano::uint512_t ("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"), output.number ()); +} + +TEST (uint512_union, parse_error_overflow) +{ + nano::uint512_union input (std::numeric_limits::max ()); + std::string text = input.to_string (); + text.push_back (0); + nano::uint512_union output; + auto error (output.decode_hex (text)); + ASSERT_TRUE (error); +} + TEST (sat_math, add_sat) { // Test uint128_t @@ -743,4 +799,67 @@ TEST (sat_math, sub_sat) ASSERT_EQ (nano::sub_sat (hundred, nano::uint512_t (200)), min); ASSERT_EQ (nano::sub_sat (min, max), min); } +} + +TEST (account, encode_zero) +{ + nano::account number0{}; + std::stringstream stream; + number0.encode_account (stream); + auto str0 = stream.str (); + + /* + * Handle different lengths for "xrb_" prefixed and "nano_" prefixed accounts + */ + ASSERT_EQ ((str0.front () == 'x') ? 64 : 65, str0.size ()); + ASSERT_EQ (65, str0.size ()); + nano::account number1; + ASSERT_FALSE (number1.decode_account (str0)); + ASSERT_EQ (number0, number1); +} + +TEST (account, encode_all) +{ + nano::account number0; + number0.decode_hex ("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); + std::stringstream stream; + number0.encode_account (stream); + auto str0 = stream.str (); + + /* + * Handle different lengths for "xrb_" prefixed and "nano_" prefixed accounts + */ + ASSERT_EQ ((str0.front () == 'x') ? 64 : 65, str0.size ()); + nano::account number1; + ASSERT_FALSE (number1.decode_account (str0)); + ASSERT_EQ (number0, number1); +} + +TEST (account, encode_fail) +{ + nano::account number0{}; + std::stringstream stream; + number0.encode_account (stream); + auto str0 = stream.str (); + str0[16] ^= 1; + nano::account number1; + ASSERT_TRUE (number1.decode_account (str0)); +} + +TEST (account, known_addresses) +{ + nano::account account1{ "0000000000000000000000000000000000000000000000000000000000000000" }; + ASSERT_EQ (account1.to_account (), "nano_1111111111111111111111111111111111111111111111111111hifc8npp"); + + nano::account account2{ "B0311EA55708D6A53C75CDBF88300259C6D018522FE3D4D0A242E431F9E8B6D0" }; + ASSERT_EQ (account2.to_account (), "nano_3e3j5tkog48pnny9dmfzj1r16pg8t1e76dz5tmac6iq689wyjfpiij4txtdo"); + + nano::account account3{ "45C6FF9D1706D61F0821327752671BDA9F9ED2DA40326B01935AB566FB9E08ED" }; + ASSERT_EQ (account3.to_account (), "nano_1jg8zygjg3pp5w644emqcbmjqpnzmubfni3kfe1s8pooeuxsw49fdq1mco9j"); + + nano::account account4{ "E89208DD038FBB269987689621D52292AE9C35941A7484756ECCED92A65093BA" }; + ASSERT_EQ (account4.to_account (), "nano_3t6k35gi95xu6tergt6p69ck76ogmitsa8mnijtpxm9fkcm736xtoncuohr3"); + + nano::account account5{ "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" }; + ASSERT_EQ (account5.to_account (), "nano_3zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzc3yoon41"); } \ No newline at end of file diff --git a/nano/core_test/wallet.cpp b/nano/core_test/wallet.cpp index 6a95ba34ec..8aed6748d0 100644 --- a/nano/core_test/wallet.cpp +++ b/nano/core_test/wallet.cpp @@ -319,48 +319,6 @@ TEST (wallet, rekey) ASSERT_TRUE (wallet.rekey (transaction, "2")); } -TEST (account, encode_zero) -{ - nano::account number0{}; - std::string str0; - number0.encode_account (str0); - - /* - * Handle different lengths for "xrb_" prefixed and "nano_" prefixed accounts - */ - ASSERT_EQ ((str0.front () == 'x') ? 64 : 65, str0.size ()); - ASSERT_EQ (65, str0.size ()); - nano::account number1; - ASSERT_FALSE (number1.decode_account (str0)); - ASSERT_EQ (number0, number1); -} - -TEST (account, encode_all) -{ - nano::account number0; - number0.decode_hex ("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); - std::string str0; - number0.encode_account (str0); - - /* - * Handle different lengths for "xrb_" prefixed and "nano_" prefixed accounts - */ - ASSERT_EQ ((str0.front () == 'x') ? 64 : 65, str0.size ()); - nano::account number1; - ASSERT_FALSE (number1.decode_account (str0)); - ASSERT_EQ (number0, number1); -} - -TEST (account, encode_fail) -{ - nano::account number0{}; - std::string str0; - number0.encode_account (str0); - str0[16] ^= 1; - nano::account number1; - ASSERT_TRUE (number1.decode_account (str0)); -} - TEST (wallet, hash_password) { bool init; diff --git a/nano/lib/CMakeLists.txt b/nano/lib/CMakeLists.txt index c05152a287..3e4d9a2365 100644 --- a/nano/lib/CMakeLists.txt +++ b/nano/lib/CMakeLists.txt @@ -55,6 +55,8 @@ add_library( errors.cpp files.hpp files.cpp + formatting.hpp + formatting.cpp fwd.hpp id_dispenser.hpp interval.hpp diff --git a/nano/lib/blocks.cpp b/nano/lib/blocks.cpp index d7d3cb8663..daa78b5559 100644 --- a/nano/lib/blocks.cpp +++ b/nano/lib/blocks.cpp @@ -472,17 +472,11 @@ void nano::send_block::serialize_json (std::string & string_a, bool single_line) void nano::send_block::serialize_json (boost::property_tree::ptree & tree) const { tree.put ("type", "send"); - std::string previous; - hashables.previous.encode_hex (previous); - tree.put ("previous", previous); + tree.put ("previous", hashables.previous.to_string ()); tree.put ("destination", hashables.destination.to_account ()); - std::string balance; - hashables.balance.encode_hex (balance); - tree.put ("balance", balance); - std::string signature_l; - signature.encode_hex (signature_l); + tree.put ("balance", hashables.balance.to_string ()); tree.put ("work", nano::to_string_hex (work)); - tree.put ("signature", signature_l); + tree.put ("signature", signature.to_string ()); } bool nano::send_block::deserialize_json (boost::property_tree::ptree const & tree_a) @@ -836,10 +830,8 @@ void nano::open_block::serialize_json (boost::property_tree::ptree & tree) const tree.put ("source", hashables.source.to_string ()); tree.put ("representative", hashables.representative.to_account ()); tree.put ("account", hashables.account.to_account ()); - std::string signature_l; - signature.encode_hex (signature_l); tree.put ("work", nano::to_string_hex (work)); - tree.put ("signature", signature_l); + tree.put ("signature", signature.to_string ()); } bool nano::open_block::deserialize_json (boost::property_tree::ptree const & tree_a) @@ -1105,9 +1097,7 @@ void nano::change_block::serialize_json (boost::property_tree::ptree & tree) con tree.put ("previous", hashables.previous.to_string ()); tree.put ("representative", hashables.representative.to_account ()); tree.put ("work", nano::to_string_hex (work)); - std::string signature_l; - signature.encode_hex (signature_l); - tree.put ("signature", signature_l); + tree.put ("signature", signature.to_string ()); } bool nano::change_block::deserialize_json (boost::property_tree::ptree const & tree_a) @@ -1424,9 +1414,7 @@ void nano::state_block::serialize_json (boost::property_tree::ptree & tree) cons tree.put ("balance", hashables.balance.to_string_dec ()); tree.put ("link", hashables.link.to_string ()); tree.put ("link_as_account", hashables.link.to_account ()); - std::string signature_l; - signature.encode_hex (signature_l); - tree.put ("signature", signature_l); + tree.put ("signature", signature.to_string ()); tree.put ("work", nano::to_string_hex (work)); } @@ -1722,16 +1710,10 @@ void nano::receive_block::serialize_json (std::string & string_a, bool single_li void nano::receive_block::serialize_json (boost::property_tree::ptree & tree) const { tree.put ("type", "receive"); - std::string previous; - hashables.previous.encode_hex (previous); - tree.put ("previous", previous); - std::string source; - hashables.source.encode_hex (source); - tree.put ("source", source); - std::string signature_l; - signature.encode_hex (signature_l); + tree.put ("previous", hashables.previous.to_string ()); + tree.put ("source", hashables.source.to_string ()); tree.put ("work", nano::to_string_hex (work)); - tree.put ("signature", signature_l); + tree.put ("signature", signature.to_string ()); } bool nano::receive_block::deserialize_json (boost::property_tree::ptree const & tree_a) diff --git a/nano/lib/common.hpp b/nano/lib/common.hpp index 1e54097d05..990aab302e 100644 --- a/nano/lib/common.hpp +++ b/nano/lib/common.hpp @@ -2,6 +2,7 @@ namespace boost::asio::ip { +class address; class tcp; template class basic_endpoint; @@ -9,6 +10,7 @@ class basic_endpoint; namespace nano { +using ip_address = boost::asio::ip::address; using endpoint = boost::asio::ip::basic_endpoint; using tcp_endpoint = endpoint; } diff --git a/nano/lib/formatting.cpp b/nano/lib/formatting.cpp new file mode 100644 index 0000000000..d103a15899 --- /dev/null +++ b/nano/lib/formatting.cpp @@ -0,0 +1 @@ +#include diff --git a/nano/lib/formatting.hpp b/nano/lib/formatting.hpp new file mode 100644 index 0000000000..fc16806a0c --- /dev/null +++ b/nano/lib/formatting.hpp @@ -0,0 +1,61 @@ +#pragma once + +#include +#include + +#include + +template <> +struct fmt::formatter : fmt::ostream_formatter +{ +}; +template <> +struct fmt::formatter : fmt::ostream_formatter +{ +}; + +template <> +struct fmt::formatter : fmt::ostream_formatter +{ +}; +template <> +struct fmt::formatter : fmt::ostream_formatter +{ +}; +template <> +struct fmt::formatter : fmt::ostream_formatter +{ +}; + +template <> +struct fmt::formatter : fmt::ostream_formatter +{ +}; +template <> +struct fmt::formatter : fmt::ostream_formatter +{ +}; +template <> +struct fmt::formatter : fmt::ostream_formatter +{ +}; +template <> +struct fmt::formatter : fmt::ostream_formatter +{ +}; +template <> +struct fmt::formatter : fmt::formatter +{ +}; +template <> +struct fmt::formatter : fmt::formatter +{ +}; +template <> +struct fmt::formatter : fmt::formatter +{ +}; +template <> +struct fmt::formatter : fmt::formatter +{ +}; diff --git a/nano/lib/logging.hpp b/nano/lib/logging.hpp index ae9563300a..2e6d60173b 100644 --- a/nano/lib/logging.hpp +++ b/nano/lib/logging.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include #include #include diff --git a/nano/lib/numbers.cpp b/nano/lib/numbers.cpp index 6c00712f7b..00ad310a15 100644 --- a/nano/lib/numbers.cpp +++ b/nano/lib/numbers.cpp @@ -5,6 +5,8 @@ #include #include +#include + #include #include #include @@ -52,33 +54,40 @@ nano::public_key nano::public_key::from_node_id (std::string const & text) return result; } -void nano::public_key::encode_account (std::string & destination_a) const +void nano::public_key::encode_account (std::ostream & os) const { - debug_assert (destination_a.empty ()); - destination_a.reserve (65); - uint64_t check (0); + uint64_t check = 0; + blake2b_state hash; blake2b_init (&hash, 5); blake2b_update (&hash, bytes.data (), bytes.size ()); blake2b_final (&hash, reinterpret_cast (&check), 5); - nano::uint512_t number_l (number ()); + + nano::uint512_t number_l{ number () }; number_l <<= 40; - number_l |= nano::uint512_t (check); + number_l |= nano::uint512_t{ check }; + + // Pre-calculate all characters in reverse order + std::array encoded{}; for (auto i (0); i < 60; ++i) { - uint8_t r (number_l & static_cast (0x1f)); + uint8_t r{ number_l & static_cast (0x1f) }; number_l >>= 5; - destination_a.push_back (account_encode (r)); + encoded[59 - i] = account_encode (r); } - destination_a.append ("_onan"); // nano_ - std::reverse (destination_a.begin (), destination_a.end ()); + + // Write prefix + os << "nano_"; + + // Write encoded characters + os.write (encoded.data (), encoded.size ()); } std::string nano::public_key::to_account () const { - std::string result; - encode_account (result); - return result; + std::stringstream stream; + encode_account (stream); + return stream.str (); } nano::public_key const & nano::public_key::null () @@ -170,13 +179,6 @@ void nano::uint256_union::encrypt (nano::raw_key const & cleartext, nano::raw_ke enc.ProcessData (bytes.data (), cleartext.bytes.data (), sizeof (cleartext.bytes)); } -std::string nano::uint256_union::to_string () const -{ - std::string result; - encode_hex (result); - return result; -} - nano::uint256_union & nano::uint256_union::operator^= (nano::uint256_union const & other_a) { auto j (other_a.qwords.begin ()); @@ -204,13 +206,11 @@ nano::uint256_union::uint256_union (std::string const & hex_a) release_assert (!error); } -void nano::uint256_union::encode_hex (std::string & text) const +void nano::uint256_union::encode_hex (std::ostream & stream) const { - debug_assert (text.empty ()); - std::stringstream stream; + boost::io::ios_flags_saver ifs{ stream }; stream << std::hex << std::uppercase << std::noshowbase << std::setw (64) << std::setfill ('0'); stream << number (); - text = stream.str (); } bool nano::uint256_union::decode_hex (std::string const & text) @@ -242,13 +242,11 @@ bool nano::uint256_union::decode_hex (std::string const & text) return error; } -void nano::uint256_union::encode_dec (std::string & text) const +void nano::uint256_union::encode_dec (std::ostream & stream) const { - debug_assert (text.empty ()); - std::stringstream stream; + boost::io::ios_flags_saver ifs{ stream }; stream << std::dec << std::noshowbase; stream << number (); - text = stream.str (); } bool nano::uint256_union::decode_dec (std::string const & text) @@ -276,13 +274,29 @@ bool nano::uint256_union::decode_dec (std::string const & text) return error; } -void nano::uint512_union::encode_hex (std::string & text) const +std::string nano::uint256_union::to_string () const +{ + std::stringstream stream; + encode_hex (stream); + return stream.str (); +} + +std::string nano::uint256_union::to_string_dec () const { - debug_assert (text.empty ()); std::stringstream stream; + encode_dec (stream); + return stream.str (); +} + +/* + * uint512_union + */ + +void nano::uint512_union::encode_hex (std::ostream & stream) const +{ + boost::io::ios_flags_saver ifs{ stream }; stream << std::hex << std::uppercase << std::noshowbase << std::setw (128) << std::setfill ('0'); stream << number (); - text = stream.str (); } bool nano::uint512_union::decode_hex (std::string const & text) @@ -312,11 +326,15 @@ bool nano::uint512_union::decode_hex (std::string const & text) std::string nano::uint512_union::to_string () const { - std::string result; - encode_hex (result); - return result; + std::stringstream stream; + encode_hex (stream); + return stream.str (); } +/* + * raw_key + */ + nano::raw_key::~raw_key () { secure_wipe_memory (bytes.data (), bytes.size ()); @@ -371,19 +389,21 @@ bool nano::validate_message (nano::public_key const & public_key, nano::uint256_ return validate_message (public_key, message.bytes.data (), sizeof (message.bytes), signature); } +/* + * uint128_union + */ + nano::uint128_union::uint128_union (std::string const & string_a) { auto error (decode_hex (string_a)); release_assert (!error); } -void nano::uint128_union::encode_hex (std::string & text) const +void nano::uint128_union::encode_hex (std::ostream & stream) const { - debug_assert (text.empty ()); - std::stringstream stream; + boost::io::ios_flags_saver ifs{ stream }; stream << std::hex << std::uppercase << std::noshowbase << std::setw (32) << std::setfill ('0'); stream << number (); - text = stream.str (); } bool nano::uint128_union::decode_hex (std::string const & text) @@ -411,13 +431,11 @@ bool nano::uint128_union::decode_hex (std::string const & text) return error; } -void nano::uint128_union::encode_dec (std::string & text) const +void nano::uint128_union::encode_dec (std::ostream & stream) const { - debug_assert (text.empty ()); - std::stringstream stream; + boost::io::ios_flags_saver ifs{ stream }; stream << std::dec << std::noshowbase; stream << number (); - text = stream.str (); } bool nano::uint128_union::decode_dec (std::string const & text, bool decimal) @@ -525,6 +543,24 @@ bool nano::uint128_union::decode_dec (std::string const & text, nano::uint128_t return error; } +std::string nano::uint128_union::to_string () const +{ + std::stringstream stream; + encode_hex (stream); + return stream.str (); +} + +std::string nano::uint128_union::to_string_dec () const +{ + std::stringstream stream; + encode_dec (stream); + return stream.str (); +} + +/* + * + */ + void format_frac (std::ostringstream & stream, nano::uint128_t value, nano::uint128_t scale, int precision) { auto reduce = scale; @@ -651,20 +687,6 @@ std::string nano::uint128_union::format_balance (nano::uint128_t scale, int prec return ::format_balance (number (), scale, precision, group_digits, thousands_sep, decimal_point, grouping); } -std::string nano::uint128_union::to_string () const -{ - std::string result; - encode_hex (result); - return result; -} - -std::string nano::uint128_union::to_string_dec () const -{ - std::string result; - encode_dec (result); - return result; -} - bool nano::hash_or_account::decode_hex (std::string const & text_a) { return raw.decode_hex (text_a); @@ -685,6 +707,10 @@ std::string nano::hash_or_account::to_account () const return account.to_account (); } +/* + * + */ + std::string nano::to_string_hex (uint64_t const value_a) { std::stringstream stream; @@ -738,34 +764,40 @@ std::string nano::to_string (double const value_a, int const precision_a) return stream.str (); } -std::ostream & nano::operator<< (std::ostream & os, const uint128_union & val) +std::ostream & nano::operator<< (std::ostream & os, const nano::uint128_union & val) { - // TODO: Replace with streaming implementation - os << val.to_string (); + val.encode_hex (os); return os; } -std::ostream & nano::operator<< (std::ostream & os, const uint256_union & val) +std::ostream & nano::operator<< (std::ostream & os, const nano::uint256_union & val) { - // TODO: Replace with streaming implementation - os << val.to_string (); + val.encode_hex (os); return os; } -std::ostream & nano::operator<< (std::ostream & os, const uint512_union & val) +std::ostream & nano::operator<< (std::ostream & os, const nano::uint512_union & val) { - // TODO: Replace with streaming implementation - os << val.to_string (); + val.encode_hex (os); return os; } -std::ostream & nano::operator<< (std::ostream & os, const hash_or_account & val) +std::ostream & nano::operator<< (std::ostream & os, const nano::hash_or_account & val) { - // TODO: Replace with streaming implementation - os << val.to_string (); + val.raw.encode_hex (os); return os; } +std::ostream & nano::operator<< (std::ostream & os, const nano::account & val) +{ + val.encode_account (os); + return os; +} + +/* + * + */ + #ifdef _WIN32 #pragma warning(push) #pragma warning(disable : 4146) // warning C4146: unary minus operator applied to unsigned type, result still unsigned diff --git a/nano/lib/numbers.hpp b/nano/lib/numbers.hpp index 716046001e..5702413c13 100644 --- a/nano/lib/numbers.hpp +++ b/nano/lib/numbers.hpp @@ -49,9 +49,9 @@ class uint128_union */ explicit uint128_union (std::string const &); - void encode_hex (std::string &) const; + void encode_hex (std::ostream &) const; bool decode_hex (std::string const &); - void encode_dec (std::string &) const; + void encode_dec (std::ostream &) const; bool decode_dec (std::string const &, bool = false); bool decode_dec (std::string const &, nano::uint128_t); @@ -151,9 +151,9 @@ class uint256_union uint256_union & operator^= (uint256_union const &); uint256_union operator^ (uint256_union const &) const; - void encode_hex (std::string &) const; + void encode_hex (std::ostream &) const; bool decode_hex (std::string const &); - void encode_dec (std::string &) const; + void encode_dec (std::ostream &) const; bool decode_dec (std::string const &); void clear () @@ -173,6 +173,7 @@ class uint256_union } std::string to_string () const; + std::string to_string_dec () const; public: union @@ -236,7 +237,7 @@ class public_key final : public uint256_union static const public_key & null (); bool decode_node_id (std::string const &); - void encode_account (std::string &) const; + void encode_account (std::ostream &) const; bool decode_account (std::string const &); std::string to_node_id () const; @@ -427,7 +428,7 @@ class uint512_union return *this; } - void encode_hex (std::string &) const; + void encode_hex (std::ostream &) const; bool decode_hex (std::string const &); void clear () @@ -519,6 +520,7 @@ std::ostream & operator<< (std::ostream &, const uint128_union &); std::ostream & operator<< (std::ostream &, const uint256_union &); std::ostream & operator<< (std::ostream &, const uint512_union &); std::ostream & operator<< (std::ostream &, const hash_or_account &); +std::ostream & operator<< (std::ostream &, const account &); /** * Convert a double to string in fixed format @@ -615,42 +617,3 @@ struct hash<::nano::uint512_union>; template <> struct hash<::nano::qualified_root>; } - -/* - * Formatters - */ - -template <> -struct fmt::formatter : fmt::ostream_formatter -{ -}; - -template <> -struct fmt::formatter : fmt::ostream_formatter -{ -}; - -template <> -struct fmt::formatter : fmt::ostream_formatter -{ -}; - -template <> -struct fmt::formatter : fmt::ostream_formatter -{ -}; - -template <> -struct fmt::formatter : fmt::formatter -{ -}; - -template <> -struct fmt::formatter : fmt::formatter -{ -}; - -template <> -struct fmt::formatter : fmt::formatter -{ -}; diff --git a/nano/lib/walletconfig.cpp b/nano/lib/walletconfig.cpp index 885bd54936..67062d877b 100644 --- a/nano/lib/walletconfig.cpp +++ b/nano/lib/walletconfig.cpp @@ -24,10 +24,7 @@ nano::error nano::wallet_config::parse (std::string const & wallet_a, std::strin nano::error nano::wallet_config::serialize_toml (nano::tomlconfig & toml) const { - std::string wallet_string; - wallet.encode_hex (wallet_string); - - toml.put ("wallet", wallet_string, "Wallet identifier\ntype:string,hex"); + toml.put ("wallet", wallet.to_string (), "Wallet identifier\ntype:string,hex"); toml.put ("account", account.to_account (), "Current wallet account\ntype:string,account"); return toml.get_error (); } diff --git a/nano/nano_node/entry.cpp b/nano/nano_node/entry.cpp index b2aa9d1393..11898a9d03 100644 --- a/nano/nano_node/entry.cpp +++ b/nano/nano_node/entry.cpp @@ -446,8 +446,7 @@ int main (int argc, char * const * argv) using time_point = std::chrono::system_clock::time_point; time_point ts (std::chrono::duration_cast (std::chrono::nanoseconds (i->first))); std::time_t timestamp = std::chrono::system_clock::to_time_t (ts); - std::string weight; - i->second.encode_dec (weight); + std::string weight = i->second.to_string_dec (); std::cout << boost::str (boost::format ("Timestamp %1% Weight %2%\n") % ctime (×tamp) % weight); } } diff --git a/nano/node/active_elections.cpp b/nano/node/active_elections.cpp index 5bd27fdc58..bf099c4f86 100644 --- a/nano/node/active_elections.cpp +++ b/nano/node/active_elections.cpp @@ -440,7 +440,7 @@ nano::election_insertion_result nano::active_elections::insert (std::shared_ptr< nano::log::arg{ "election", result.election }); node.logger.debug (nano::log::type::active_elections, "Started new election for block: {} (behavior: {}, active immediately: {})", - hash.to_string (), + hash, to_string (election_behavior_a), activate_immediately); } @@ -578,7 +578,7 @@ bool nano::active_elections::publish (std::shared_ptr const & block node.vote_cache_processor.trigger (block_a->hash ()); node.stats.inc (nano::stat::type::active, nano::stat::detail::election_block_conflict); - node.logger.debug (nano::log::type::active_elections, "Block was added to an existing election: {}", block_a->hash ().to_string ()); + node.logger.debug (nano::log::type::active_elections, "Block was added to an existing election: {}", block_a->hash ()); } } return result; diff --git a/nano/node/bootstrap/bootstrap_service.cpp b/nano/node/bootstrap/bootstrap_service.cpp index 2e8bd74253..e69b3d5c25 100644 --- a/nano/node/bootstrap/bootstrap_service.cpp +++ b/nano/node/bootstrap/bootstrap_service.cpp @@ -542,8 +542,8 @@ bool nano::bootstrap_service::request (nano::account account, size_t count, std: tag.hash = info->head; logger.debug (nano::log::type::bootstrap, "Requesting blocks for {} starting from account frontier: {} (optimistic: {})", - account.to_account (), // TODO: Lazy eval - tag.start.to_string (), // TODO: Lazy eval + account, + tag.start, optimistic_reuest); } else // Pessimistic (safe) request case @@ -557,8 +557,8 @@ bool nano::bootstrap_service::request (nano::account account, size_t count, std: tag.hash = conf_info->height; logger.debug (nano::log::type::bootstrap, "Requesting blocks for {} starting from confirmation frontier: {} (optimistic: {})", - account.to_account (), // TODO: Lazy eval - tag.start.to_string (), // TODO: Lazy eval + account, + tag.start, optimistic_reuest); } else @@ -567,7 +567,7 @@ bool nano::bootstrap_service::request (nano::account account, size_t count, std: tag.start = account; logger.debug (nano::log::type::bootstrap, "Requesting blocks for {} starting from account root (optimistic: {})", - account.to_account (), // TODO: Lazy eval + account, optimistic_reuest); } } @@ -579,7 +579,7 @@ bool nano::bootstrap_service::request (nano::account account, size_t count, std: tag.type = query_type::blocks_by_account; tag.start = account; - logger.debug (nano::log::type::bootstrap, "Requesting blocks for {}", account.to_account ()); // TODO: Lazy eval + logger.debug (nano::log::type::bootstrap, "Requesting blocks for {}", account); } } @@ -594,7 +594,7 @@ bool nano::bootstrap_service::request_info (nano::block_hash hash, std::shared_p tag.start = hash; tag.hash = hash; - logger.debug (nano::log::type::bootstrap, "Requesting account info for: {}", hash.to_string ()); // TODO: Lazy eval + logger.debug (nano::log::type::bootstrap, "Requesting account info for: {}", hash); return send (channel, tag); } @@ -606,7 +606,7 @@ bool nano::bootstrap_service::request_frontiers (nano::account start, std::share tag.source = source; tag.start = start; - logger.debug (nano::log::type::bootstrap, "Requesting frontiers starting from: {}", start.to_account ()); // TODO: Lazy eval + logger.debug (nano::log::type::bootstrap, "Requesting frontiers starting from: {}", start); return send (channel, tag); } diff --git a/nano/node/bounded_backlog.cpp b/nano/node/bounded_backlog.cpp index 8f9e9f8337..41ec172103 100644 --- a/nano/node/bounded_backlog.cpp +++ b/nano/node/bounded_backlog.cpp @@ -292,7 +292,7 @@ std::deque nano::bounded_backlog::perform_rollbacks (std::dequ // Here we check that the block is still OK to rollback, there could be a delay between gathering the targets and performing the rollbacks if (auto block = ledger.any.block_get (transaction, hash)) { - logger.debug (nano::log::type::bounded_backlog, "Rolling back: {}, account: {}", hash.to_string (), block->account ().to_account ()); + logger.debug (nano::log::type::bounded_backlog, "Rolling back: {}, account: {}", hash, block->account ()); std::deque> rollback_list; bool error = ledger.rollback (transaction, hash, rollback_list); diff --git a/nano/node/confirming_set.cpp b/nano/node/confirming_set.cpp index e08082e5d8..2347dc9333 100644 --- a/nano/node/confirming_set.cpp +++ b/nano/node/confirming_set.cpp @@ -263,12 +263,12 @@ void nano::confirming_set::run_batch (std::unique_lock & lock) if (success) { stats.inc (nano::stat::type::confirming_set, nano::stat::detail::cemented_hash); - logger.debug (nano::log::type::confirming_set, "Cemented block: {} (total cemented: {})", hash.to_string (), cemented_count); + logger.debug (nano::log::type::confirming_set, "Cemented block: {} (total cemented: {})", hash, cemented_count); } else { stats.inc (nano::stat::type::confirming_set, nano::stat::detail::cementing_failed); - logger.debug (nano::log::type::confirming_set, "Failed to cement block: {}", hash.to_string ()); + logger.debug (nano::log::type::confirming_set, "Failed to cement block: {}", hash); // Requeue failed blocks for processing later // Add them to the deferred set while still holding the exclusive database write transaction to avoid block processor races diff --git a/nano/node/distributed_work.cpp b/nano/node/distributed_work.cpp index a7cb40598e..aa9498375d 100644 --- a/nano/node/distributed_work.cpp +++ b/nano/node/distributed_work.cpp @@ -96,7 +96,8 @@ void nano::distributed_work::start () } else { - this_l->node.logger.error (nano::log::type::distributed_work, "Error resolving work peer: {}:{} ({})", peer.first, peer.second, ec.message ()); + this_l->node.logger.error (nano::log::type::distributed_work, "Error resolving work peer: {}:{} ({})", + peer.first, peer.second, ec.message ()); this_l->failure (); } @@ -169,9 +170,8 @@ void nano::distributed_work::do_request (nano::tcp_endpoint const & endpoint_a) } else if (ec) { - this_l->node.logger.error (nano::log::type::distributed_work, "Work peer responded with an error {}:{} ({})", - nano::util::to_str (connection->endpoint.address ()), - connection->endpoint.port (), + this_l->node.logger.error (nano::log::type::distributed_work, "Work peer responded with an error {} ({})", + connection->endpoint, ec.message ()); this_l->add_bad_peer (connection->endpoint); @@ -187,9 +187,8 @@ void nano::distributed_work::do_request (nano::tcp_endpoint const & endpoint_a) } else if (ec && ec != boost::system::errc::operation_canceled) { - this_l->node.logger.error (nano::log::type::distributed_work, "Unable to write to work peer {}:{} ({})", - nano::util::to_str (connection->endpoint.address ()), - connection->endpoint.port (), + this_l->node.logger.error (nano::log::type::distributed_work, "Unable to write to work peer {} ({})", + connection->endpoint, ec.message ()); this_l->add_bad_peer (connection->endpoint); @@ -199,9 +198,8 @@ void nano::distributed_work::do_request (nano::tcp_endpoint const & endpoint_a) } else if (ec && ec != boost::system::errc::operation_canceled) { - this_l->node.logger.error (nano::log::type::distributed_work, "Unable to connect to work peer {}:{} ({})", - nano::util::to_str (connection->endpoint.address ()), - connection->endpoint.port (), + this_l->node.logger.error (nano::log::type::distributed_work, "Unable to connect to work peer {} ({})", + connection->endpoint, ec.message ()); this_l->add_bad_peer (connection->endpoint); @@ -234,9 +232,8 @@ void nano::distributed_work::do_cancel (nano::tcp_endpoint const & endpoint_a) [this_l, peer_cancel, cancelling_l] (boost::system::error_code const & ec, std::size_t bytes_transferred) { if (ec && ec != boost::system::errc::operation_canceled) { - this_l->node.logger.error (nano::log::type::distributed_work, "Unable to send work cancel to work peer {}:{} ({})", - nano::util::to_str (cancelling_l->endpoint.address ()), - cancelling_l->endpoint.port (), + this_l->node.logger.error (nano::log::type::distributed_work, "Unable to send work cancel to work peer {} ({})", + cancelling_l->endpoint, ec.message ()); } })); @@ -265,27 +262,24 @@ void nano::distributed_work::success (std::string const & body_a, nano::tcp_endp } else { - node.logger.error (nano::log::type::distributed_work, "Incorrect work response from {}:{} for root {} with difficulty {}: {}", - nano::util::to_str (endpoint_a.address ()), - endpoint_a.port (), - request.root.to_string (), + node.logger.error (nano::log::type::distributed_work, "Incorrect work response from {} for root {} with difficulty {}: {}", + endpoint_a, + request.root, nano::to_string_hex (request.difficulty), work_text); } } else { - node.logger.error (nano::log::type::distributed_work, "Work response from {}:{} wasn't a number: {}", - nano::util::to_str (endpoint_a.address ()), - endpoint_a.port (), + node.logger.error (nano::log::type::distributed_work, "Work response from {} wasn't a number: {}", + endpoint_a, work_text); } } catch (...) { - node.logger.error (nano::log::type::distributed_work, "Work response from {}:{} wasn't parsable: {}", - nano::util::to_str (endpoint_a.address ()), - endpoint_a.port (), + node.logger.error (nano::log::type::distributed_work, "Work response from {} wasn't parsable: {}", + endpoint_a, body_a); } if (error) @@ -319,17 +313,15 @@ void nano::distributed_work::stop_once (bool const local_stop_a) connection_l->socket.close (ec); if (ec) { - this_l->node.logger.error (nano::log::type::distributed_work, "Error closing socket with work peer: {}:{} ({})", - nano::util::to_str (connection_l->endpoint.address ()), - connection_l->endpoint.port (), + this_l->node.logger.error (nano::log::type::distributed_work, "Error closing socket with work peer: {} ({})", + connection_l->endpoint, ec.message ()); } } else { - this_l->node.logger.error (nano::log::type::distributed_work, "Error cancelling operation with work peer: {}:{} ({})", - nano::util::to_str (connection_l->endpoint.address ()), - connection_l->endpoint.port (), + this_l->node.logger.error (nano::log::type::distributed_work, "Error cancelling operation with work peer: {} ({})", + connection_l->endpoint, ec.message ()); } } @@ -347,7 +339,7 @@ void nano::distributed_work::set_once (uint64_t const work_a, std::string const elapsed.stop (); node.logger.info (nano::log::type::distributed_work, "Work generation for {}, with a threshold difficulty of {} (multiplier {}x) complete: {} ms", - request.root.to_string (), + request.root, nano::to_string_hex (request.difficulty), nano::to_string (nano::difficulty::to_multiplier (request.difficulty, node.default_difficulty (request.version)), 2), elapsed.value ().count ()); @@ -369,7 +361,7 @@ void nano::distributed_work::cancel () elapsed.stop (); node.logger.info (nano::log::type::distributed_work, "Work generation for {} was cancelled after {} ms", - request.root.to_string (), + request.root, elapsed.value ().count ()); status = work_generation_status::cancelled; @@ -397,7 +389,7 @@ void nano::distributed_work::handle_failure () if (!local_generation_started && !finished.exchange (true)) { node.logger.info (nano::log::type::distributed_work, "Work peer(s) failed to generate work for root {}, retrying... (backoff: {}s)", - request.root.to_string (), + request.root, backoff.count ()); status = work_generation_status::failure_peers; diff --git a/nano/node/election.cpp b/nano/node/election.cpp index 1f064b62e7..3ee56c1f0b 100644 --- a/nano/node/election.cpp +++ b/nano/node/election.cpp @@ -65,7 +65,7 @@ void nano::election::confirm_once (nano::unique_lock & lock) nano::log::arg{ "status", extended_status }); node.logger.debug (nano::log::type::election, "Election confirmed with winner: {} (behavior: {}, state: {}, voters: {}, blocks: {}, duration: {}ms, confirmation requests: {})", - status_l.winner->hash ().to_string (), + status_l.winner->hash (), to_string (behavior_m), to_string (state_m), extended_status.status.voter_count, @@ -179,7 +179,7 @@ void nano::election::send_confirm_req (nano::confirmation_solicitor & solicitor_ node.stats.inc (nano::stat::type::election, nano::stat::detail::confirmation_request); node.logger.debug (nano::log::type::election, "Sent confirmation request for root: {} (behavior: {}, state: {}, voters: {}, blocks: {}, duration: {}ms, confirmation requests: {})", - qualified_root.to_string (), + qualified_root, to_string (behavior_m), to_string (state_m), status.voter_count, @@ -210,7 +210,7 @@ bool nano::election::transition_priority () node.logger.debug (nano::log::type::election, "Transitioned election behavior to priority from {} for root: {} (duration: {}ms)", to_string (behavior_m), - qualified_root.to_string (), + qualified_root, duration ().count ()); return true; @@ -270,8 +270,8 @@ void nano::election::broadcast_block (nano::confirmation_solicitor & solicitor_a node.stats.inc (nano::stat::type::election, last_block_hash.is_zero () ? nano::stat::detail::broadcast_block_initial : nano::stat::detail::broadcast_block_repeat); node.logger.debug (nano::log::type::election, "Broadcasting current winner: {} for root: {} (behavior: {}, state: {}, voters: {}, blocks: {}, duration: {}ms)", - status.winner->hash ().to_string (), - qualified_root.to_string (), + status.winner->hash (), + qualified_root, to_string (behavior_m), to_string (state_m), status.voter_count, @@ -558,11 +558,11 @@ nano::vote_code nano::election::vote (nano::account const & rep, uint64_t timest nano::log::arg{ "weight", weight }); node.logger.debug (nano::log::type::election, "Vote received for: {} from: {} root: {} (final: {}, weight: {}, source: {})", - block_hash_a.to_string (), - rep.to_account (), - qualified_root.to_string (), + block_hash_a, + rep, + qualified_root, nano::vote::is_final_timestamp (timestamp_a), - weight.convert_to (), + weight, to_string (vote_source_a)); if (!confirmed_locked ()) @@ -839,11 +839,10 @@ bool nano::election::contains (nano::block_hash const & hash) const return last_blocks.contains (hash); } -// TODO: Remove the need for .to_string () calls void nano::election::operator() (nano::object_stream & obs) const { obs.write ("id", id); - obs.write ("qualified_root", qualified_root.to_string ()); + obs.write ("qualified_root", qualified_root); obs.write ("behavior", behavior_m); obs.write ("height", height); obs.write ("status", current_status ()); @@ -851,7 +850,7 @@ void nano::election::operator() (nano::object_stream & obs) const void nano::election_extended_status::operator() (nano::object_stream & obs) const { - obs.write ("winner", status.winner->hash ().to_string ()); + obs.write ("winner", status.winner->hash ()); obs.write ("tally_amount", status.tally.to_string_dec ()); obs.write ("final_tally_amount", status.final_tally.to_string_dec ()); obs.write ("confirmation_request_count", status.confirmation_request_count); @@ -862,8 +861,8 @@ void nano::election_extended_status::operator() (nano::object_stream & obs) cons obs.write_range ("votes", votes, [] (auto const & entry, nano::object_stream & obs) { auto & [account, info] = entry; - obs.write ("account", account.to_account ()); - obs.write ("hash", info.hash.to_string ()); + obs.write ("account", account); + obs.write ("hash", info.hash); obs.write ("final", nano::vote::is_final_timestamp (info.timestamp)); obs.write ("timestamp", info.timestamp); obs.write ("time", info.time.time_since_epoch ().count ()); @@ -876,7 +875,7 @@ void nano::election_extended_status::operator() (nano::object_stream & obs) cons obs.write_range ("tally", tally, [] (auto const & entry, nano::object_stream & obs) { auto & [amount, block] = entry; - obs.write ("hash", block->hash ().to_string ()); + obs.write ("hash", block->hash ()); obs.write ("amount", amount); }); } diff --git a/nano/node/epoch_upgrader.cpp b/nano/node/epoch_upgrader.cpp index 1a44e9f244..751df5d692 100644 --- a/nano/node/epoch_upgrader.cpp +++ b/nano/node/epoch_upgrader.cpp @@ -65,7 +65,7 @@ void nano::epoch_upgrader::upgrade_impl (nano::raw_key const & prv_a, nano::epoc bool fork (result == nano::block_status::fork); logger.error (nano::log::type::epoch_upgrader, "Failed to upgrade account {} (valid signature: {}, valid work: {}, fork: {})", - account_a.to_account (), + account_a, valid_signature, valid_work, fork); diff --git a/nano/node/ipc/flatbuffers_util.cpp b/nano/node/ipc/flatbuffers_util.cpp index c4d3a0355f..0be70f20b3 100644 --- a/nano/node/ipc/flatbuffers_util.cpp +++ b/nano/node/ipc/flatbuffers_util.cpp @@ -14,7 +14,7 @@ std::unique_ptr nano::ipc::flatbuffers_builder::from (nano block->balance = block_a.balance ().to_string_dec (); block->link = block_a.link_field ().value ().to_string (); block->link_as_account = block_a.link_field ().value ().to_account (); - block_a.signature.encode_hex (block->signature); + block->signature = block_a.signature.to_string (); block->work = nano::to_string_hex (block_a.work); if (is_state_send_a) @@ -43,7 +43,7 @@ std::unique_ptr nano::ipc::flatbuffers_builder::from (nano: block->balance = block_a.balance ().to_string_dec (); block->destination = block_a.hashables.destination.to_account (); block->previous = block_a.previous ().to_string (); - block_a.signature.encode_hex (block->signature); + block->signature = block_a.signature.to_string (); block->work = nano::to_string_hex (block_a.work); return block; } @@ -54,7 +54,7 @@ std::unique_ptr nano::ipc::flatbuffers_builder::from (na block->hash = block_a.hash ().to_string (); block->source = block_a.source_field ().value ().to_string (); block->previous = block_a.previous ().to_string (); - block_a.signature.encode_hex (block->signature); + block->signature = block_a.signature.to_string (); block->work = nano::to_string_hex (block_a.work); return block; } @@ -66,7 +66,7 @@ std::unique_ptr nano::ipc::flatbuffers_builder::from (nano: block->source = block_a.source_field ().value ().to_string (); block->account = block_a.account ().to_account (); block->representative = block_a.representative_field ().value ().to_account (); - block_a.signature.encode_hex (block->signature); + block->signature = block_a.signature.to_string (); block->work = nano::to_string_hex (block_a.work); return block; } @@ -77,7 +77,7 @@ std::unique_ptr nano::ipc::flatbuffers_builder::from (nan block->hash = block_a.hash ().to_string (); block->previous = block_a.previous ().to_string (); block->representative = block_a.representative_field ().value ().to_account (); - block_a.signature.encode_hex (block->signature); + block->signature = block_a.signature.to_string (); block->work = nano::to_string_hex (block_a.work); return block; } diff --git a/nano/node/json_handler.cpp b/nano/node/json_handler.cpp index fcdca6a24c..850062d9f9 100644 --- a/nano/node/json_handler.cpp +++ b/nano/node/json_handler.cpp @@ -618,8 +618,7 @@ void nano::json_handler::account_info () response_l.put ("open_block", info.open_block.to_string ()); response_l.put ("representative_block", node.ledger.representative (transaction, info.head).to_string ()); nano::amount balance_l (info.balance); - std::string balance; - balance_l.encode_dec (balance); + std::string balance = balance_l.to_string_dec (); response_l.put ("balance", balance); @@ -635,8 +634,7 @@ void nano::json_handler::account_info () // block_height and confirmed height are the same, so can just reuse balance confirmed_balance_l = balance_l; } - std::string confirmed_balance; - confirmed_balance_l.encode_dec (confirmed_balance); + std::string confirmed_balance = confirmed_balance_l.to_string_dec (); response_l.put ("confirmed_balance", confirmed_balance); } @@ -2181,8 +2179,7 @@ void nano::json_handler::delegators () { if (info.balance.number () >= threshold.number ()) { - std::string balance; - nano::uint128_union (info.balance).encode_dec (balance); + std::string balance = nano::uint128_union (info.balance).to_string_dec (); nano::account const & delegator (i->first); delegators.put (delegator.to_account (), balance); } @@ -2734,8 +2731,7 @@ void nano::json_handler::ledger () response_a.put ("frontier", info.head.to_string ()); response_a.put ("open_block", info.open_block.to_string ()); response_a.put ("representative_block", node.ledger.representative (transaction, info.head).to_string ()); - std::string balance; - nano::uint128_union (info.balance).encode_dec (balance); + std::string balance = nano::uint128_union (info.balance).to_string_dec (); response_a.put ("balance", balance); response_a.put ("modified_timestamp", std::to_string (info.modified)); response_a.put ("block_count", std::to_string (info.block_count)); @@ -2787,8 +2783,7 @@ void nano::json_handler::ledger () response_a.put ("frontier", info.head.to_string ()); response_a.put ("open_block", info.open_block.to_string ()); response_a.put ("representative_block", node.ledger.representative (transaction, info.head).to_string ()); - std::string balance; - (i->first).encode_dec (balance); + std::string balance = (i->first).to_string_dec (); response_a.put ("balance", balance); response_a.put ("modified_timestamp", std::to_string (info.modified)); response_a.put ("block_count", std::to_string (info.block_count)); @@ -4650,8 +4645,7 @@ void nano::json_handler::wallet_ledger () entry.put ("frontier", info->head.to_string ()); entry.put ("open_block", info->open_block.to_string ()); entry.put ("representative_block", node.ledger.representative (block_transaction, info->head).to_string ()); - std::string balance; - nano::uint128_union (info->balance).encode_dec (balance); + std::string balance = nano::uint128_union (info->balance).to_string_dec (); entry.put ("balance", balance); entry.put ("modified_timestamp", std::to_string (info->modified)); entry.put ("block_count", std::to_string (info->block_count)); diff --git a/nano/node/local_block_broadcaster.cpp b/nano/node/local_block_broadcaster.cpp index 10acde6261..6b17d63039 100644 --- a/nano/node/local_block_broadcaster.cpp +++ b/nano/node/local_block_broadcaster.cpp @@ -192,7 +192,7 @@ void nano::local_block_broadcaster::run_broadcasts (nano::unique_lockhash ().to_string (), + entry.block->hash (), entry.rebroadcasts); stats.inc (nano::stat::type::local_block_broadcaster, nano::stat::detail::broadcast, nano::stat::dir::out); diff --git a/nano/node/network.cpp b/nano/node/network.cpp index 12ee9718d6..57c429c6b8 100644 --- a/nano/node/network.cpp +++ b/nano/node/network.cpp @@ -357,12 +357,12 @@ bool nano::network::merge_peer (nano::endpoint const & peer) if (track_reachout (peer)) { node.stats.inc (nano::stat::type::network, nano::stat::detail::merge_peer); - node.logger.debug (nano::log::type::network, "Initiating peer merge: {}", fmt::streamed (peer)); + node.logger.debug (nano::log::type::network, "Initiating peer merge: {}", peer); bool started = tcp_channels.start_tcp (peer); if (!started) { node.stats.inc (nano::stat::type::tcp, nano::stat::detail::merge_peer_failed); - node.logger.debug (nano::log::type::network, "Peer merge failed: {}", fmt::streamed (peer)); + node.logger.debug (nano::log::type::network, "Peer merge failed: {}", peer); } return started; } diff --git a/nano/node/node.cpp b/nano/node/node.cpp index 114b46b05f..187ece9ad6 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -471,7 +471,7 @@ void nano::node::process_active (std::shared_ptr const & incoming) [[nodiscard]] nano::block_status nano::node::process (secure::write_transaction const & transaction, std::shared_ptr block) { auto status = ledger.process (transaction, block); - logger.debug (nano::log::type::node, "Directly processed block: {} (status: {})", block->hash ().to_string (), to_string (status)); + logger.debug (nano::log::type::node, "Directly processed block: {} (status: {})", block->hash (), to_string (status)); return status; } diff --git a/nano/node/online_reps.cpp b/nano/node/online_reps.cpp index 1de0e27c2a..ea1494145d 100644 --- a/nano/node/online_reps.cpp +++ b/nano/node/online_reps.cpp @@ -32,7 +32,7 @@ void nano::online_reps::start () nano::lock_guard lock{ mutex }; cached_trended = trended_l; - logger.info (nano::log::type::online_reps, "Initial trended weight: {}", fmt::streamed (cached_trended)); + logger.info (nano::log::type::online_reps, "Initial trended weight: {}", cached_trended); } thread = std::thread ([this] () { @@ -125,7 +125,7 @@ void nano::online_reps::sample () nano::lock_guard lock{ mutex }; cached_trended = trended_l; } - logger.info (nano::log::type::online_reps, "Updated trended weight: {}", fmt::streamed (trended_l)); + logger.info (nano::log::type::online_reps, "Updated trended weight: {}", trended_l); } nano::uint128_t nano::online_reps::calculate_online () const diff --git a/nano/node/peer_history.cpp b/nano/node/peer_history.cpp index 0065a0057a..8307df3f61 100644 --- a/nano/node/peer_history.cpp +++ b/nano/node/peer_history.cpp @@ -92,7 +92,7 @@ void nano::peer_history::run_one () if (!exists) { stats.inc (nano::stat::type::peer_history, nano::stat::detail::inserted); - logger.debug (nano::log::type::peer_history, "Saved new peer: {}", fmt::streamed (endpoint)); + logger.debug (nano::log::type::peer_history, "Saved new peer: {}", endpoint); } else { @@ -116,7 +116,7 @@ void nano::peer_history::run_one () stats.inc (nano::stat::type::peer_history, nano::stat::detail::erased); logger.debug (nano::log::type::peer_history, "Erased peer: {} (not seen for {}s)", - fmt::streamed (endpoint.endpoint ()), + endpoint.endpoint (), nano::log::seconds_delta (timestamp)); } } diff --git a/nano/node/repcrawler.cpp b/nano/node/repcrawler.cpp index 18523cc951..88589a1106 100644 --- a/nano/node/repcrawler.cpp +++ b/nano/node/repcrawler.cpp @@ -91,8 +91,8 @@ void nano::rep_crawler::validate_and_process (nano::unique_lock & l if (rep_weight < minimum) { logger.debug (nano::log::type::rep_crawler, "Ignoring vote from account: {} with too little voting weight: {}", - vote->account.to_account (), - fmt::streamed (rep_weight)); + vote->account, + rep_weight); continue; // Skip this vote } @@ -220,8 +220,8 @@ void nano::rep_crawler::cleanup () erase_if (reps, [this] (rep_entry const & rep) { if (!rep.channel->alive ()) { - logger.info (nano::log::type::rep_crawler, "Evicting representative: {} with dead channel at: {}", rep.account.to_account (), rep.channel->to_string ()); stats.inc (nano::stat::type::rep_crawler, nano::stat::detail::channel_dead); + logger.info (nano::log::type::rep_crawler, "Evicting representative: {} with dead channel at: {}", rep.account, rep.channel->to_string ()); return true; // Erase } return false; @@ -233,13 +233,13 @@ void nano::rep_crawler::cleanup () { if (query.replies == 0) { - logger.debug (nano::log::type::rep_crawler, "Aborting unresponsive query for block: {} from: {}", query.hash.to_string (), query.channel->to_string ()); stats.inc (nano::stat::type::rep_crawler, nano::stat::detail::query_timeout); + logger.debug (nano::log::type::rep_crawler, "Aborting unresponsive query for block: {} from: {}", query.hash, query.channel->to_string ()); } else { - logger.debug (nano::log::type::rep_crawler, "Completion of query with: {} replies for block: {} from: {}", query.replies, query.hash.to_string (), query.channel->to_string ()); stats.inc (nano::stat::type::rep_crawler, nano::stat::detail::query_completion); + logger.debug (nano::log::type::rep_crawler, "Completion of query with: {} replies for block: {} from: {}", query.replies, query.hash, query.channel->to_string ()); } return true; // Erase } @@ -345,8 +345,8 @@ void nano::rep_crawler::query (std::dequeto_string ()); stats.inc (nano::stat::type::rep_crawler, nano::stat::detail::query_sent); + logger.debug (nano::log::type::rep_crawler, "Sending query for block: {} to: {}", hash_root.first, channel->to_string ()); auto const & [hash, root] = hash_root; nano::confirm_req req{ network_constants, hash, root }; @@ -357,8 +357,8 @@ void nano::rep_crawler::query (std::dequeto_string ()); stats.inc (nano::stat::type::rep_crawler, nano::stat::detail::query_duplicate); + logger.debug (nano::log::type::rep_crawler, "Ignoring duplicate query for block: {} to: {}", hash_root.first, channel->to_string ()); } } } @@ -393,8 +393,8 @@ bool nano::rep_crawler::process (std::shared_ptr const & vote, std:: }); if (found) { - logger.debug (nano::log::type::rep_crawler, "Processing response for block: {} from: {}", target_hash.to_string (), channel->to_string ()); stats.inc (nano::stat::type::rep_crawler, nano::stat::detail::response); + logger.debug (nano::log::type::rep_crawler, "Processing response for block: {} from: {}", target_hash, channel->to_string ()); // Track response time stats.sample (nano::stat::sample::rep_response_time, nano::log::milliseconds_delta (it->time), { 0, config.query_timeout.count () }); diff --git a/nano/node/request_aggregator.cpp b/nano/node/request_aggregator.cpp index ab84cc60ce..c59894bc59 100644 --- a/nano/node/request_aggregator.cpp +++ b/nano/node/request_aggregator.cpp @@ -253,19 +253,18 @@ auto nano::request_aggregator::aggregate (nano::secure::transaction const & tran if (should_generate_final_vote (block)) { to_generate_final.push_back (block); + stats.inc (nano::stat::type::requests, nano::stat::detail::requests_final); logger.debug (nano::log::type::request_aggregator, "Replying with final vote for: {} to: {}", - block->hash ().to_string (), // TODO: Lazy eval - channel_a->to_string ()); // TODO: Lazy eval + block->hash (), channel_a->to_string ()); // TODO: Lazy eval } else { stats.inc (nano::stat::type::requests, nano::stat::detail::requests_non_final); logger.debug (nano::log::type::request_aggregator, "Skipping reply with normal vote for: {} (requested by: {})", - block->hash ().to_string (), // TODO: Lazy eval - channel_a->to_string ()); // TODO: Lazy eval + block->hash (), channel_a->to_string ()); // TODO: Lazy eval } } else @@ -273,9 +272,7 @@ auto nano::request_aggregator::aggregate (nano::secure::transaction const & tran stats.inc (nano::stat::type::requests, nano::stat::detail::requests_unknown); logger.debug (nano::log::type::request_aggregator, "Cannot reply, block not found: {} with root: {} (requested by: {})", - hash.to_string (), // TODO: Lazy eval - root.to_string (), // TODO: Lazy eval - channel_a->to_string ()); // TODO: Lazy eval + hash, root, channel_a->to_string ()); // TODO: Lazy eval } } diff --git a/nano/node/scheduler/priority.cpp b/nano/node/scheduler/priority.cpp index 14d83af51d..61762a277e 100644 --- a/nano/node/scheduler/priority.cpp +++ b/nano/node/scheduler/priority.cpp @@ -135,7 +135,7 @@ bool nano::scheduler::priority::activate (secure::transaction const & transactio { stats.inc (nano::stat::type::election_scheduler, nano::stat::detail::activated); logger.trace (nano::log::type::election_scheduler, nano::log::detail::block_activated, - nano::log::arg{ "account", account.to_account () }, // TODO: Convert to lazy eval + nano::log::arg{ "account", account }, nano::log::arg{ "block", block }, nano::log::arg{ "time", account_info.modified }, nano::log::arg{ "priority_balance", priority_balance }, diff --git a/nano/node/transport/tcp_channels.cpp b/nano/node/transport/tcp_channels.cpp index 62cc25b65b..9d2660a29f 100644 --- a/nano/node/transport/tcp_channels.cpp +++ b/nano/node/transport/tcp_channels.cpp @@ -56,7 +56,7 @@ bool nano::transport::tcp_channels::check (const nano::tcp_endpoint & endpoint, if (node.network.not_a_peer (nano::transport::map_tcp_to_endpoint (endpoint), node.config.allow_local_peers)) { node.stats.inc (nano::stat::type::tcp_channels_rejected, nano::stat::detail::not_a_peer); - node.logger.debug (nano::log::type::tcp_channels, "Rejected invalid endpoint channel: {}", fmt::streamed (endpoint)); + node.logger.debug (nano::log::type::tcp_channels, "Rejected invalid endpoint channel: {}", endpoint); return false; // Reject } @@ -76,7 +76,7 @@ bool nano::transport::tcp_channels::check (const nano::tcp_endpoint & endpoint, if (has_duplicate) { node.stats.inc (nano::stat::type::tcp_channels_rejected, nano::stat::detail::channel_duplicate); - node.logger.debug (nano::log::type::tcp_channels, "Rejected duplicate channel: {} ({})", fmt::streamed (endpoint), node_id.to_node_id ()); + node.logger.debug (nano::log::type::tcp_channels, "Rejected duplicate channel: {} ({})", endpoint, node_id.to_node_id ()); return false; // Reject } @@ -100,7 +100,7 @@ std::shared_ptr nano::transport::tcp_channels::cre if (!check (endpoint, node_id)) { node.stats.inc (nano::stat::type::tcp_channels, nano::stat::detail::channel_rejected); - node.logger.debug (nano::log::type::tcp_channels, "Rejected channel: {} ({})", fmt::streamed (endpoint), node_id.to_node_id ()); + node.logger.debug (nano::log::type::tcp_channels, "Rejected channel: {} ({})", endpoint, node_id.to_node_id ()); // Rejection reason should be logged earlier return nullptr; @@ -108,7 +108,7 @@ std::shared_ptr nano::transport::tcp_channels::cre node.stats.inc (nano::stat::type::tcp_channels, nano::stat::detail::channel_accepted); node.logger.debug (nano::log::type::tcp_channels, "Accepted channel: {} ({}) ({})", - fmt::streamed (socket->remote_endpoint ()), + socket->remote_endpoint (), to_string (socket->endpoint_type ()), node_id.to_node_id ()); diff --git a/nano/node/transport/tcp_listener.cpp b/nano/node/transport/tcp_listener.cpp index e666b2dd6d..cf5d03c396 100644 --- a/nano/node/transport/tcp_listener.cpp +++ b/nano/node/transport/tcp_listener.cpp @@ -58,7 +58,7 @@ void nano::transport::tcp_listener::start () local = acceptor.local_endpoint (); } - logger.debug (nano::log::type::tcp_listener, "Listening for incoming connections on: {}", fmt::streamed (acceptor.local_endpoint ())); + logger.debug (nano::log::type::tcp_listener, "Listening for incoming connections on: {}", acceptor.local_endpoint ()); } catch (boost::system::system_error const & ex) { @@ -186,7 +186,7 @@ void nano::transport::tcp_listener::cleanup () if (connection.socket.expired () && connection.server.expired ()) { stats.inc (nano::stat::type::tcp_listener, nano::stat::detail::erase_dead); - logger.debug (nano::log::type::tcp_listener, "Evicting dead connection: {}", fmt::streamed (connection.endpoint)); + logger.debug (nano::log::type::tcp_listener, "Evicting dead connection: {}", connection.endpoint); return true; } else @@ -216,7 +216,7 @@ void nano::transport::tcp_listener::timeout () stats.inc (nano::stat::type::tcp_listener, nano::stat::detail::attempt_timeout); logger.debug (nano::log::type::tcp_listener, "Connection attempt timed out: {} (started {}s ago)", - fmt::streamed (attempt.endpoint), nano::log::seconds_delta (attempt.start)); + attempt.endpoint, nano::log::seconds_delta (attempt.start)); } } } @@ -239,7 +239,7 @@ bool nano::transport::tcp_listener::connect (asio::ip::address ip, uint16_t port { stats.inc (nano::stat::type::tcp_listener_rejected, nano::stat::detail::max_attempts, nano::stat::dir::out); logger.debug (nano::log::type::tcp_listener, "Max connection attempts reached ({}), rejected connection attempt: {}", - count, ip.to_string ()); + count, ip); return false; // Rejected } @@ -248,7 +248,7 @@ bool nano::transport::tcp_listener::connect (asio::ip::address ip, uint16_t port { stats.inc (nano::stat::type::tcp_listener_rejected, nano::stat::detail::max_attempts_per_ip, nano::stat::dir::out); logger.debug (nano::log::type::tcp_listener, "Connection attempt already in progress ({}), rejected connection attempt: {}", - count, ip.to_string ()); + count, ip); return false; // Rejected } @@ -264,7 +264,7 @@ bool nano::transport::tcp_listener::connect (asio::ip::address ip, uint16_t port nano::tcp_endpoint const endpoint{ ip, port }; stats.inc (nano::stat::type::tcp_listener, nano::stat::detail::connect_initiate, nano::stat::dir::out); - logger.debug (nano::log::type::tcp_listener, "Initiating outgoing connection to: {}", fmt::streamed (endpoint)); + logger.debug (nano::log::type::tcp_listener, "Initiating outgoing connection to: {}", endpoint); auto task = nano::async::task (strand, connect_impl (endpoint)); @@ -286,7 +286,7 @@ auto nano::transport::tcp_listener::connect_impl (asio::ip::tcp::endpoint endpoi if (result.result == accept_result::accepted) { stats.inc (nano::stat::type::tcp_listener, nano::stat::detail::connect_success, nano::stat::dir::out); - logger.debug (nano::log::type::tcp_listener, "Successfully connected to: {}", fmt::streamed (endpoint)); + logger.debug (nano::log::type::tcp_listener, "Successfully connected to: {}", endpoint); release_assert (result.server); result.server->initiate_handshake (); @@ -300,7 +300,7 @@ auto nano::transport::tcp_listener::connect_impl (asio::ip::tcp::endpoint endpoi catch (boost::system::system_error const & ex) { stats.inc (nano::stat::type::tcp_listener, nano::stat::detail::connect_error, nano::stat::dir::out); - logger.log (nano::log::level::debug, nano::log::type::tcp_listener, "Error connecting to: {} ({})", fmt::streamed (endpoint), ex.what ()); + logger.log (nano::log::level::debug, nano::log::type::tcp_listener, "Error connecting to: {} ({})", endpoint, ex.what ()); } } @@ -387,7 +387,7 @@ auto nano::transport::tcp_listener::accept_one (asio::ip::tcp::socket raw_socket if (auto result = check_limits (remote_endpoint.address (), type); result != accept_result::accepted) { stats.inc (nano::stat::type::tcp_listener, nano::stat::detail::accept_rejected, to_stat_dir (type)); - logger.debug (nano::log::type::tcp_listener, "Rejected connection from: {} ({})", fmt::streamed (remote_endpoint), to_string (type)); + logger.debug (nano::log::type::tcp_listener, "Rejected connection from: {} ({})", remote_endpoint, to_string (type)); // Rejection reason should be logged earlier try @@ -406,7 +406,7 @@ auto nano::transport::tcp_listener::accept_one (asio::ip::tcp::socket raw_socket } stats.inc (nano::stat::type::tcp_listener, nano::stat::detail::accept_success, to_stat_dir (type)); - logger.debug (nano::log::type::tcp_listener, "Accepted connection: {} ({})", fmt::streamed (remote_endpoint), to_string (type)); + logger.debug (nano::log::type::tcp_listener, "Accepted connection: {} ({})", remote_endpoint, to_string (type)); auto socket = std::make_shared (node, std::move (raw_socket), remote_endpoint, local_endpoint, to_socket_endpoint (type)); auto server = std::make_shared (socket, node.shared (), true); @@ -438,9 +438,7 @@ auto nano::transport::tcp_listener::check_limits (asio::ip::address const & ip, if (node.network.excluded_peers.check (ip)) // true => error { stats.inc (nano::stat::type::tcp_listener_rejected, nano::stat::detail::excluded, to_stat_dir (type)); - logger.debug (nano::log::type::tcp_listener, "Rejected connection from excluded peer: {} ({})", - ip.to_string (), - to_string (type)); + logger.debug (nano::log::type::tcp_listener, "Rejected connection from excluded peer: {} ({})", ip, to_string (type)); return accept_result::rejected; } @@ -451,9 +449,7 @@ auto nano::transport::tcp_listener::check_limits (asio::ip::address const & ip, { stats.inc (nano::stat::type::tcp_listener_rejected, nano::stat::detail::max_per_ip, to_stat_dir (type)); logger.debug (nano::log::type::tcp_listener, "Max connections: {} per IP: {} reached, unable to open a new connection ({})", - count, - ip.to_string (), - to_string (type)); + count, ip, to_string (type)); return accept_result::rejected; } @@ -466,9 +462,7 @@ auto nano::transport::tcp_listener::check_limits (asio::ip::address const & ip, { stats.inc (nano::stat::type::tcp_listener_rejected, nano::stat::detail::max_per_subnetwork, to_stat_dir (type)); logger.debug (nano::log::type::tcp_listener, "Max connections: {} per subnetwork of IP: {} reached, unable to open a new connection ({})", - count, - ip.to_string (), - to_string (type)); + count, ip, to_string (type)); return accept_result::rejected; } @@ -482,7 +476,7 @@ auto nano::transport::tcp_listener::check_limits (asio::ip::address const & ip, { stats.inc (nano::stat::type::tcp_listener_rejected, nano::stat::detail::max_attempts, to_stat_dir (type)); logger.debug (nano::log::type::tcp_listener, "Max inbound connections reached: {}, unable to accept new connection: {}", - count, ip.to_string ()); + count, ip); return accept_result::rejected; } @@ -493,7 +487,7 @@ auto nano::transport::tcp_listener::check_limits (asio::ip::address const & ip, { stats.inc (nano::stat::type::tcp_listener_rejected, nano::stat::detail::max_attempts, to_stat_dir (type)); logger.debug (nano::log::type::tcp_listener, "Max outbound connections reached: {}, unable to initiate new connection: {}", - count, ip.to_string ()); + count, ip); return accept_result::rejected; } diff --git a/nano/node/transport/tcp_server.cpp b/nano/node/transport/tcp_server.cpp index 1097301cb8..251d76ce22 100644 --- a/nano/node/transport/tcp_server.cpp +++ b/nano/node/transport/tcp_server.cpp @@ -33,7 +33,7 @@ nano::transport::tcp_server::~tcp_server () return; } - node->logger.debug (nano::log::type::tcp_server, "Exiting server: {}", fmt::streamed (remote_endpoint)); + node->logger.debug (nano::log::type::tcp_server, "Exiting server: {}", remote_endpoint); stop (); } @@ -53,7 +53,7 @@ void nano::transport::tcp_server::start () return; } - node->logger.debug (nano::log::type::tcp_server, "Starting server: {}", fmt::streamed (remote_endpoint)); + node->logger.debug (nano::log::type::tcp_server, "Starting server: {}", remote_endpoint); receive_message (); } @@ -86,7 +86,7 @@ void nano::transport::tcp_server::receive_message () node->logger.debug (nano::log::type::tcp_server, "Error reading message: {}, status: {} ({})", ec.message (), to_string (this_l->message_deserializer->status), - fmt::streamed (this_l->remote_endpoint)); + this_l->remote_endpoint); this_l->stop (); } @@ -134,7 +134,7 @@ void nano::transport::tcp_server::received_message (std::unique_ptrlogger.debug (nano::log::type::tcp_server, "Error deserializing message: {} ({})", to_string (message_deserializer->status), - fmt::streamed (remote_endpoint)); + remote_endpoint); } break; } @@ -193,7 +193,7 @@ auto nano::transport::tcp_server::process_message (std::unique_ptrstats.inc (nano::stat::type::tcp_server, nano::stat::detail::handshake_abort); - node->logger.debug (nano::log::type::tcp_server, "Aborting handshake: {} ({})", to_string (message->type ()), fmt::streamed (remote_endpoint)); + node->logger.debug (nano::log::type::tcp_server, "Aborting handshake: {} ({})", to_string (message->type ()), remote_endpoint); return process_result::abort; } @@ -212,7 +212,7 @@ auto nano::transport::tcp_server::process_message (std::unique_ptrstats.inc (nano::stat::type::tcp_server, nano::stat::detail::handshake_error); - node->logger.debug (nano::log::type::tcp_server, "Error switching to bootstrap mode: {} ({})", to_string (message->type ()), fmt::streamed (remote_endpoint)); + node->logger.debug (nano::log::type::tcp_server, "Error switching to bootstrap mode: {} ({})", to_string (message->type ()), remote_endpoint); return process_result::abort; // Switch failed, abort } @@ -276,21 +276,21 @@ auto nano::transport::tcp_server::process_handshake (nano::node_id_handshake con if (node->flags.disable_tcp_realtime) { node->stats.inc (nano::stat::type::tcp_server, nano::stat::detail::handshake_error); - node->logger.debug (nano::log::type::tcp_server, "Handshake attempted with disabled realtime mode ({})", fmt::streamed (remote_endpoint)); + node->logger.debug (nano::log::type::tcp_server, "Handshake attempted with disabled realtime mode ({})", remote_endpoint); return handshake_status::abort; } if (!message.query && !message.response) { node->stats.inc (nano::stat::type::tcp_server, nano::stat::detail::handshake_error); - node->logger.debug (nano::log::type::tcp_server, "Invalid handshake message received ({})", fmt::streamed (remote_endpoint)); + node->logger.debug (nano::log::type::tcp_server, "Invalid handshake message received ({})", remote_endpoint); return handshake_status::abort; } if (message.query && handshake_received) // Second handshake message should be a response only { node->stats.inc (nano::stat::type::tcp_server, nano::stat::detail::handshake_error); - node->logger.debug (nano::log::type::tcp_server, "Detected multiple handshake queries ({})", fmt::streamed (remote_endpoint)); + node->logger.debug (nano::log::type::tcp_server, "Detected multiple handshake queries ({})", remote_endpoint); return handshake_status::abort; } @@ -300,7 +300,7 @@ auto nano::transport::tcp_server::process_handshake (nano::node_id_handshake con node->stats.inc (nano::stat::type::tcp_server, nano::stat::detail::node_id_handshake, nano::stat::dir::in); node->logger.debug (nano::log::type::tcp_server, "Handshake message received: {} ({})", message.query ? (message.response ? "query + response" : "query") : (message.response ? "response" : "none"), - fmt::streamed (remote_endpoint)); + remote_endpoint); if (message.query) { @@ -320,7 +320,7 @@ auto nano::transport::tcp_server::process_handshake (nano::node_id_handshake con else { node->stats.inc (nano::stat::type::tcp_server, nano::stat::detail::handshake_error); - node->logger.debug (nano::log::type::tcp_server, "Error switching to realtime mode ({})", fmt::streamed (remote_endpoint)); + node->logger.debug (nano::log::type::tcp_server, "Error switching to realtime mode ({})", remote_endpoint); return handshake_status::abort; } @@ -328,7 +328,7 @@ auto nano::transport::tcp_server::process_handshake (nano::node_id_handshake con else { node->stats.inc (nano::stat::type::tcp_server, nano::stat::detail::handshake_response_invalid); - node->logger.debug (nano::log::type::tcp_server, "Invalid handshake response received ({})", fmt::streamed (remote_endpoint)); + node->logger.debug (nano::log::type::tcp_server, "Invalid handshake response received ({})", remote_endpoint); return handshake_status::abort; } @@ -348,7 +348,7 @@ void nano::transport::tcp_server::initiate_handshake () auto query = node->network.prepare_handshake_query (nano::transport::map_tcp_to_endpoint (remote_endpoint)); nano::node_id_handshake message{ node->network_params.network, query }; - node->logger.debug (nano::log::type::tcp_server, "Initiating handshake query ({})", fmt::streamed (remote_endpoint)); + node->logger.debug (nano::log::type::tcp_server, "Initiating handshake query ({})", remote_endpoint); auto shared_const_buffer = message.to_shared_const_buffer (); socket->async_write (shared_const_buffer, [this_l = shared_from_this ()] (boost::system::error_code const & ec, std::size_t size_a) { @@ -360,7 +360,7 @@ void nano::transport::tcp_server::initiate_handshake () if (ec) { node->stats.inc (nano::stat::type::tcp_server, nano::stat::detail::handshake_network_error); - node->logger.debug (nano::log::type::tcp_server, "Error sending handshake query: {} ({})", ec.message (), fmt::streamed (this_l->remote_endpoint)); + node->logger.debug (nano::log::type::tcp_server, "Error sending handshake query: {} ({})", ec.message (), this_l->remote_endpoint); // Stop invalid handshake this_l->stop (); @@ -385,7 +385,7 @@ void nano::transport::tcp_server::send_handshake_response (nano::node_id_handsha auto own_query = node->network.prepare_handshake_query (nano::transport::map_tcp_to_endpoint (remote_endpoint)); nano::node_id_handshake handshake_response{ node->network_params.network, own_query, response }; - node->logger.debug (nano::log::type::tcp_server, "Responding to handshake ({})", fmt::streamed (remote_endpoint)); + node->logger.debug (nano::log::type::tcp_server, "Responding to handshake ({})", remote_endpoint); auto shared_const_buffer = handshake_response.to_shared_const_buffer (); socket->async_write (shared_const_buffer, [this_l = shared_from_this ()] (boost::system::error_code const & ec, std::size_t size_a) { @@ -397,7 +397,7 @@ void nano::transport::tcp_server::send_handshake_response (nano::node_id_handsha if (ec) { node->stats.inc (nano::stat::type::tcp_server, nano::stat::detail::handshake_network_error); - node->logger.debug (nano::log::type::tcp_server, "Error sending handshake response: {} ({})", ec.message (), fmt::streamed (this_l->remote_endpoint)); + node->logger.debug (nano::log::type::tcp_server, "Error sending handshake response: {} ({})", ec.message (), this_l->remote_endpoint); // Stop invalid handshake this_l->stop (); @@ -551,7 +551,7 @@ void nano::transport::tcp_server::timeout () } if (socket->has_timed_out ()) { - node->logger.debug (nano::log::type::tcp_server, "Closing TCP server due to timeout ({})", fmt::streamed (remote_endpoint)); + node->logger.debug (nano::log::type::tcp_server, "Closing TCP server due to timeout ({})", remote_endpoint); socket->close (); } @@ -600,7 +600,7 @@ bool nano::transport::tcp_server::to_bootstrap_connection () socket->type_set (nano::transport::socket_type::bootstrap); - node->logger.debug (nano::log::type::tcp_server, "Switched to bootstrap mode ({})", fmt::streamed (remote_endpoint)); + node->logger.debug (nano::log::type::tcp_server, "Switched to bootstrap mode ({})", remote_endpoint); return true; } @@ -630,7 +630,7 @@ bool nano::transport::tcp_server::to_realtime_connection (nano::account const & socket->type_set (nano::transport::socket_type::realtime); - node->logger.debug (nano::log::type::tcp_server, "Switched to realtime mode ({})", fmt::streamed (remote_endpoint)); + node->logger.debug (nano::log::type::tcp_server, "Switched to realtime mode ({})", remote_endpoint); return true; } diff --git a/nano/node/transport/tcp_socket.cpp b/nano/node/transport/tcp_socket.cpp index 07bc9a4ec8..d5686c688a 100644 --- a/nano/node/transport/tcp_socket.cpp +++ b/nano/node/transport/tcp_socket.cpp @@ -83,10 +83,7 @@ void nano::transport::tcp_socket::async_connect (nano::tcp_endpoint const & endp boost::system::error_code ec; this_l->local = this_l->raw_socket.local_endpoint (ec); } - - node_l->logger.debug (nano::log::type::tcp_socket, "Successfully connected to: {}, local: {}", - fmt::streamed (this_l->remote), - fmt::streamed (this_l->local)); + node_l->logger.debug (nano::log::type::tcp_socket, "Successfully connected to: {}, local: {}", this_l->remote, this_l->local); } callback (ec); })); @@ -318,7 +315,7 @@ void nano::transport::tcp_socket::ongoing_checkup () if (condition_to_disconnect) { // TODO: Stats - node_l->logger.debug (nano::log::type::tcp_socket, "Socket timeout, closing: {}", fmt::streamed (this_l->remote)); + node_l->logger.debug (nano::log::type::tcp_socket, "Socket timeout, closing: {}", this_l->remote); this_l->timed_out = true; this_l->close (); } @@ -395,13 +392,13 @@ void nano::transport::tcp_socket::close_internal () { node_l->stats.inc (nano::stat::type::socket, nano::stat::detail::error_socket_close); node_l->logger.error (nano::log::type::tcp_socket, "Failed to close socket gracefully: {} ({})", - fmt::streamed (remote), + remote, ec.message ()); } else { // TODO: Stats - node_l->logger.debug (nano::log::type::tcp_socket, "Closed socket: {}", fmt::streamed (remote)); + node_l->logger.debug (nano::log::type::tcp_socket, "Closed socket: {}", remote); } } diff --git a/nano/qt/qt.cpp b/nano/qt/qt.cpp index 84a215c451..78dc738f1c 100644 --- a/nano/qt/qt.cpp +++ b/nano/qt/qt.cpp @@ -1935,11 +1935,9 @@ void nano_qt::advanced_actions::refresh_ledger () QList items; items.push_back (new QStandardItem (QString (i->first.to_account ().c_str ()))); nano::account_info const & info (i->second); - std::string balance; - nano::amount (info.balance.number () / wallet.rendering_ratio).encode_dec (balance); + std::string balance = nano::amount (info.balance.number () / wallet.rendering_ratio).to_string_dec (); items.push_back (new QStandardItem (QString (balance.c_str ()))); - std::string block_hash; - info.head.encode_hex (block_hash); + std::string block_hash = info.head.to_string (); items.push_back (new QStandardItem (QString (block_hash.c_str ()))); ledger_model->appendRow (items); } diff --git a/nano/qt_test/qt.cpp b/nano/qt_test/qt.cpp index dd97b99733..c76f88dd74 100644 --- a/nano/qt_test/qt.cpp +++ b/nano/qt_test/qt.cpp @@ -373,12 +373,9 @@ TEST (wallet, DISABLED_process_block) QTest::mouseClick (wallet->advanced.enter_block, Qt::LeftButton); ASSERT_EQ (wallet->block_entry.window, wallet->main_stack->currentWidget ()); nano::send_block send (latest, key1.pub, 0, nano::dev::genesis_key.prv, nano::dev::genesis_key.pub, *system.work.generate (latest)); - std::string previous; - send.hashables.previous.encode_hex (previous); - std::string balance; - send.hashables.balance.encode_hex (balance); - std::string signature; - send.signature.encode_hex (signature); + std::string previous = send.hashables.previous.to_string (); + std::string balance = send.hashables.balance.to_string (); + std::string signature = send.signature.to_string (); std::string block_json; send.serialize_json (block_json); block_json.erase (std::remove (block_json.begin (), block_json.end (), '\n'), block_json.end ()); diff --git a/nano/rpc/rpc.cpp b/nano/rpc/rpc.cpp index a2c1e33202..fd90ea3e4f 100644 --- a/nano/rpc/rpc.cpp +++ b/nano/rpc/rpc.cpp @@ -45,7 +45,7 @@ void nano::rpc::start () logger.critical (nano::log::type::rpc, "Error while binding for RPC on port: {} ({})", endpoint.port (), ec.message ()); throw std::runtime_error (ec.message ()); } - logger.info (nano::log::type::rpc, "RPC listening address: {}", fmt::streamed (acceptor.local_endpoint ())); + logger.info (nano::log::type::rpc, "RPC listening address: {}", acceptor.local_endpoint ()); acceptor.listen (); accept (); } diff --git a/nano/rpc/rpc_handler.cpp b/nano/rpc/rpc_handler.cpp index 4d4a6f36dc..6ccaa59fb6 100644 --- a/nano/rpc/rpc_handler.cpp +++ b/nano/rpc/rpc_handler.cpp @@ -101,8 +101,7 @@ void nano::rpc_handler::process_request (nano::rpc_handler_request_params const { nano::uint128_union random_id; nano::random_pool::generate_block (random_id.bytes.data (), random_id.bytes.size ()); - std::string random_id_text; - random_id.encode_hex (random_id_text); + std::string random_id_text = random_id.to_string (); request.put ("id", random_id_text); std::stringstream ostream; boost::property_tree::write_json (ostream, request); diff --git a/nano/rpc_test/rpc.cpp b/nano/rpc_test/rpc.cpp index eecaf6430c..57131dfe89 100644 --- a/nano/rpc_test/rpc.cpp +++ b/nano/rpc_test/rpc.cpp @@ -192,8 +192,7 @@ TEST (rpc, wallet_contains) system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv); auto const rpc_ctx = add_rpc (system, node); boost::property_tree::ptree request; - std::string wallet; - node->wallets.items.begin ()->first.encode_hex (wallet); + std::string wallet = node->wallets.items.begin ()->first.to_string (); request.put ("wallet", wallet); request.put ("action", "wallet_contains"); request.put ("account", nano::dev::genesis_key.pub.to_account ()); @@ -208,8 +207,7 @@ TEST (rpc, wallet_doesnt_contain) auto node = add_ipc_enabled_node (system); auto const rpc_ctx = add_rpc (system, node); boost::property_tree::ptree request; - std::string wallet; - node->wallets.items.begin ()->first.encode_hex (wallet); + std::string wallet = node->wallets.items.begin ()->first.to_string (); request.put ("wallet", wallet); request.put ("action", "wallet_contains"); request.put ("account", nano::dev::genesis_key.pub.to_account ()); @@ -236,8 +234,7 @@ TEST (rpc, validate_account_invalid) nano::test::system system; auto node = add_ipc_enabled_node (system); auto const rpc_ctx = add_rpc (system, node); - std::string account; - nano::dev::genesis_key.pub.encode_account (account); + std::string account = nano::dev::genesis_key.pub.to_account (); account[0] ^= 0x1; boost::property_tree::ptree request; request.put ("action", "validate_account_number"); @@ -254,8 +251,7 @@ TEST (rpc, send) system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv); auto const rpc_ctx = add_rpc (system, node); boost::property_tree::ptree request; - std::string wallet; - node->wallets.items.begin ()->first.encode_hex (wallet); + std::string wallet = node->wallets.items.begin ()->first.to_string (); request.put ("wallet", wallet); request.put ("action", "send"); request.put ("source", nano::dev::genesis_key.pub.to_account ()); @@ -277,8 +273,7 @@ TEST (rpc, send_fail) auto node = add_ipc_enabled_node (system); auto const rpc_ctx = add_rpc (system, node); boost::property_tree::ptree request; - std::string wallet; - node->wallets.items.begin ()->first.encode_hex (wallet); + std::string wallet = node->wallets.items.begin ()->first.to_string (); request.put ("wallet", wallet); request.put ("action", "send"); request.put ("source", nano::dev::genesis_key.pub.to_account ()); @@ -295,8 +290,7 @@ TEST (rpc, send_work) system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv); auto const rpc_ctx = add_rpc (system, node); boost::property_tree::ptree request; - std::string wallet; - node->wallets.items.begin ()->first.encode_hex (wallet); + std::string wallet = node->wallets.items.begin ()->first.to_string (); request.put ("wallet", wallet); request.put ("action", "send"); request.put ("source", nano::dev::genesis_key.pub.to_account ()); @@ -324,8 +318,7 @@ TEST (rpc, send_work_disabled) system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv); auto const rpc_ctx = add_rpc (system, node); boost::property_tree::ptree request; - std::string wallet; - node->wallets.items.begin ()->first.encode_hex (wallet); + std::string wallet = node->wallets.items.begin ()->first.to_string (); request.put ("wallet", wallet); request.put ("action", "send"); request.put ("source", nano::dev::genesis_key.pub.to_account ()); @@ -342,8 +335,7 @@ TEST (rpc, send_idempotent) system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv); auto const rpc_ctx = add_rpc (system, node); boost::property_tree::ptree request; - std::string wallet; - node->wallets.items.begin ()->first.encode_hex (wallet); + std::string wallet = node->wallets.items.begin ()->first.to_string (); request.put ("wallet", wallet); request.put ("action", "send"); request.put ("source", nano::dev::genesis_key.pub.to_account ()); @@ -384,8 +376,7 @@ TEST (rpc, send_epoch_2) auto const rpc_ctx = add_rpc (system, node); boost::property_tree::ptree request; - std::string wallet; - node->wallets.items.begin ()->first.encode_hex (wallet); + std::string wallet = node->wallets.items.begin ()->first.to_string (); request.put ("wallet", wallet); request.put ("action", "send"); request.put ("source", nano::dev::genesis_key.pub.to_account ()); @@ -437,11 +428,9 @@ TEST (rpc, wallet_add) auto node = add_ipc_enabled_node (system); auto const rpc_ctx = add_rpc (system, node); nano::keypair key1; - std::string key_text; - key1.prv.encode_hex (key_text); + std::string key_text = key1.prv.to_string (); boost::property_tree::ptree request; - std::string wallet; - node->wallets.items.begin ()->first.encode_hex (wallet); + std::string wallet = node->wallets.items.begin ()->first.to_string (); request.put ("wallet", wallet); request.put ("action", "wallet_add"); request.put ("key", key_text); @@ -457,8 +446,7 @@ TEST (rpc, wallet_password_valid) auto node = add_ipc_enabled_node (system); auto const rpc_ctx = add_rpc (system, node); boost::property_tree::ptree request; - std::string wallet; - node->wallets.items.begin ()->first.encode_hex (wallet); + std::string wallet = node->wallets.items.begin ()->first.to_string (); request.put ("wallet", wallet); request.put ("action", "password_valid"); auto response (wait_response (system, rpc_ctx, request)); @@ -472,8 +460,7 @@ TEST (rpc, wallet_password_change) auto node = add_ipc_enabled_node (system); auto const rpc_ctx = add_rpc (system, node); boost::property_tree::ptree request; - std::string wallet; - node->wallets.items.begin ()->first.encode_hex (wallet); + std::string wallet = node->wallets.items.begin ()->first.to_string (); request.put ("wallet", wallet); request.put ("action", "password_change"); request.put ("password", "test"); @@ -502,8 +489,7 @@ TEST (rpc, wallet_password_enter) system.wallet (0)->store.password.value (password_l); } boost::property_tree::ptree request; - std::string wallet; - node->wallets.items.begin ()->first.encode_hex (wallet); + std::string wallet = node->wallets.items.begin ()->first.to_string (); request.put ("wallet", wallet); request.put ("action", "password_enter"); request.put ("password", ""); @@ -518,8 +504,7 @@ TEST (rpc, wallet_representative) auto node = add_ipc_enabled_node (system); auto const rpc_ctx = add_rpc (system, node); boost::property_tree::ptree request; - std::string wallet; - node->wallets.items.begin ()->first.encode_hex (wallet); + std::string wallet = node->wallets.items.begin ()->first.to_string (); request.put ("wallet", wallet); request.put ("action", "wallet_representative"); auto response (wait_response (system, rpc_ctx, request)); @@ -533,8 +518,7 @@ TEST (rpc, wallet_representative_set) auto node = add_ipc_enabled_node (system); auto const rpc_ctx = add_rpc (system, node); boost::property_tree::ptree request; - std::string wallet; - node->wallets.items.begin ()->first.encode_hex (wallet); + std::string wallet = node->wallets.items.begin ()->first.to_string (); request.put ("wallet", wallet); nano::keypair key; request.put ("action", "wallet_representative_set"); @@ -551,8 +535,7 @@ TEST (rpc, wallet_representative_set_force) system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv); auto const rpc_ctx = add_rpc (system, node); boost::property_tree::ptree request; - std::string wallet; - node->wallets.items.begin ()->first.encode_hex (wallet); + std::string wallet = node->wallets.items.begin ()->first.to_string (); request.put ("wallet", wallet); nano::keypair key; request.put ("action", "wallet_representative_set"); @@ -585,8 +568,7 @@ TEST (rpc, account_list) system.wallet (0)->insert_adhoc (key2.prv); auto const rpc_ctx = add_rpc (system, node); boost::property_tree::ptree request; - std::string wallet; - node->wallets.items.begin ()->first.encode_hex (wallet); + std::string wallet = node->wallets.items.begin ()->first.to_string (); request.put ("wallet", wallet); request.put ("action", "account_list"); auto response (wait_response (system, rpc_ctx, request)); @@ -613,8 +595,7 @@ TEST (rpc, wallet_key_valid) system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv); auto const rpc_ctx = add_rpc (system, node); boost::property_tree::ptree request; - std::string wallet; - node->wallets.items.begin ()->first.encode_hex (wallet); + std::string wallet = node->wallets.items.begin ()->first.to_string (); request.put ("wallet", wallet); request.put ("action", "wallet_key_valid"); auto response (wait_response (system, rpc_ctx, request)); @@ -2468,8 +2449,7 @@ TEST (rpc, account_representative_set_epoch_2_insufficient_work) auto const rpc_ctx = add_rpc (system, node); boost::property_tree::ptree request; - std::string wallet; - node->wallets.items.begin ()->first.encode_hex (wallet); + std::string wallet = node->wallets.items.begin ()->first.to_string (); request.put ("wallet", wallet); request.put ("action", "account_representative_set"); request.put ("account", nano::dev::genesis_key.pub.to_account ()); @@ -3923,8 +3903,7 @@ TEST (rpc, json_block_input) boost::property_tree::ptree request; request.put ("action", "sign"); request.put ("json_block", "true"); - std::string wallet; - node1->wallets.items.begin ()->first.encode_hex (wallet); + std::string wallet = node1->wallets.items.begin ()->first.to_string (); request.put ("wallet", wallet); request.put ("account", key.pub.to_account ()); boost::property_tree::ptree json; @@ -4574,8 +4553,7 @@ TEST (rpc, block_create) boost::property_tree::ptree request1; request1.put ("action", "block_create"); request1.put ("type", "open"); - std::string key_text; - key.prv.encode_hex (key_text); + std::string key_text = key.prv.to_string (); request1.put ("key", key_text); request1.put ("representative", nano::dev::genesis_key.pub.to_account ()); request1.put ("source", send->hash ().to_string ()); @@ -4925,8 +4903,7 @@ TEST (rpc, wallet_lock) auto node = add_ipc_enabled_node (system); auto const rpc_ctx = add_rpc (system, node); boost::property_tree::ptree request; - std::string wallet; - node->wallets.items.begin ()->first.encode_hex (wallet); + std::string wallet = node->wallets.items.begin ()->first.to_string (); { auto transaction (system.wallet (0)->wallets.tx_begin_read ()); ASSERT_TRUE (system.wallet (0)->store.valid_password (transaction)); @@ -4946,8 +4923,7 @@ TEST (rpc, wallet_locked) auto node = add_ipc_enabled_node (system); auto const rpc_ctx = add_rpc (system, node); boost::property_tree::ptree request; - std::string wallet; - node->wallets.items.begin ()->first.encode_hex (wallet); + std::string wallet = node->wallets.items.begin ()->first.to_string (); request.put ("wallet", wallet); request.put ("action", "wallet_locked"); auto response (wait_response (system, rpc_ctx, request)); @@ -5052,8 +5028,7 @@ TEST (rpc, wallet_add_watch) auto node = add_ipc_enabled_node (system); auto const rpc_ctx = add_rpc (system, node); boost::property_tree::ptree request; - std::string wallet; - node->wallets.items.begin ()->first.encode_hex (wallet); + std::string wallet = node->wallets.items.begin ()->first.to_string (); request.put ("wallet", wallet); request.put ("action", "wallet_add_watch"); boost::property_tree::ptree entry; @@ -5678,8 +5653,7 @@ TEST (rpc, sign_block) auto const rpc_ctx = add_rpc (system, node1); boost::property_tree::ptree request; request.put ("action", "sign"); - std::string wallet; - node1->wallets.items.begin ()->first.encode_hex (wallet); + std::string wallet = node1->wallets.items.begin ()->first.to_string (); request.put ("wallet", wallet); request.put ("account", key.pub.to_account ()); std::string json; @@ -6416,8 +6390,7 @@ TEST (rpc, receive) nano::test::system system; auto node = add_ipc_enabled_node (system); auto wallet = system.wallet (0); - std::string wallet_text; - node->wallets.items.begin ()->first.encode_hex (wallet_text); + std::string wallet_text = node->wallets.items.begin ()->first.to_string (); wallet->insert_adhoc (nano::dev::genesis_key.prv); nano::keypair key1; wallet->insert_adhoc (key1.prv); @@ -6457,8 +6430,7 @@ TEST (rpc, receive_unopened) nano::test::system system; auto node = add_ipc_enabled_node (system); auto wallet = system.wallet (0); - std::string wallet_text; - node->wallets.items.begin ()->first.encode_hex (wallet_text); + std::string wallet_text = node->wallets.items.begin ()->first.to_string (); wallet->insert_adhoc (nano::dev::genesis_key.prv); // Test receiving for unopened account nano::keypair key1; @@ -6515,8 +6487,7 @@ TEST (rpc, receive_work_disabled) config.work_threads = 0; auto node = add_ipc_enabled_node (system, config); auto wallet = system.wallet (1); - std::string wallet_text; - node->wallets.items.begin ()->first.encode_hex (wallet_text); + std::string wallet_text = node->wallets.items.begin ()->first.to_string (); wallet->insert_adhoc (nano::dev::genesis_key.prv); nano::keypair key1; ASSERT_TRUE (worker_node.work_generation_enabled ()); @@ -6549,8 +6520,7 @@ TEST (rpc, receive_pruned) auto node2 = add_ipc_enabled_node (system, node_config, node_flags); auto wallet1 = system.wallet (0); auto wallet2 = system.wallet (1); - std::string wallet_text; - node2->wallets.items.begin ()->first.encode_hex (wallet_text); + std::string wallet_text = node2->wallets.items.begin ()->first.to_string (); wallet1->insert_adhoc (nano::dev::genesis_key.prv); nano::keypair key1; wallet2->insert_adhoc (key1.prv);