diff --git a/src/util/validation.cpp b/src/util/validation.cpp index cd7f7298f..7f86a8f81 100644 --- a/src/util/validation.cpp +++ b/src/util/validation.cpp @@ -1,19 +1,26 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2019 The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include #include #include -/** Convert ValidationState to a human-readable message for logging */ std::string FormatStateMessage(const ValidationState &state) { - return strprintf( - "%s%s (code %i)", state.GetRejectReason(), - state.GetDebugMessage().empty() ? "" : ", " + state.GetDebugMessage(), - state.GetRejectCode()); + if (state.IsValid()) { + return "Valid"; + } + + const std::string debug_message = state.GetDebugMessage(); + if (!debug_message.empty()) { + return strprintf("%s, %s (code %i)", state.GetRejectReason(), + debug_message, state.GetRejectCode()); + } + + return strprintf("%s (code %i)", state.GetRejectReason(), + state.GetRejectCode()); } const std::string strMessageMagic = "Bitcoin Signed Message:\n";