2017-11-09 19:34:51 +01:00
|
|
|
/*
|
|
|
|
|
* This file is part of the Flowee project
|
|
|
|
|
* Copyright (C) 2009-2010 Satoshi Nakamoto
|
|
|
|
|
* Copyright (C) 2009-2015 The Bitcoin Core developers
|
2021-06-20 22:44:44 +02:00
|
|
|
* Copyright (C) 2017 Tom Zander <tom@flowee.org>
|
2017-11-09 19:34:51 +01:00
|
|
|
*
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
2015-01-24 15:57:12 +01:00
|
|
|
|
2018-01-16 10:47:52 +00:00
|
|
|
#ifndef FLOWEE_CONSENSUS_VALIDATION_H
|
|
|
|
|
#define FLOWEE_CONSENSUS_VALIDATION_H
|
2015-01-24 15:57:12 +01:00
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
|
|
/** "reject" message codes */
|
|
|
|
|
static const unsigned char REJECT_MALFORMED = 0x01;
|
|
|
|
|
static const unsigned char REJECT_INVALID = 0x10;
|
|
|
|
|
static const unsigned char REJECT_OBSOLETE = 0x11;
|
|
|
|
|
static const unsigned char REJECT_DUPLICATE = 0x12;
|
2017-01-31 10:36:59 +01:00
|
|
|
static const unsigned char REJECT_EXCEEDSLIMIT = 0x13;
|
2015-01-24 15:57:12 +01:00
|
|
|
static const unsigned char REJECT_NONSTANDARD = 0x40;
|
|
|
|
|
static const unsigned char REJECT_DUST = 0x41;
|
|
|
|
|
static const unsigned char REJECT_INSUFFICIENTFEE = 0x42;
|
|
|
|
|
static const unsigned char REJECT_CHECKPOINT = 0x43;
|
|
|
|
|
|
|
|
|
|
/** Capture information about block/transaction validation */
|
|
|
|
|
class CValidationState {
|
|
|
|
|
private:
|
|
|
|
|
enum mode_state {
|
|
|
|
|
MODE_VALID, //! everything ok
|
|
|
|
|
MODE_INVALID, //! network rule violation (DoS value may be set)
|
|
|
|
|
MODE_ERROR, //! run-time error
|
|
|
|
|
} mode;
|
|
|
|
|
int nDoS;
|
|
|
|
|
std::string strRejectReason;
|
2015-03-16 21:36:43 -04:00
|
|
|
unsigned int chRejectCode;
|
2015-01-24 15:57:12 +01:00
|
|
|
bool corruptionPossible;
|
2015-08-06 09:47:01 +02:00
|
|
|
std::string strDebugMessage;
|
2015-01-24 15:57:12 +01:00
|
|
|
public:
|
|
|
|
|
CValidationState() : mode(MODE_VALID), nDoS(0), chRejectCode(0), corruptionPossible(false) {}
|
|
|
|
|
bool DoS(int level, bool ret = false,
|
2015-08-06 09:47:01 +02:00
|
|
|
unsigned int chRejectCodeIn=0, const std::string &strRejectReasonIn="",
|
|
|
|
|
bool corruptionIn=false,
|
|
|
|
|
const std::string &strDebugMessageIn="") {
|
2015-01-24 15:57:12 +01:00
|
|
|
chRejectCode = chRejectCodeIn;
|
|
|
|
|
strRejectReason = strRejectReasonIn;
|
|
|
|
|
corruptionPossible = corruptionIn;
|
2015-08-06 09:47:01 +02:00
|
|
|
strDebugMessage = strDebugMessageIn;
|
2015-01-24 15:57:12 +01:00
|
|
|
if (mode == MODE_ERROR)
|
|
|
|
|
return ret;
|
|
|
|
|
nDoS += level;
|
|
|
|
|
mode = MODE_INVALID;
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
bool Invalid(bool ret = false,
|
2015-08-06 09:47:01 +02:00
|
|
|
unsigned int _chRejectCode=0, const std::string &_strRejectReason="",
|
|
|
|
|
const std::string &_strDebugMessage="") {
|
|
|
|
|
return DoS(0, ret, _chRejectCode, _strRejectReason, false, _strDebugMessage);
|
2015-01-24 15:57:12 +01:00
|
|
|
}
|
2015-05-31 15:36:44 +02:00
|
|
|
bool Error(const std::string& strRejectReasonIn) {
|
2015-01-24 15:57:12 +01:00
|
|
|
if (mode == MODE_VALID)
|
|
|
|
|
strRejectReason = strRejectReasonIn;
|
|
|
|
|
mode = MODE_ERROR;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
bool IsValid() const {
|
|
|
|
|
return mode == MODE_VALID;
|
|
|
|
|
}
|
|
|
|
|
bool IsInvalid() const {
|
|
|
|
|
return mode == MODE_INVALID;
|
|
|
|
|
}
|
|
|
|
|
bool IsError() const {
|
|
|
|
|
return mode == MODE_ERROR;
|
|
|
|
|
}
|
|
|
|
|
bool IsInvalid(int &nDoSOut) const {
|
|
|
|
|
if (IsInvalid()) {
|
|
|
|
|
nDoSOut = nDoS;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
bool CorruptionPossible() const {
|
|
|
|
|
return corruptionPossible;
|
|
|
|
|
}
|
2015-03-16 21:36:43 -04:00
|
|
|
unsigned int GetRejectCode() const { return chRejectCode; }
|
2015-01-24 15:57:12 +01:00
|
|
|
std::string GetRejectReason() const { return strRejectReason; }
|
2015-08-06 09:47:01 +02:00
|
|
|
std::string GetDebugMessage() const { return strDebugMessage; }
|
2015-01-24 15:57:12 +01:00
|
|
|
};
|
|
|
|
|
|
2018-01-16 10:47:52 +00:00
|
|
|
#endif
|