From 6edebacb2191373e76d79a4972d6192300976096 Mon Sep 17 00:00:00 2001 From: Jeffrey Czyz Date: Fri, 3 Jan 2020 11:38:44 -0800 Subject: Refactor FormatStateMessage for clarity All cases of CValidationState were condensed into one strprintf call. This is no longer suitable as more cases are added (e.g., IsValid). --- src/util/validation.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/util/validation.cpp b/src/util/validation.cpp index 603db51d45..ed9c108bb0 100644 --- a/src/util/validation.cpp +++ b/src/util/validation.cpp @@ -8,16 +8,18 @@ #include #include -/** Convert ValidationState to a human-readable message for logging */ std::string FormatStateMessage(const ValidationState &state) { if (state.IsValid()) { return "Valid"; } - return strprintf("%s%s", - state.GetRejectReason(), - state.GetDebugMessage().empty() ? "" : ", "+state.GetDebugMessage()); + const std::string debug_message = state.GetDebugMessage(); + if (!debug_message.empty()) { + return strprintf("%s, %s", state.GetRejectReason(), debug_message); + } + + return state.GetRejectReason(); } const std::string strMessageMagic = "Bitcoin Signed Message:\n"; -- cgit v1.2.3