LCOV - code coverage report
Current view: top level - src/consensus - validation.h (source / functions) Hit Total Coverage
Test: bitcoincash_test.info Lines: 4 4 100.0 %
Date: 2018-04-13 15:12:50 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             : // Distributed under the MIT software license, see the accompanying
       4             : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
       5             : 
       6             : #ifndef BITCOIN_CONSENSUS_VALIDATION_H
       7             : #define BITCOIN_CONSENSUS_VALIDATION_H
       8             : 
       9             : #include <string>
      10             : 
      11             : /** "reject" message codes */
      12             : static const uint8_t REJECT_MALFORMED = 0x01;
      13             : static const uint8_t REJECT_INVALID = 0x10;
      14             : static const uint8_t REJECT_OBSOLETE = 0x11;
      15             : static const uint8_t REJECT_DUPLICATE = 0x12;
      16             : static const uint8_t REJECT_NONSTANDARD = 0x40;
      17             : static const uint8_t REJECT_DUST = 0x41;
      18             : static const uint8_t REJECT_INSUFFICIENTFEE = 0x42;
      19             : static const uint8_t REJECT_CHECKPOINT = 0x43;
      20             : 
      21             : /** Capture information about block/transaction validation */
      22       67875 : class CValidationState {
      23             : private:
      24             :     enum mode_state {
      25             :         MODE_VALID,   //!< everything ok
      26             :         MODE_INVALID, //!< network rule violation (DoS value may be set)
      27             :         MODE_ERROR,   //!< run-time error
      28             :     } mode;
      29             :     int nDoS;
      30             :     std::string strRejectReason;
      31             :     unsigned int chRejectCode;
      32             :     bool corruptionPossible;
      33             :     std::string strDebugMessage;
      34             : 
      35             : public:
      36             :     CValidationState()
      37             :         : mode(MODE_VALID), nDoS(0), chRejectCode(0),
      38       65124 :           corruptionPossible(false) {}
      39             : 
      40             :     bool DoS(int level, bool ret = false, unsigned int chRejectCodeIn = 0,
      41             :              const std::string &strRejectReasonIn = "",
      42             :              bool corruptionIn = false,
      43             :              const std::string &strDebugMessageIn = "") {
      44             :         chRejectCode = chRejectCodeIn;
      45             :         strRejectReason = strRejectReasonIn;
      46             :         corruptionPossible = corruptionIn;
      47             :         strDebugMessage = strDebugMessageIn;
      48             :         if (mode == MODE_ERROR) {
      49             :             return ret;
      50             :         }
      51             :         nDoS += level;
      52             :         mode = MODE_INVALID;
      53             :         return ret;
      54             :     }
      55             : 
      56             :     bool Invalid(bool ret = false, unsigned int _chRejectCode = 0,
      57             :                  const std::string &_strRejectReason = "",
      58             :                  const std::string &_strDebugMessage = "") {
      59             :         return DoS(0, ret, _chRejectCode, _strRejectReason, false,
      60             :                    _strDebugMessage);
      61             :     }
      62             :     bool Error(const std::string &strRejectReasonIn) {
      63             :         if (mode == MODE_VALID) {
      64             :             strRejectReason = strRejectReasonIn;
      65             :         }
      66             : 
      67             :         mode = MODE_ERROR;
      68             :         return false;
      69             :     }
      70             : 
      71        1097 :     bool IsValid() const { return mode == MODE_VALID; }
      72             :     bool IsInvalid() const { return mode == MODE_INVALID; }
      73             :     bool IsError() const { return mode == MODE_ERROR; }
      74             :     bool IsInvalid(int &nDoSOut) const {
      75             :         if (IsInvalid()) {
      76             :             nDoSOut = nDoS;
      77             :             return true;
      78             :         }
      79             :         return false;
      80             :     }
      81             : 
      82             :     bool CorruptionPossible() const { return corruptionPossible; }
      83             :     void SetCorruptionPossible() { corruptionPossible = true; }
      84             :     unsigned int GetRejectCode() const { return chRejectCode; }
      85          18 :     std::string GetRejectReason() const { return strRejectReason; }
      86             :     std::string GetDebugMessage() const { return strDebugMessage; }
      87             : };
      88             : 
      89             : #endif // BITCOIN_CONSENSUS_VALIDATION_H

Generated by: LCOV version 1.12