From b7dc1da699f208a568d08172e1aa69f843bc0409 Mon Sep 17 00:00:00 2001 From: brandon-bb <41524435+brandon-bb@users.noreply.github.com> Date: Wed, 30 Aug 2023 19:42:50 +0100 Subject: [PATCH] Add to_string functions to the classes asc_pull_req and asc_pull_ack (#4255) Adding ::to_string methods to asc_pull_req and asc_pull_ack messages. --- nano/node/messages.cpp | 70 ++++++++++++++++++++++++++++++++++++++++++ nano/node/messages.hpp | 4 ++- 2 files changed, 73 insertions(+), 1 deletion(-) diff --git a/nano/node/messages.cpp b/nano/node/messages.cpp index d98c02f6a2..2417eddf18 100644 --- a/nano/node/messages.cpp +++ b/nano/node/messages.cpp @@ -23,7 +23,9 @@ #include #include #include +#include #include +#include #include /* @@ -1656,6 +1658,35 @@ bool nano::asc_pull_req::verify_consistency () const return true; // Just for convenience of calling from asserts } +std::string nano::asc_pull_req::to_string () const +{ + std::string s = header.to_string () + "\n"; + + std::visit ([&s] (auto && arg) { + using T = std::decay_t; + + if constexpr (std::is_same_v) + { + s += "missing payload"; + } + + else if constexpr (std::is_same_v) + { + s += "acc:" + arg.start.to_string (); + s += " max block count:" + to_string_hex (static_cast (arg.count)); + s += " hash type:" + to_string_hex (static_cast (arg.start_type)); + } + + else if constexpr (std::is_same_v) + { + s += "target:" + arg.target.to_string (); + s += " hash type:" + to_string_hex (static_cast (arg.target_type)); + } + }, + payload); + + return s; +} /* * asc_pull_req::blocks_payload */ @@ -1809,6 +1840,45 @@ bool nano::asc_pull_ack::verify_consistency () const return true; // Just for convenience of calling from asserts } +std::string nano::asc_pull_ack::to_string () const +{ + std::string s = header.to_string () + "\n"; + + std::visit ([&s] (auto && arg) { + using T = std::decay_t; + + if constexpr (std::is_same_v) + { + s += "missing payload"; + } + + else if constexpr (std::is_same_v) + { + auto block = std::begin (arg.blocks); + auto end_block = std::end (arg.blocks); + + while (block != end_block) + { + s += (*block)->to_json (); + ++block; + } + } + + else if constexpr (std::is_same_v) + { + s += "account public key:" + arg.account.to_account (); + s += " account open:" + arg.account_open.to_string (); + s += " account head:" + arg.account_head.to_string (); + s += " block count:" + to_string_hex (arg.account_block_count); + s += " confirmation frontier:" + arg.account_conf_frontier.to_string (); + s += " confirmation height:" + to_string_hex (arg.account_conf_height); + } + }, + payload); + + return s; +} + /* * asc_pull_ack::blocks_payload */ diff --git a/nano/node/messages.hpp b/nano/node/messages.hpp index 976ba2b55f..bf4ab2b2ab 100644 --- a/nano/node/messages.hpp +++ b/nano/node/messages.hpp @@ -429,6 +429,7 @@ class asc_pull_req final : public message void serialize_payload (nano::stream &) const; void deserialize_payload (nano::stream &); + std::string to_string () const; private: // Debug /** @@ -504,6 +505,7 @@ class asc_pull_ack final : public message void serialize_payload (nano::stream &) const; void deserialize_payload (nano::stream &); + std::string to_string () const; private: // Debug /** @@ -613,4 +615,4 @@ class message_visitor } virtual void default_handler (nano::message const &){}; }; -} \ No newline at end of file +}