mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-09 10:43:19 -05:00
refactor: Switch ValidationState mode to C++11 enum class
This commit is contained in:
parent
3d57015aa2
commit
fa492895b5
1 changed files with 16 additions and 14 deletions
|
@ -75,37 +75,39 @@ enum class BlockValidationResult {
|
||||||
* by TxValidationState and BlockValidationState for validation information on transactions
|
* by TxValidationState and BlockValidationState for validation information on transactions
|
||||||
* and blocks respectively. */
|
* and blocks respectively. */
|
||||||
template <typename Result>
|
template <typename Result>
|
||||||
class ValidationState {
|
class ValidationState
|
||||||
|
{
|
||||||
private:
|
private:
|
||||||
enum mode_state {
|
enum class ModeState {
|
||||||
MODE_VALID, //!< everything ok
|
M_VALID, //!< everything ok
|
||||||
MODE_INVALID, //!< network rule violation (DoS value may be set)
|
M_INVALID, //!< network rule violation (DoS value may be set)
|
||||||
MODE_ERROR, //!< run-time error
|
M_ERROR, //!< run-time error
|
||||||
} m_mode{MODE_VALID};
|
} m_mode{ModeState::M_VALID};
|
||||||
Result m_result{};
|
Result m_result{};
|
||||||
std::string m_reject_reason;
|
std::string m_reject_reason;
|
||||||
std::string m_debug_message;
|
std::string m_debug_message;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
bool Invalid(Result result,
|
bool Invalid(Result result,
|
||||||
const std::string &reject_reason="",
|
const std::string& reject_reason = "",
|
||||||
const std::string &debug_message="")
|
const std::string& debug_message = "")
|
||||||
{
|
{
|
||||||
m_result = result;
|
m_result = result;
|
||||||
m_reject_reason = reject_reason;
|
m_reject_reason = reject_reason;
|
||||||
m_debug_message = debug_message;
|
m_debug_message = debug_message;
|
||||||
if (m_mode != MODE_ERROR) m_mode = MODE_INVALID;
|
if (m_mode != ModeState::M_ERROR) m_mode = ModeState::M_INVALID;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
bool Error(const std::string& reject_reason)
|
bool Error(const std::string& reject_reason)
|
||||||
{
|
{
|
||||||
if (m_mode == MODE_VALID)
|
if (m_mode == ModeState::M_VALID)
|
||||||
m_reject_reason = reject_reason;
|
m_reject_reason = reject_reason;
|
||||||
m_mode = MODE_ERROR;
|
m_mode = ModeState::M_ERROR;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
bool IsValid() const { return m_mode == MODE_VALID; }
|
bool IsValid() const { return m_mode == ModeState::M_VALID; }
|
||||||
bool IsInvalid() const { return m_mode == MODE_INVALID; }
|
bool IsInvalid() const { return m_mode == ModeState::M_INVALID; }
|
||||||
bool IsError() const { return m_mode == MODE_ERROR; }
|
bool IsError() const { return m_mode == ModeState::M_ERROR; }
|
||||||
Result GetResult() const { return m_result; }
|
Result GetResult() const { return m_result; }
|
||||||
std::string GetRejectReason() const { return m_reject_reason; }
|
std::string GetRejectReason() const { return m_reject_reason; }
|
||||||
std::string GetDebugMessage() const { return m_debug_message; }
|
std::string GetDebugMessage() const { return m_debug_message; }
|
||||||
|
|
Loading…
Add table
Reference in a new issue