PIVX Core  5.6.99
P2P Digital Currency
validation.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2016 The Bitcoin Core developers
3 // Copyright (c) 2020-2021 The PIVX Core developers
4 // Distributed under the MIT software license, see the accompanying
5 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
6 
7 #ifndef PIVX_CONSENSUS_VALIDATION_H
8 #define PIVX_CONSENSUS_VALIDATION_H
9 
10 #include <string>
11 
13 static const unsigned char REJECT_MALFORMED = 0x01;
14 static const unsigned char REJECT_INVALID = 0x10;
15 static const unsigned char REJECT_OBSOLETE = 0x11;
16 static const unsigned char REJECT_DUPLICATE = 0x12;
17 static const unsigned char REJECT_NONSTANDARD = 0x40;
18 static const unsigned char REJECT_DUST = 0x41;
19 static const unsigned char REJECT_INSUFFICIENTFEE = 0x42;
20 static const unsigned char REJECT_CHECKPOINT = 0x43;
21 
24 {
25 private:
26  enum mode_state {
30  } mode;
31  int nDoS;
32  std::string strRejectReason;
33  unsigned int chRejectCode;
35  std::string strDebugMessage;
36 
37 public:
39  bool DoS(int level, bool ret = false,
40  unsigned int chRejectCodeIn = 0,
41  std::string strRejectReasonIn = "",
42  bool corruptionIn = false,
43  const std::string& strDebugMessageIn = "")
44  {
45  chRejectCode = chRejectCodeIn;
46  strRejectReason = strRejectReasonIn;
47  corruptionPossible = corruptionIn;
48  strDebugMessage = strDebugMessageIn;
49  if (mode == MODE_ERROR)
50  return ret;
51  nDoS += level;
53  return ret;
54  }
55  bool Invalid(bool ret = false,
56  unsigned int _chRejectCode = 0,
57  const std::string& _strRejectReason = "",
58  const std::string& _strDebugMessage = "")
59  {
60  return DoS(0, ret, _chRejectCode, _strRejectReason, false, _strDebugMessage);
61  }
62  bool Error(std::string strRejectReasonIn = "")
63  {
64  if (mode == MODE_VALID)
65  strRejectReason = strRejectReasonIn;
66  mode = MODE_ERROR;
67  return false;
68  }
69  bool IsValid() const
70  {
71  return mode == MODE_VALID;
72  }
73  bool IsInvalid() const
74  {
75  return mode == MODE_INVALID;
76  }
77  bool IsError() const
78  {
79  return mode == MODE_ERROR;
80  }
81  bool IsInvalid(int& nDoSOut) const
82  {
83  if (IsInvalid()) {
84  nDoSOut = nDoS;
85  return true;
86  }
87  return false;
88  }
89  bool CorruptionPossible() const
90  {
91  return corruptionPossible;
92  }
93  unsigned int GetRejectCode() const { return chRejectCode; }
94  std::string GetRejectReason() const { return strRejectReason; }
95  std::string GetDebugMessage() const { return strDebugMessage; }
96  int GetDoSScore() const { return nDoS; }
97 };
98 
99 #endif // PIVX_CONSENSUS_VALIDATION_H
false
Definition: bls_dkg.cpp:151
Capture information about block/transaction validation.
Definition: validation.h:24
unsigned int GetRejectCode() const
Definition: validation.h:93
unsigned int chRejectCode
Definition: validation.h:33
int GetDoSScore() const
Definition: validation.h:96
bool Invalid(bool ret=false, unsigned int _chRejectCode=0, const std::string &_strRejectReason="", const std::string &_strDebugMessage="")
Definition: validation.h:55
bool IsInvalid(int &nDoSOut) const
Definition: validation.h:81
std::string strRejectReason
Definition: validation.h:32
bool DoS(int level, bool ret=false, unsigned int chRejectCodeIn=0, std::string strRejectReasonIn="", bool corruptionIn=false, const std::string &strDebugMessageIn="")
Definition: validation.h:39
bool IsValid() const
Definition: validation.h:69
std::string GetRejectReason() const
Definition: validation.h:94
enum CValidationState::mode_state mode
@ MODE_INVALID
everything ok
Definition: validation.h:28
@ MODE_ERROR
network rule violation (DoS value may be set)
Definition: validation.h:29
bool Error(std::string strRejectReasonIn="")
Definition: validation.h:62
bool IsInvalid() const
Definition: validation.h:73
bool CorruptionPossible() const
Definition: validation.h:89
bool IsError() const
Definition: validation.h:77
std::string GetDebugMessage() const
Definition: validation.h:95
std::string strDebugMessage
Definition: validation.h:35
bool corruptionPossible
Definition: validation.h:34