aboutsummaryrefslogtreecommitdiff
path: root/src/main.h
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2012-11-14 22:18:10 +0100
committerPieter Wuille <pieter.wuille@gmail.com>2012-11-16 00:12:33 +0100
commite754cf4133c9c97e320ae5dec394e338524e650b (patch)
treeb2cf9b6c6c9d7f462c0e9874626093955c928a46 /src/main.h
parent6caffb5358b1e403b293846b3c832433fa928e46 (diff)
downloadbitcoin-e754cf4133c9c97e320ae5dec394e338524e650b.tar.xz
Split off CBlockHeader from CBlock
Cleaner and removes the need for the application-specific flags in serialize.h.
Diffstat (limited to 'src/main.h')
-rw-r--r--src/main.h77
1 files changed, 47 insertions, 30 deletions
diff --git a/src/main.h b/src/main.h
index 0ef192f901..994d0bfb6c 100644
--- a/src/main.h
+++ b/src/main.h
@@ -1068,7 +1068,7 @@ public:
* in the block is a special one that creates a new coin owned by the creator
* of the block.
*/
-class CBlock
+class CBlockHeader
{
public:
// header
@@ -1080,17 +1080,7 @@ public:
unsigned int nBits;
unsigned int nNonce;
- // network and disk
- std::vector<CTransaction> vtx;
-
- // memory only
- mutable std::vector<uint256> vMerkleTree;
-
- // Denial-of-service detection:
- mutable int nDoS;
- bool DoS(int nDoSIn, bool fIn) const { nDoS += nDoSIn; return fIn; }
-
- CBlock()
+ CBlockHeader()
{
SetNull();
}
@@ -1104,25 +1094,16 @@ public:
READWRITE(nTime);
READWRITE(nBits);
READWRITE(nNonce);
-
- // ConnectBlock depends on vtx being last so it can calculate offset
- if (!(nType & (SER_GETHASH|SER_BLOCKHEADERONLY)))
- READWRITE(vtx);
- else if (fRead)
- const_cast<CBlock*>(this)->vtx.clear();
)
void SetNull()
{
- nVersion = CBlock::CURRENT_VERSION;
+ nVersion = CBlockHeader::CURRENT_VERSION;
hashPrevBlock = 0;
hashMerkleRoot = 0;
nTime = 0;
nBits = 0;
nNonce = 0;
- vtx.clear();
- vMerkleTree.clear();
- nDoS = 0;
}
bool IsNull() const
@@ -1141,7 +1122,45 @@ public:
}
void UpdateTime(const CBlockIndex* pindexPrev);
+};
+
+class CBlock : public CBlockHeader
+{
+public:
+ // network and disk
+ std::vector<CTransaction> vtx;
+
+ // memory only
+ mutable std::vector<uint256> vMerkleTree;
+ // Denial-of-service detection:
+ mutable int nDoS;
+ bool DoS(int nDoSIn, bool fIn) const { nDoS += nDoSIn; return fIn; }
+
+ CBlock()
+ {
+ SetNull();
+ }
+
+ CBlock(const CBlockHeader &header)
+ {
+ SetNull();
+ *((CBlockHeader*)this) = header;
+ }
+
+ IMPLEMENT_SERIALIZE
+ (
+ READWRITE(*(CBlockHeader*)this);
+ READWRITE(vtx);
+ )
+
+ void SetNull()
+ {
+ CBlockHeader::SetNull();
+ vtx.clear();
+ vMerkleTree.clear();
+ nDoS = 0;
+ }
uint256 BuildMerkleTree() const
{
@@ -1226,7 +1245,7 @@ public:
return true;
}
- bool ReadFromDisk(const CDiskBlockPos &pos, bool fReadTransactions = true)
+ bool ReadFromDisk(const CDiskBlockPos &pos)
{
SetNull();
@@ -1234,8 +1253,6 @@ public:
CAutoFile filein = CAutoFile(OpenBlockFile(pos, true), SER_DISK, CLIENT_VERSION);
if (!filein)
return error("CBlock::ReadFromDisk() : OpenBlockFile failed");
- if (!fReadTransactions)
- filein.nType |= SER_BLOCKHEADERONLY;
// Read block
try {
@@ -1282,7 +1299,7 @@ public:
bool ConnectBlock(CBlockIndex *pindex, CCoinsViewCache &coins, bool fJustCheck=false);
// Read a block from disk
- bool ReadFromDisk(const CBlockIndex* pindex, bool fReadTransactions=true);
+ bool ReadFromDisk(const CBlockIndex* pindex);
// Add this block to the block index, and if necessary, switch the active block chain to this
bool AddToBlockIndex(const CDiskBlockPos &pos);
@@ -1447,7 +1464,7 @@ public:
nNonce = 0;
}
- CBlockIndex(CBlock& block)
+ CBlockIndex(CBlockHeader& block)
{
phashBlock = NULL;
pprev = NULL;
@@ -1488,9 +1505,9 @@ public:
return ret;
}
- CBlock GetBlockHeader() const
+ CBlockHeader GetBlockHeader() const
{
- CBlock block;
+ CBlockHeader block;
block.nVersion = nVersion;
if (pprev)
block.hashPrevBlock = pprev->GetBlockHash();
@@ -1634,7 +1651,7 @@ public:
uint256 GetBlockHash() const
{
- CBlock block;
+ CBlockHeader block;
block.nVersion = nVersion;
block.hashPrevBlock = hashPrev;
block.hashMerkleRoot = hashMerkleRoot;