LCOV - code coverage report
Current view: top level - src/consensus - validation.h (source / functions) Hit Total Coverage
Test: total_coverage.info Lines: 33 33 100.0 %
Date: 2025-02-23 09:33:43 Functions: 1 1 100.0 %

          Line data    Source code
       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             : 
      12             : /** "reject" message codes */
      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             : 
      22             : /** Capture information about block/transaction validation */
      23             : class CValidationState
      24             : {
      25             : private:
      26             :     enum mode_state {
      27             :         MODE_VALID,   //! everything ok
      28             :         MODE_INVALID, //! network rule violation (DoS value may be set)
      29             :         MODE_ERROR,   //! run-time error
      30             :     } mode;
      31             :     int nDoS;
      32             :     std::string strRejectReason;
      33             :     unsigned int chRejectCode;
      34             :     bool corruptionPossible;
      35             :     std::string strDebugMessage;
      36             : 
      37             : public:
      38     3688607 :     CValidationState() : mode(MODE_VALID), nDoS(0), chRejectCode(0), corruptionPossible(false) {}
      39         614 :     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         614 :         chRejectCode = chRejectCodeIn;
      46         408 :         strRejectReason = strRejectReasonIn;
      47         614 :         corruptionPossible = corruptionIn;
      48         614 :         strDebugMessage = strDebugMessageIn;
      49         614 :         if (mode == MODE_ERROR)
      50             :             return ret;
      51         614 :         nDoS += level;
      52         614 :         mode = MODE_INVALID;
      53         614 :         return ret;
      54             :     }
      55         258 :     bool Invalid(bool ret = false,
      56             :         unsigned int _chRejectCode = 0,
      57             :         const std::string& _strRejectReason = "",
      58             :         const std::string& _strDebugMessage = "")
      59             :     {
      60         535 :         return DoS(0, ret, _chRejectCode, _strRejectReason, false, _strDebugMessage);
      61             :     }
      62       10463 :     bool Error(std::string strRejectReasonIn = "")
      63             :     {
      64       10463 :         if (mode == MODE_VALID)
      65       10463 :             strRejectReason = strRejectReasonIn;
      66       10463 :         mode = MODE_ERROR;
      67       10463 :         return false;
      68             :     }
      69       66519 :     bool IsValid() const
      70             :     {
      71       66519 :         return mode == MODE_VALID;
      72             :     }
      73       48601 :     bool IsInvalid() const
      74             :     {
      75       48601 :         return mode == MODE_INVALID;
      76             :     }
      77       12827 :     bool IsError() const
      78             :     {
      79       12827 :         return mode == MODE_ERROR;
      80             :     }
      81       48472 :     bool IsInvalid(int& nDoSOut) const
      82             :     {
      83       48472 :         if (IsInvalid()) {
      84          81 :             nDoSOut = nDoS;
      85          81 :             return true;
      86             :         }
      87             :         return false;
      88             :     }
      89         102 :     bool CorruptionPossible() const
      90             :     {
      91         102 :         return corruptionPossible;
      92             :     }
      93          64 :     unsigned int GetRejectCode() const { return chRejectCode; }
      94       25184 :     std::string GetRejectReason() const { return strRejectReason; }
      95       10681 :     std::string GetDebugMessage() const { return strDebugMessage; }
      96           2 :     int GetDoSScore() const { return nDoS; }
      97             : };
      98             : 
      99             : #endif // PIVX_CONSENSUS_VALIDATION_H

Generated by: LCOV version 1.14