diff --git a/src/chain.h b/src/chain.h --- a/src/chain.h +++ b/src/chain.h @@ -8,6 +8,7 @@ #include "arith_uint256.h" #include "consensus/params.h" +#include "diskblockpos.h" #include "pow.h" #include "primitives/block.h" #include "tinyformat.h" @@ -30,44 +31,6 @@ */ static const int64_t TIMESTAMP_WINDOW = MAX_FUTURE_BLOCK_TIME; -struct CDiskBlockPos { - int nFile; - unsigned int nPos; - - ADD_SERIALIZE_METHODS; - - template - inline void SerializationOp(Stream &s, Operation ser_action) { - READWRITE(VARINT(nFile)); - READWRITE(VARINT(nPos)); - } - - CDiskBlockPos() { SetNull(); } - - CDiskBlockPos(int nFileIn, unsigned int nPosIn) { - nFile = nFileIn; - nPos = nPosIn; - } - - friend bool operator==(const CDiskBlockPos &a, const CDiskBlockPos &b) { - return (a.nFile == b.nFile && a.nPos == b.nPos); - } - - friend bool operator!=(const CDiskBlockPos &a, const CDiskBlockPos &b) { - return !(a == b); - } - - void SetNull() { - nFile = -1; - nPos = 0; - } - bool IsNull() const { return (nFile == -1); } - - std::string ToString() const { - return strprintf("CBlockDiskPos(nFile=%i, nPos=%i)", nFile, nPos); - } -}; - enum class BlockValidity : uint32_t { /** * Unused. diff --git a/src/diskblockpos.h b/src/diskblockpos.h new file mode 100644 --- /dev/null +++ b/src/diskblockpos.h @@ -0,0 +1,51 @@ +// Copyright (c) 2018 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#ifndef BITCOIN_DISKBLOCKPOS_H +#define BITCOIN_DISKBLOCKPOS_H + +#include "serialize.h" +#include "tinyformat.h" + +#include + +struct CDiskBlockPos { + int nFile; + unsigned int nPos; + + ADD_SERIALIZE_METHODS; + + template + inline void SerializationOp(Stream &s, Operation ser_action) { + READWRITE(VARINT(nFile)); + READWRITE(VARINT(nPos)); + } + + CDiskBlockPos() { SetNull(); } + + CDiskBlockPos(int nFileIn, unsigned int nPosIn) { + nFile = nFileIn; + nPos = nPosIn; + } + + friend bool operator==(const CDiskBlockPos &a, const CDiskBlockPos &b) { + return (a.nFile == b.nFile && a.nPos == b.nPos); + } + + friend bool operator!=(const CDiskBlockPos &a, const CDiskBlockPos &b) { + return !(a == b); + } + + void SetNull() { + nFile = -1; + nPos = 0; + } + bool IsNull() const { return (nFile == -1); } + + std::string ToString() const { + return strprintf("CBlockDiskPos(nFile=%i, nPos=%i)", nFile, nPos); + } +}; + +#endif // BITCOIN_DISKBLOCKPOS_H diff --git a/src/init.cpp b/src/init.cpp --- a/src/init.cpp +++ b/src/init.cpp @@ -17,6 +17,7 @@ #include "compat/sanity.h" #include "config.h" #include "consensus/validation.h" +#include "diskblockpos.h" #include "fs.h" #include "httprpc.h" #include "httpserver.h" diff --git a/src/test/blockindex_tests.cpp b/src/test/blockindex_tests.cpp --- a/src/test/blockindex_tests.cpp +++ b/src/test/blockindex_tests.cpp @@ -3,6 +3,7 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include "chain.h" +#include "diskblockpos.h" #include "uint256.h" #include "test/test_bitcoin.h" diff --git a/src/txdb.h b/src/txdb.h --- a/src/txdb.h +++ b/src/txdb.h @@ -6,10 +6,11 @@ #ifndef BITCOIN_TXDB_H #define BITCOIN_TXDB_H -#include "chain.h" #include "blockfileinfo.h" +#include "chain.h" #include "coins.h" #include "dbwrapper.h" +#include "diskblockpos.h" #include #include diff --git a/src/validation.h b/src/validation.h --- a/src/validation.h +++ b/src/validation.h @@ -12,10 +12,11 @@ #endif #include "amount.h" -#include "chain.h" #include "blockfileinfo.h" +#include "chain.h" #include "coins.h" #include "consensus/consensus.h" +#include "diskblockpos.h" #include "fs.h" #include "protocol.h" // For CMessageHeader::MessageMagic #include "script/script_error.h"