[validation] Tidy Up ValidationResult class

Minor style fixups and comment updates.

This is purely a style change. There is no change in behavior.
This commit is contained in:
John Newbery 2019-04-28 12:17:56 -05:00
parent a27a2957ed
commit 067981e492

View File

@ -85,42 +85,34 @@ private:
MODE_VALID, //!< everything ok MODE_VALID, //!< everything ok
MODE_INVALID, //!< network rule violation (DoS value may be set) MODE_INVALID, //!< network rule violation (DoS value may be set)
MODE_ERROR, //!< run-time error MODE_ERROR, //!< run-time error
} mode; } m_mode;
std::string strRejectReason; std::string m_reject_reason;
std::string strDebugMessage; std::string m_debug_message;
protected: protected:
bool Invalid(bool ret = false, void Invalid(const std::string &reject_reason="",
const std::string &strRejectReasonIn="", const std::string &debug_message="")
const std::string &strDebugMessageIn="") { {
strRejectReason = strRejectReasonIn; m_reject_reason = reject_reason;
strDebugMessage = strDebugMessageIn; m_debug_message = debug_message;
if (mode == MODE_ERROR) if (m_mode != MODE_ERROR) m_mode = MODE_INVALID;
return ret;
mode = MODE_INVALID;
return ret;
} }
public: public:
// ValidationState is abstract. Have a pure virtual destructor. // ValidationState is abstract. Have a pure virtual destructor.
virtual ~ValidationState() = 0; virtual ~ValidationState() = 0;
ValidationState() : mode(MODE_VALID) {} ValidationState() : m_mode(MODE_VALID) {}
bool Error(const std::string& strRejectReasonIn) { bool Error(const std::string& reject_reason)
if (mode == MODE_VALID) {
strRejectReason = strRejectReasonIn; if (m_mode == MODE_VALID)
mode = MODE_ERROR; m_reject_reason = reject_reason;
m_mode = MODE_ERROR;
return false; return false;
} }
bool IsValid() const { bool IsValid() const { return m_mode == MODE_VALID; }
return mode == MODE_VALID; bool IsInvalid() const { return m_mode == MODE_INVALID; }
} bool IsError() const { return m_mode == MODE_ERROR; }
bool IsInvalid() const { std::string GetRejectReason() const { return m_reject_reason; }
return mode == MODE_INVALID; std::string GetDebugMessage() const { return m_debug_message; }
}
bool IsError() const {
return mode == MODE_ERROR;
}
std::string GetRejectReason() const { return strRejectReason; }
std::string GetDebugMessage() const { return strDebugMessage; }
}; };
inline ValidationState::~ValidationState() {}; inline ValidationState::~ValidationState() {};
@ -130,10 +122,12 @@ private:
TxValidationResult m_result; TxValidationResult m_result;
public: public:
bool Invalid(TxValidationResult result, bool ret = false, bool Invalid(TxValidationResult result, bool ret = false,
const std::string &_strRejectReason="", const std::string &reject_reason="",
const std::string &_strDebugMessage="") { const std::string &debug_message="")
{
m_result = result; m_result = result;
return ValidationState::Invalid(ret, _strRejectReason, _strDebugMessage); ValidationState::Invalid(reject_reason, debug_message);
return ret;
} }
TxValidationResult GetResult() const { return m_result; } TxValidationResult GetResult() const { return m_result; }
}; };
@ -143,10 +137,11 @@ private:
BlockValidationResult m_result; BlockValidationResult m_result;
public: public:
bool Invalid(BlockValidationResult result, bool ret = false, bool Invalid(BlockValidationResult result, bool ret = false,
const std::string &_strRejectReason="", const std::string &reject_reason="",
const std::string &_strDebugMessage="") { const std::string &debug_message="") {
m_result = result; m_result = result;
return ValidationState::Invalid(ret, _strRejectReason, _strDebugMessage); ValidationState::Invalid(reject_reason, debug_message);
return ret;
} }
BlockValidationResult GetResult() const { return m_result; } BlockValidationResult GetResult() const { return m_result; }
}; };