Changeset View
Changeset View
Standalone View
Standalone View
src/blockstatus.h
// Copyright (c) 2018 The Bitcoin developers | // Copyright (c) 2018 The Bitcoin developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#ifndef BITCOIN_BLOCKSTATUS_H | #ifndef BITCOIN_BLOCKSTATUS_H | ||||
#define BITCOIN_BLOCKSTATUS_H | #define BITCOIN_BLOCKSTATUS_H | ||||
#include "blockvalidity.h" | #include "blockvalidity.h" | ||||
#include "serialize.h" | #include "serialize.h" | ||||
#include <cstdint> | #include <cstdint> | ||||
struct BlockStatus { | struct BlockStatus { | ||||
private: | private: | ||||
uint32_t status; | uint32_t status; | ||||
explicit BlockStatus(uint32_t nStatusIn) : status(nStatusIn) {} | explicit constexpr BlockStatus(uint32_t nStatusIn) : status(nStatusIn) {} | ||||
static const uint32_t VALIDITY_MASK = 0x07; | static const uint32_t VALIDITY_MASK = 0x07; | ||||
// Full block available in blk*.dat | // Full block available in blk*.dat | ||||
static const uint32_t HAS_DATA_FLAG = 0x08; | static const uint32_t HAS_DATA_FLAG = 0x08; | ||||
// Undo data available in rev*.dat | // Undo data available in rev*.dat | ||||
static const uint32_t HAS_UNDO_FLAG = 0x10; | static const uint32_t HAS_UNDO_FLAG = 0x10; | ||||
Show All 10 Lines | private: | ||||
static const uint32_t PARKED_FLAG = 0x80; | static const uint32_t PARKED_FLAG = 0x80; | ||||
// One of the block's parent is parked. | // One of the block's parent is parked. | ||||
static const uint32_t PARKED_PARENT_FLAG = 0x100; | static const uint32_t PARKED_PARENT_FLAG = 0x100; | ||||
// Mask used to check for parked blocks. | // Mask used to check for parked blocks. | ||||
static const uint32_t PARKED_MASK = PARKED_FLAG | PARKED_PARENT_FLAG; | static const uint32_t PARKED_MASK = PARKED_FLAG | PARKED_PARENT_FLAG; | ||||
public: | public: | ||||
explicit BlockStatus() : status(0) {} | explicit constexpr BlockStatus() : status(0) {} | ||||
BlockValidity getValidity() const { | BlockValidity getValidity() const { | ||||
return BlockValidity(status & VALIDITY_MASK); | return BlockValidity(status & VALIDITY_MASK); | ||||
} | } | ||||
BlockStatus withValidity(BlockValidity validity) const { | BlockStatus withValidity(BlockValidity validity) const { | ||||
return BlockStatus((status & ~VALIDITY_MASK) | uint32_t(validity)); | return BlockStatus((status & ~VALIDITY_MASK) | uint32_t(validity)); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | BlockStatus withClearedFailureFlags() const { | ||||
return BlockStatus(status & ~INVALID_MASK); | return BlockStatus(status & ~INVALID_MASK); | ||||
} | } | ||||
bool isOnParkedChain() const { return status & PARKED_MASK; } | bool isOnParkedChain() const { return status & PARKED_MASK; } | ||||
BlockStatus withClearedParkedFlags() const { | BlockStatus withClearedParkedFlags() const { | ||||
return BlockStatus(status & ~PARKED_MASK); | return BlockStatus(status & ~PARKED_MASK); | ||||
} | } | ||||
BlockStatus withReconsideredFlags() const { | |||||
return withClearedFailureFlags().withClearedParkedFlags(); | |||||
} | |||||
ADD_SERIALIZE_METHODS; | ADD_SERIALIZE_METHODS; | ||||
template <typename Stream, typename Operation> | template <typename Stream, typename Operation> | ||||
inline void SerializationOp(Stream &s, Operation ser_action) { | inline void SerializationOp(Stream &s, Operation ser_action) { | ||||
READWRITE(VARINT(status)); | READWRITE(VARINT(status)); | ||||
} | } | ||||
friend constexpr bool operator==(const BlockStatus a, const BlockStatus b) { | |||||
return a.status == b.status; | |||||
} | |||||
friend constexpr bool operator!=(const BlockStatus a, const BlockStatus b) { | |||||
return !(a == b); | |||||
} | |||||
}; | }; | ||||
#endif // BITCOIN_BLOCKSTATUS_H | #endif // BITCOIN_BLOCKSTATUS_H |