diff options
| author | Ross Nicoll <[email protected]> | 2015-07-05 17:45:38 +0100 |
|---|---|---|
| committer | Ross Nicoll <[email protected]> | 2015-07-10 20:23:14 +0100 |
| commit | c453bcc9e5fd98ae4aebd1f2fc85192b5fd7410a (patch) | |
| tree | 0422e17d73ffc244e48ba41c4ea63cd39c8b09dd /src/primitives | |
| parent | Merge AuxPoW support from Namecore (diff) | |
| download | discoin-c453bcc9e5fd98ae4aebd1f2fc85192b5fd7410a.tar.xz discoin-c453bcc9e5fd98ae4aebd1f2fc85192b5fd7410a.zip | |
Adapt AuxPoW to Dogecoin
Changed AuxPoW parent block hashing to use Scrypt rather than SHA256 hash.
Update chain parameters to match Dogecoin
Move CheckProofOfWork into dogecoin.cpp and rename it to CheckAuxPowProofOfWork.
Add operator overrides to CBlockVersion so that naive usage operates on the underlying version without chain ID or flags.
Modify RPC mining to more closely match existing submitblock() structure
Diffstat (limited to 'src/primitives')
| -rw-r--r-- | src/primitives/block.h | 2 | ||||
| -rw-r--r-- | src/primitives/pureheader.cpp | 8 | ||||
| -rw-r--r-- | src/primitives/pureheader.h | 42 |
3 files changed, 21 insertions, 31 deletions
diff --git a/src/primitives/block.h b/src/primitives/block.h index ef2b19010..d59ac4427 100644 --- a/src/primitives/block.h +++ b/src/primitives/block.h @@ -37,7 +37,7 @@ public: template <typename Stream, typename Operation> inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { READWRITE(*(CPureBlockHeader*)this); - nVersion = this->nVersion.GetBaseVersion(); + nVersion = this->nVersion; if (this->nVersion.IsAuxpow()) { if (ser_action.ForRead()) diff --git a/src/primitives/pureheader.cpp b/src/primitives/pureheader.cpp index c90d5fd8e..94f14499b 100644 --- a/src/primitives/pureheader.cpp +++ b/src/primitives/pureheader.cpp @@ -10,14 +10,6 @@ #include "hash.h" #include "utilstrencodings.h" -void CBlockVersion::SetBaseVersion(int32_t nBaseVersion) -{ - assert(nBaseVersion >= 1 && nBaseVersion < VERSION_AUXPOW); - assert(!IsAuxpow()); - const int32_t nChainId = Params().GetConsensus().nAuxpowChainId; - nVersion = nBaseVersion | (nChainId * VERSION_CHAIN_START); -} - uint256 CPureBlockHeader::GetHash() const { return SerializeHash(*this); 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); |