forked from Bitcoin-ABC/bitcoin-abc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblockfileinfo.h
72 lines (62 loc) · 1.92 KB
/
blockfileinfo.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Copyright (c) 2018-2020 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 <cstdint>
#include <string>
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;
SERIALIZE_METHODS(CBlockFileInfo, obj) {
READWRITE(VARINT(obj.nBlocks));
READWRITE(VARINT(obj.nSize));
READWRITE(VARINT(obj.nUndoSize));
READWRITE(VARINT(obj.nHeightFirst));
READWRITE(VARINT(obj.nHeightLast));
READWRITE(VARINT(obj.nTimeFirst));
READWRITE(VARINT(obj.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