forked from etotheipi/BitcoinArmory
-
Notifications
You must be signed in to change notification settings - Fork 171
/
DatabaseBuilder.h
81 lines (63 loc) · 2.85 KB
/
DatabaseBuilder.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
73
74
75
76
77
78
79
80
81
////////////////////////////////////////////////////////////////////////////////
// //
// Copyright (C) 2016, goatpig. //
// Distributed under the MIT license //
// See LICENSE-MIT or https://opensource.org/licenses/MIT //
// //
////////////////////////////////////////////////////////////////////////////////
#include "BlockDataMap.h"
#include "Blockchain.h"
#include "bdmenums.h"
#include "Progress.h"
class BlockDataManager;
class ScrAddrFilter;
class UnresolvedHashException {};
typedef function<void(BDMPhase, double, unsigned, unsigned)> ProgressCallback;
/////////////////////////////////////////////////////////////////////////////
class DatabaseBuilder
{
private:
BlockFiles& blockFiles_;
shared_ptr<Blockchain> blockchain_;
LMDBBlockDatabase* db_;
shared_ptr<ScrAddrFilter> scrAddrFilter_;
const ProgressCallback progress_;
const BinaryData magicBytes_;
BlockOffset topBlockOffset_;
const BlockDataManagerConfig bdmConfig_;
unsigned checkedTransactions_ = 0;
private:
void findLastKnownBlockPos();
BlockOffset loadBlockHeadersFromDB(const ProgressCallback &progress);
bool addBlocksToDB(
BlockDataLoader& bdl, uint16_t fileID, size_t startOffset,
shared_ptr<BlockOffset> bo, bool fullHints);
void parseBlockFile(const uint8_t* fileMap, size_t fileSize, size_t startOffset,
function<bool(const uint8_t* data, size_t size, size_t offset)>);
Blockchain::ReorganizationState updateBlocksInDB(
const ProgressCallback &progress, bool verbose, bool fullHints);
BinaryData updateTransactionHistory(int32_t startHeight);
BinaryData scanHistory(int32_t startHeight, bool reportprogress);
void undoHistory(Blockchain::ReorganizationState& reorgState);
void resetHistory(void);
void resetSSHdb(void);
bool reparseBlkFiles(unsigned fromID);
map<BinaryData, shared_ptr<BlockHeader>> assessBlkFile(BlockDataLoader& bdl,
unsigned fileID);
void verifyTransactions(void);
void commitAllTxHints(
const map<uint32_t, BlockData>&, const set<unsigned>&);
void commitAllStxos(shared_ptr<BlockDataFileMap>,
const map<uint32_t, BlockData>&, const set<unsigned>&);
void repairTxFilters(const set<unsigned>&);
void reprocessTxFilter(shared_ptr<BlockDataFileMap>, unsigned);
void cycleDatabases(void);
public:
DatabaseBuilder(BlockFiles&, BlockDataManager&,
const ProgressCallback&);
void init(void);
Blockchain::ReorganizationState update(void);
void verifyChain(void);
unsigned getCheckedTxCount(void) const { return checkedTransactions_; }
void verifyTxFilters(void);
};