Format CValidationState properly in all cases

FormatValidationMessage does not properly handle the case where
CValidationState::IsValid() returns true. Use "Valid" for the state in
this case.
This commit is contained in:
Jeffrey Czyz
2019-08-29 12:42:42 -07:00
parent 389d423a25
commit ee4d66a38c
2 changed files with 12 additions and 7 deletions

View File

@ -5,15 +5,20 @@
#include <util/validation.h>
#include <consensus/validation.h>
#include <tinyformat.h>
/** Convert ValidationState to a human-readable message for logging */
std::string FormatStateMessage(const ValidationState &state)
{
return strprintf("%s%s",
state.GetRejectReason(),
state.GetDebugMessage().empty() ? "" : ", "+state.GetDebugMessage());
if (state.IsValid()) {
return "Valid";
}
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";

View File

@ -6,9 +6,9 @@
#ifndef BITCOIN_UTIL_VALIDATION_H
#define BITCOIN_UTIL_VALIDATION_H
#include <string>
#include <consensus/validation.h>
class ValidationState;
#include <string>
/** Convert ValidationState to a human-readable message for logging */
std::string FormatStateMessage(const ValidationState &state);