|
14 | 14 | #include "chain.h" |
15 | 15 | #include "chainparams.h" |
16 | 16 | #include "coins.h" |
| 17 | +#include "consensus/validation.h" |
17 | 18 | #include "primitives/block.h" |
18 | 19 | #include "primitives/transaction.h" |
19 | 20 | #include "net.h" |
@@ -94,16 +95,6 @@ static const unsigned int DATABASE_WRITE_INTERVAL = 3600; |
94 | 95 | /** Maximum length of reject messages. */ |
95 | 96 | static const unsigned int MAX_REJECT_MESSAGE_LENGTH = 111; |
96 | 97 |
|
97 | | -/** "reject" message codes */ |
98 | | -static const unsigned char REJECT_MALFORMED = 0x01; |
99 | | -static const unsigned char REJECT_INVALID = 0x10; |
100 | | -static const unsigned char REJECT_OBSOLETE = 0x11; |
101 | | -static const unsigned char REJECT_DUPLICATE = 0x12; |
102 | | -static const unsigned char REJECT_NONSTANDARD = 0x40; |
103 | | -static const unsigned char REJECT_DUST = 0x41; |
104 | | -static const unsigned char REJECT_INSUFFICIENTFEE = 0x42; |
105 | | -static const unsigned char REJECT_CHECKPOINT = 0x43; |
106 | | - |
107 | 98 | struct BlockHasher |
108 | 99 | { |
109 | 100 | size_t operator()(const uint256& hash) const { return hash.GetCheapHash(); } |
@@ -438,21 +429,18 @@ class CValidationState { |
438 | 429 | bool corruptionPossible; |
439 | 430 | public: |
440 | 431 | CValidationState() : mode(MODE_VALID), nDoS(0), chRejectCode(0), corruptionPossible(false) {} |
| 432 | + // !Modifies the CValidationState from the received ValidationResult and logs the later's error attribute unless it's empty |
| 433 | + bool ApplyResult(const ValidationResult& result); |
| 434 | + // !Deprecated in favor of CValidationState::ApplyResult() |
441 | 435 | bool DoS(int level, bool ret = false, |
442 | 436 | unsigned char chRejectCodeIn=0, std::string strRejectReasonIn="", |
443 | 437 | bool corruptionIn=false) { |
444 | | - chRejectCode = chRejectCodeIn; |
445 | | - strRejectReason = strRejectReasonIn; |
446 | | - corruptionPossible = corruptionIn; |
447 | | - if (mode == MODE_ERROR) |
448 | | - return ret; |
449 | | - nDoS += level; |
450 | | - mode = MODE_INVALID; |
451 | | - return ret; |
| 438 | + return this->ApplyResult(ValidationResult(level, ret, "", chRejectCodeIn, strRejectReasonIn, corruptionIn)); |
452 | 439 | } |
| 440 | + // !Deprecated in favor of CValidationState::ApplyResult() |
453 | 441 | bool Invalid(bool ret = false, |
454 | 442 | unsigned char _chRejectCode=0, std::string _strRejectReason="") { |
455 | | - return DoS(0, ret, _chRejectCode, _strRejectReason); |
| 443 | + return this->ApplyResult(ValidationResult(0, ret, "", _chRejectCode, _strRejectReason)); |
456 | 444 | } |
457 | 445 | bool Error(std::string strRejectReasonIn="") { |
458 | 446 | if (mode == MODE_VALID) |
|
0 commit comments