Changeset View
Changeset View
Standalone View
Standalone View
src/consensus/validation.h
Show First 20 Lines • Show All 83 Lines • ▼ Show 20 Lines | |||||
* validation information on transactions and blocks respectively. | * validation information on transactions and blocks respectively. | ||||
*/ | */ | ||||
class ValidationState { | class ValidationState { | ||||
private: | private: | ||||
enum mode_state { | enum mode_state { | ||||
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 | ||||
} m_mode; | } m_mode{MODE_VALID}; | ||||
std::string m_reject_reason; | std::string m_reject_reason; | ||||
std::string m_debug_message; | std::string m_debug_message; | ||||
protected: | protected: | ||||
void Invalid(const std::string &reject_reason = "", | void Invalid(const std::string &reject_reason = "", | ||||
const std::string &debug_message = "") { | const std::string &debug_message = "") { | ||||
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) { | if (m_mode != MODE_ERROR) { | ||||
m_mode = MODE_INVALID; | m_mode = MODE_INVALID; | ||||
} | } | ||||
} | } | ||||
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() : m_mode(MODE_VALID) {} | |||||
bool Error(const std::string &reject_reason) { | bool Error(const std::string &reject_reason) { | ||||
if (m_mode == MODE_VALID) { | if (m_mode == MODE_VALID) { | ||||
m_reject_reason = reject_reason; | m_reject_reason = reject_reason; | ||||
} | } | ||||
m_mode = MODE_ERROR; | m_mode = MODE_ERROR; | ||||
return false; | return false; | ||||
} | } | ||||
bool IsValid() const { return m_mode == MODE_VALID; } | bool IsValid() const { return m_mode == MODE_VALID; } | ||||
▲ Show 20 Lines • Show All 50 Lines • Show Last 20 Lines |