diff options
Diffstat (limited to 'src/primitives/pureheader.h')
| -rw-r--r-- | src/primitives/pureheader.h | 42 |
1 files changed, 20 insertions, 22 deletions
diff --git a/src/primitives/pureheader.h b/src/primitives/pureheader.h index 449ebbff0..0e4385e6e 100644 --- a/src/primitives/pureheader.h +++ b/src/primitives/pureheader.h @@ -24,7 +24,7 @@ private: static const int32_t VERSION_CHAIN_START = (1 << 16); /** The version as integer. Should not be accessed directly. */ - int32_t nVersion; + int nVersion; public: inline CBlockVersion() @@ -46,29 +46,12 @@ public: } /** - * Extract the base version (without modifiers and chain ID). - * @return The base version./ - */ - inline int32_t GetBaseVersion() const - { - return nVersion % VERSION_AUXPOW; - } - - /** - * Set the base version (apart from chain ID and auxpow flag) to - * the one given. This should only be called when auxpow is not yet - * set, to initialise a block! - * @param nBaseVersion The base version. - */ - void SetBaseVersion(int32_t nBaseVersion); - - /** * Extract the chain ID. * @return The chain ID encoded in the version. */ inline int32_t GetChainId() const { - return nVersion / VERSION_CHAIN_START; + return nVersion >> 16; } /** @@ -123,12 +106,27 @@ public: /** * Check whether this is a "legacy" block without chain ID. - * @return True iff it is. + * @return True if it is. */ inline bool IsLegacy() const { - return nVersion == 1; + return nVersion == 1 + || (nVersion == 2 && GetChainId() == 0); + } + + CBlockVersion& operator=(const int nBaseVersion) + { + nVersion = (nBaseVersion & 0x000000ff) | (nVersion & 0xffffff00); + return *this; } + + operator int() { return nVersion & 0x000000ff; } + friend inline bool operator==(const CBlockVersion a, const int b) { return (a.nVersion & 0x000000ff) == b; } + friend inline bool operator!=(const CBlockVersion a, const int b) { return (a.nVersion & 0x000000ff) != b; } + friend inline bool operator>(const CBlockVersion a, const int b) { return (a.nVersion & 0x000000ff) > b; } + friend inline bool operator<(const CBlockVersion a, const int b) { return (a.nVersion & 0x000000ff) < b; } + friend inline bool operator>=(const CBlockVersion a, const int b) { return (a.nVersion & 0x000000ff) >= b; } + friend inline bool operator<=(const CBlockVersion a, const int b) { return (a.nVersion & 0x000000ff) <= b; } }; /** @@ -161,7 +159,7 @@ public: inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { READWRITE(this->nVersion); - nVersion = this->nVersion.GetBaseVersion(); + nVersion = this->nVersion; READWRITE(hashPrevBlock); READWRITE(hashMerkleRoot); READWRITE(nTime); |