LCOV - code coverage report
Current view: top level - src/consensus - validation.h (source / functions) Hit Total Coverage
Test: total_coverage.info Lines: 15 26 57.7 %
Date: 2015-10-12 22:39:14 Functions: 2 8 25.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // Copyright (c) 2009-2010 Satoshi Nakamoto
       2             : // Copyright (c) 2009-2014 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 unsigned char REJECT_MALFORMED = 0x01;
      13             : static const unsigned char REJECT_INVALID = 0x10;
      14             : static const unsigned char REJECT_OBSOLETE = 0x11;
      15             : static const unsigned char REJECT_DUPLICATE = 0x12;
      16             : static const unsigned char REJECT_NONSTANDARD = 0x40;
      17             : static const unsigned char REJECT_DUST = 0x41;
      18             : static const unsigned char REJECT_INSUFFICIENTFEE = 0x42;
      19             : static const unsigned char REJECT_CHECKPOINT = 0x43;
      20             : 
      21             : /** Capture information about block/transaction validation */
      22      623004 : 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             : public:
      35      415304 :     CValidationState() : mode(MODE_VALID), nDoS(0), chRejectCode(0), corruptionPossible(false) {}
      36             :     bool DoS(int level, bool ret = false,
      37             :              unsigned int chRejectCodeIn=0, const std::string &strRejectReasonIn="",
      38             :              bool corruptionIn=false,
      39             :              const std::string &strDebugMessageIn="") {
      40          86 :         chRejectCode = chRejectCodeIn;
      41          86 :         strRejectReason = strRejectReasonIn;
      42          86 :         corruptionPossible = corruptionIn;
      43          86 :         strDebugMessage = strDebugMessageIn;
      44          86 :         if (mode == MODE_ERROR)
      45             :             return ret;
      46          63 :         nDoS += level;
      47          86 :         mode = MODE_INVALID;
      48             :         return ret;
      49             :     }
      50             :     bool Invalid(bool ret = false,
      51             :                  unsigned int _chRejectCode=0, const std::string &_strRejectReason="",
      52             :                  const std::string &_strDebugMessage="") {
      53          10 :         return DoS(0, ret, _chRejectCode, _strRejectReason, false, _strDebugMessage);
      54             :     }
      55             :     bool Error(const std::string& strRejectReasonIn) {
      56           0 :         if (mode == MODE_VALID)
      57           0 :             strRejectReason = strRejectReasonIn;
      58           0 :         mode = MODE_ERROR;
      59             :         return false;
      60             :     }
      61           0 :     bool IsValid() const {
      62         662 :         return mode == MODE_VALID;
      63             :     }
      64           0 :     bool IsInvalid() const {
      65           0 :         return mode == MODE_INVALID;
      66             :     }
      67           0 :     bool IsError() const {
      68           0 :         return mode == MODE_ERROR;
      69             :     }
      70             :     bool IsInvalid(int &nDoSOut) const {
      71        4395 :         if (IsInvalid()) {
      72          55 :             nDoSOut = nDoS;
      73             :             return true;
      74             :         }
      75             :         return false;
      76             :     }
      77           0 :     bool CorruptionPossible() const {
      78           0 :         return corruptionPossible;
      79             :     }
      80           0 :     unsigned int GetRejectCode() const { return chRejectCode; }
      81          67 :     std::string GetRejectReason() const { return strRejectReason; }
      82          15 :     std::string GetDebugMessage() const { return strDebugMessage; }
      83             : };
      84             : 
      85             : #endif // BITCOIN_CONSENSUS_VALIDATION_H

Generated by: LCOV version 1.11