aboutsummaryrefslogtreecommitdiff
path: root/src/primitives/block.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/primitives/block.h')
-rw-r--r--src/primitives/block.h59
1 files changed, 26 insertions, 33 deletions
diff --git a/src/primitives/block.h b/src/primitives/block.h
index 9bc06ad6b..1c3243bb3 100644
--- a/src/primitives/block.h
+++ b/src/primitives/block.h
@@ -6,10 +6,14 @@
#ifndef BITCOIN_PRIMITIVES_BLOCK_H
#define BITCOIN_PRIMITIVES_BLOCK_H
+#include <auxpow.h>
#include <primitives/transaction.h>
+#include <primitives/pureheader.h>
#include <serialize.h>
#include <uint256.h>
+#include <memory>
+
/** Nodes collect new transactions into a block, hash them into a hash tree,
* and scan through nonce values to make the block's hash satisfy proof-of-work
* requirements. When they solve the proof-of-work, they broadcast the block
@@ -17,16 +21,12 @@
* in the block is a special one that creates a new coin owned by the creator
* of the block.
*/
-class CBlockHeader
+class CBlockHeader : public CPureBlockHeader
{
public:
- // header
- int32_t nVersion;
- uint256 hashPrevBlock;
- uint256 hashMerkleRoot;
- uint32_t nTime;
- uint32_t nBits;
- uint32_t nNonce;
+
+ // auxpow (if this is a merge-minded block)
+ std::shared_ptr<CAuxPow> auxpow;
CBlockHeader()
{
@@ -37,37 +37,29 @@ public:
template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action) {
- READWRITE(this->nVersion);
- READWRITE(hashPrevBlock);
- READWRITE(hashMerkleRoot);
- READWRITE(nTime);
- READWRITE(nBits);
- READWRITE(nNonce);
+ READWRITE(*(CPureBlockHeader*)this);
+
+ if (this->IsAuxpow())
+ {
+ if (ser_action.ForRead())
+ auxpow = std::make_shared<CAuxPow>();
+ assert(auxpow != nullptr);
+ READWRITE(*auxpow);
+ } else if (ser_action.ForRead())
+ auxpow.reset();
}
void SetNull()
{
- nVersion = 0;
- hashPrevBlock.SetNull();
- hashMerkleRoot.SetNull();
- nTime = 0;
- nBits = 0;
- nNonce = 0;
- }
-
- bool IsNull() const
- {
- return (nBits == 0);
+ CPureBlockHeader::SetNull();
+ auxpow.reset();
}
- uint256 GetHash() const;
-
- uint256 GetPoWHash() const;
-
- int64_t GetBlockTime() const
- {
- return (int64_t)nTime;
- }
+ /**
+ * Set the block's auxpow (or unset it). This takes care of updating
+ * the version accordingly.
+ */
+ void SetAuxpow (std::unique_ptr<CAuxPow> apow);
};
@@ -115,6 +107,7 @@ public:
block.nTime = nTime;
block.nBits = nBits;
block.nNonce = nNonce;
+ block.auxpow = auxpow;
return block;
}