Skip to content

Commit d6d8a78

Browse files
committed
Move CDiskBlockPos from chain to flatfile.
1 parent e038093 commit d6d8a78

File tree

3 files changed

+49
-43
lines changed

3 files changed

+49
-43
lines changed

src/chain.h

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include <arith_uint256.h>
1010
#include <consensus/params.h>
11+
#include <flatfile.h>
1112
#include <primitives/block.h>
1213
#include <tinyformat.h>
1314
#include <uint256.h>
@@ -90,46 +91,6 @@ class CBlockFileInfo
9091
}
9192
};
9293

93-
struct CDiskBlockPos
94-
{
95-
int nFile;
96-
unsigned int nPos;
97-
98-
ADD_SERIALIZE_METHODS;
99-
100-
template <typename Stream, typename Operation>
101-
inline void SerializationOp(Stream& s, Operation ser_action) {
102-
READWRITE(VARINT(nFile, VarIntMode::NONNEGATIVE_SIGNED));
103-
READWRITE(VARINT(nPos));
104-
}
105-
106-
CDiskBlockPos() {
107-
SetNull();
108-
}
109-
110-
CDiskBlockPos(int nFileIn, unsigned int nPosIn) {
111-
nFile = nFileIn;
112-
nPos = nPosIn;
113-
}
114-
115-
friend bool operator==(const CDiskBlockPos &a, const CDiskBlockPos &b) {
116-
return (a.nFile == b.nFile && a.nPos == b.nPos);
117-
}
118-
119-
friend bool operator!=(const CDiskBlockPos &a, const CDiskBlockPos &b) {
120-
return !(a == b);
121-
}
122-
123-
void SetNull() { nFile = -1; nPos = 0; }
124-
bool IsNull() const { return (nFile == -1); }
125-
126-
std::string ToString() const
127-
{
128-
return strprintf("CDiskBlockPos(nFile=%i, nPos=%i)", nFile, nPos);
129-
}
130-
131-
};
132-
13394
enum BlockStatus: uint32_t {
13495
//! Unused.
13596
BLOCK_VALID_UNKNOWN = 0,

src/flatfile.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// Copyright (c) 2019 The Bitcoin Core developers
1+
// Copyright (c) 2009-2010 Satoshi Nakamoto
2+
// Copyright (c) 2009-2019 The Bitcoin Core developers
23
// Distributed under the MIT software license, see the accompanying
34
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
45

@@ -19,6 +20,11 @@ FlatFileSeq::FlatFileSeq(fs::path dir, const char* prefix, size_t chunk_size) :
1920
}
2021
}
2122

23+
std::string CDiskBlockPos::ToString() const
24+
{
25+
return strprintf("CDiskBlockPos(nFile=%i, nPos=%i)", nFile, nPos);
26+
}
27+
2228
fs::path FlatFileSeq::FileName(const CDiskBlockPos& pos) const
2329
{
2430
return m_dir / strprintf("%s%05u.dat", m_prefix, pos.nFile);

src/flatfile.h

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,51 @@
1-
// Copyright (c) 2019 The Bitcoin Core developers
1+
// Copyright (c) 2009-2010 Satoshi Nakamoto
2+
// Copyright (c) 2009-2019 The Bitcoin Core developers
23
// Distributed under the MIT software license, see the accompanying
34
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
45

56
#ifndef BITCOIN_FLATFILE_H
67
#define BITCOIN_FLATFILE_H
78

8-
#include <chain.h>
9+
#include <string>
10+
911
#include <fs.h>
12+
#include <serialize.h>
13+
14+
struct CDiskBlockPos
15+
{
16+
int nFile;
17+
unsigned int nPos;
18+
19+
ADD_SERIALIZE_METHODS;
20+
21+
template <typename Stream, typename Operation>
22+
inline void SerializationOp(Stream& s, Operation ser_action) {
23+
READWRITE(VARINT(nFile, VarIntMode::NONNEGATIVE_SIGNED));
24+
READWRITE(VARINT(nPos));
25+
}
26+
27+
CDiskBlockPos() {
28+
SetNull();
29+
}
30+
31+
CDiskBlockPos(int nFileIn, unsigned int nPosIn) {
32+
nFile = nFileIn;
33+
nPos = nPosIn;
34+
}
35+
36+
friend bool operator==(const CDiskBlockPos &a, const CDiskBlockPos &b) {
37+
return (a.nFile == b.nFile && a.nPos == b.nPos);
38+
}
39+
40+
friend bool operator!=(const CDiskBlockPos &a, const CDiskBlockPos &b) {
41+
return !(a == b);
42+
}
43+
44+
void SetNull() { nFile = -1; nPos = 0; }
45+
bool IsNull() const { return (nFile == -1); }
46+
47+
std::string ToString() const;
48+
};
1049

1150
/**
1251
* FlatFileSeq represents a sequence of numbered files storing raw data. This class facilitates

0 commit comments

Comments
 (0)