Skip to content

Commit 067981e

Browse files
committed
[validation] Tidy Up ValidationResult class
Minor style fixups and comment updates. This is purely a style change. There is no change in behavior.
1 parent a27a295 commit 067981e

File tree

1 file changed

+29
-34
lines changed

1 file changed

+29
-34
lines changed

src/consensus/validation.h

Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -85,42 +85,34 @@ class ValidationState {
8585
MODE_VALID, //!< everything ok
8686
MODE_INVALID, //!< network rule violation (DoS value may be set)
8787
MODE_ERROR, //!< run-time error
88-
} mode;
89-
std::string strRejectReason;
90-
std::string strDebugMessage;
88+
} m_mode;
89+
std::string m_reject_reason;
90+
std::string m_debug_message;
9191
protected:
92-
bool Invalid(bool ret = false,
93-
const std::string &strRejectReasonIn="",
94-
const std::string &strDebugMessageIn="") {
95-
strRejectReason = strRejectReasonIn;
96-
strDebugMessage = strDebugMessageIn;
97-
if (mode == MODE_ERROR)
98-
return ret;
99-
mode = MODE_INVALID;
100-
return ret;
92+
void Invalid(const std::string &reject_reason="",
93+
const std::string &debug_message="")
94+
{
95+
m_reject_reason = reject_reason;
96+
m_debug_message = debug_message;
97+
if (m_mode != MODE_ERROR) m_mode = MODE_INVALID;
10198
}
10299
public:
103100
// ValidationState is abstract. Have a pure virtual destructor.
104101
virtual ~ValidationState() = 0;
105102

106-
ValidationState() : mode(MODE_VALID) {}
107-
bool Error(const std::string& strRejectReasonIn) {
108-
if (mode == MODE_VALID)
109-
strRejectReason = strRejectReasonIn;
110-
mode = MODE_ERROR;
103+
ValidationState() : m_mode(MODE_VALID) {}
104+
bool Error(const std::string& reject_reason)
105+
{
106+
if (m_mode == MODE_VALID)
107+
m_reject_reason = reject_reason;
108+
m_mode = MODE_ERROR;
111109
return false;
112110
}
113-
bool IsValid() const {
114-
return mode == MODE_VALID;
115-
}
116-
bool IsInvalid() const {
117-
return mode == MODE_INVALID;
118-
}
119-
bool IsError() const {
120-
return mode == MODE_ERROR;
121-
}
122-
std::string GetRejectReason() const { return strRejectReason; }
123-
std::string GetDebugMessage() const { return strDebugMessage; }
111+
bool IsValid() const { return m_mode == MODE_VALID; }
112+
bool IsInvalid() const { return m_mode == MODE_INVALID; }
113+
bool IsError() const { return m_mode == MODE_ERROR; }
114+
std::string GetRejectReason() const { return m_reject_reason; }
115+
std::string GetDebugMessage() const { return m_debug_message; }
124116
};
125117

126118
inline ValidationState::~ValidationState() {};
@@ -130,10 +122,12 @@ class TxValidationState : public ValidationState {
130122
TxValidationResult m_result;
131123
public:
132124
bool Invalid(TxValidationResult result, bool ret = false,
133-
const std::string &_strRejectReason="",
134-
const std::string &_strDebugMessage="") {
125+
const std::string &reject_reason="",
126+
const std::string &debug_message="")
127+
{
135128
m_result = result;
136-
return ValidationState::Invalid(ret, _strRejectReason, _strDebugMessage);
129+
ValidationState::Invalid(reject_reason, debug_message);
130+
return ret;
137131
}
138132
TxValidationResult GetResult() const { return m_result; }
139133
};
@@ -143,10 +137,11 @@ class BlockValidationState : public ValidationState {
143137
BlockValidationResult m_result;
144138
public:
145139
bool Invalid(BlockValidationResult result, bool ret = false,
146-
const std::string &_strRejectReason="",
147-
const std::string &_strDebugMessage="") {
140+
const std::string &reject_reason="",
141+
const std::string &debug_message="") {
148142
m_result = result;
149-
return ValidationState::Invalid(ret, _strRejectReason, _strDebugMessage);
143+
ValidationState::Invalid(reject_reason, debug_message);
144+
return ret;
150145
}
151146
BlockValidationResult GetResult() const { return m_result; }
152147
};

0 commit comments

Comments
 (0)