diff --git a/src/Makefile.am b/src/Makefile.am --- a/src/Makefile.am +++ b/src/Makefile.am @@ -91,6 +91,7 @@ base58.h \ bloom.h \ blockencodings.h \ + blockfileinfo.h \ blockindexworkcomparator.h \ cashaddr.h \ cashaddrenc.h \ diff --git a/src/blockfileinfo.h b/src/blockfileinfo.h new file mode 100644 --- /dev/null +++ b/src/blockfileinfo.h @@ -0,0 +1,75 @@ +// Copyright (c) 2018 The Bitcoin developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#ifndef BITCOIN_BLOCKFILEINFO_H +#define BITCOIN_BLOCKFILEINFO_H + +#include "serialize.h" + +#include +#include + +class CBlockFileInfo { +public: + //!< number of blocks stored in file + unsigned int nBlocks; + //!< number of used bytes of block file + unsigned int nSize; + //!< number of used bytes in the undo file + unsigned int nUndoSize; + //!< lowest height of block in file + unsigned int nHeightFirst; + //!< highest height of block in file + unsigned int nHeightLast; + //!< earliest time of block in file + uint64_t nTimeFirst; + //!< latest time of block in file + uint64_t nTimeLast; + + ADD_SERIALIZE_METHODS; + + template + inline void SerializationOp(Stream &s, Operation ser_action) { + READWRITE(VARINT(nBlocks)); + READWRITE(VARINT(nSize)); + READWRITE(VARINT(nUndoSize)); + READWRITE(VARINT(nHeightFirst)); + READWRITE(VARINT(nHeightLast)); + READWRITE(VARINT(nTimeFirst)); + READWRITE(VARINT(nTimeLast)); + } + + void SetNull() { + nBlocks = 0; + nSize = 0; + nUndoSize = 0; + nHeightFirst = 0; + nHeightLast = 0; + nTimeFirst = 0; + nTimeLast = 0; + } + + CBlockFileInfo() { SetNull(); } + + std::string ToString() const; + + /** update statistics (does not update nSize) */ + void AddBlock(unsigned int nHeightIn, uint64_t nTimeIn) { + if (nBlocks == 0 || nHeightFirst > nHeightIn) { + nHeightFirst = nHeightIn; + } + if (nBlocks == 0 || nTimeFirst > nTimeIn) { + nTimeFirst = nTimeIn; + } + nBlocks++; + if (nHeightIn > nHeightLast) { + nHeightLast = nHeightIn; + } + if (nTimeIn > nTimeLast) { + nTimeLast = nTimeIn; + } + } +}; + +#endif // BITCOIN_BLOCKFILEINFO_H diff --git a/src/chain.h b/src/chain.h --- a/src/chain.h +++ b/src/chain.h @@ -30,68 +30,6 @@ */ static const int64_t TIMESTAMP_WINDOW = MAX_FUTURE_BLOCK_TIME; -class CBlockFileInfo { -public: - //!< number of blocks stored in file - unsigned int nBlocks; - //!< number of used bytes of block file - unsigned int nSize; - //!< number of used bytes in the undo file - unsigned int nUndoSize; - //!< lowest height of block in file - unsigned int nHeightFirst; - //!< highest height of block in file - unsigned int nHeightLast; - //!< earliest time of block in file - uint64_t nTimeFirst; - //!< latest time of block in file - uint64_t nTimeLast; - - ADD_SERIALIZE_METHODS; - - template - inline void SerializationOp(Stream &s, Operation ser_action) { - READWRITE(VARINT(nBlocks)); - READWRITE(VARINT(nSize)); - READWRITE(VARINT(nUndoSize)); - READWRITE(VARINT(nHeightFirst)); - READWRITE(VARINT(nHeightLast)); - READWRITE(VARINT(nTimeFirst)); - READWRITE(VARINT(nTimeLast)); - } - - void SetNull() { - nBlocks = 0; - nSize = 0; - nUndoSize = 0; - nHeightFirst = 0; - nHeightLast = 0; - nTimeFirst = 0; - nTimeLast = 0; - } - - CBlockFileInfo() { SetNull(); } - - std::string ToString() const; - - /** update statistics (does not update nSize) */ - void AddBlock(unsigned int nHeightIn, uint64_t nTimeIn) { - if (nBlocks == 0 || nHeightFirst > nHeightIn) { - nHeightFirst = nHeightIn; - } - if (nBlocks == 0 || nTimeFirst > nTimeIn) { - nTimeFirst = nTimeIn; - } - nBlocks++; - if (nHeightIn > nHeightLast) { - nHeightLast = nHeightIn; - } - if (nTimeIn > nTimeLast) { - nTimeLast = nTimeIn; - } - } -}; - struct CDiskBlockPos { int nFile; unsigned int nPos; diff --git a/src/txdb.h b/src/txdb.h --- a/src/txdb.h +++ b/src/txdb.h @@ -6,6 +6,7 @@ #ifndef BITCOIN_TXDB_H #define BITCOIN_TXDB_H +#include "blockfileinfo.h" #include "chain.h" #include "coins.h" #include "dbwrapper.h" diff --git a/src/validation.h b/src/validation.h --- a/src/validation.h +++ b/src/validation.h @@ -12,6 +12,7 @@ #endif #include "amount.h" +#include "blockfileinfo.h" #include "chain.h" #include "coins.h" #include "consensus/consensus.h"