forked from cryptonotefoundation/cryptonote
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBlockchainIndices.h
executable file
·108 lines (84 loc) · 2.75 KB
/
BlockchainIndices.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// Copyright (c) 2011-2016 The Cryptonote developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#pragma once
#include <string>
#include <unordered_map>
#include <map>
#include "crypto/hash.h"
#include "CryptoNoteBasic.h"
namespace CryptoNote {
class ISerializer;
class PaymentIdIndex {
public:
PaymentIdIndex() = default;
bool add(const Transaction& transaction);
bool remove(const Transaction& transaction);
bool find(const Crypto::Hash& paymentId, std::vector<Crypto::Hash>& transactionHashes);
void clear();
void serialize(ISerializer& s);
template<class Archive>
void serialize(Archive& archive, unsigned int version) {
archive & index;
}
private:
std::unordered_multimap<Crypto::Hash, Crypto::Hash> index;
};
class TimestampBlocksIndex {
public:
TimestampBlocksIndex() = default;
bool add(uint64_t timestamp, const Crypto::Hash& hash);
bool remove(uint64_t timestamp, const Crypto::Hash& hash);
bool find(uint64_t timestampBegin, uint64_t timestampEnd, uint32_t hashesNumberLimit, std::vector<Crypto::Hash>& hashes, uint32_t& hashesNumberWithinTimestamps);
void clear();
void serialize(ISerializer& s);
template<class Archive>
void serialize(Archive& archive, unsigned int version) {
archive & index;
}
private:
std::multimap<uint64_t, Crypto::Hash> index;
};
class TimestampTransactionsIndex {
public:
TimestampTransactionsIndex() = default;
bool add(uint64_t timestamp, const Crypto::Hash& hash);
bool remove(uint64_t timestamp, const Crypto::Hash& hash);
bool find(uint64_t timestampBegin, uint64_t timestampEnd, uint64_t hashesNumberLimit, std::vector<Crypto::Hash>& hashes, uint64_t& hashesNumberWithinTimestamps);
void clear();
void serialize(ISerializer& s);
template<class Archive>
void serialize(Archive& archive, unsigned int version) {
archive & index;
}
private:
std::multimap<uint64_t, Crypto::Hash> index;
};
class GeneratedTransactionsIndex {
public:
GeneratedTransactionsIndex();
bool add(const Block& block);
bool remove(const Block& block);
bool find(uint32_t height, uint64_t& generatedTransactions);
void clear();
void serialize(ISerializer& s);
template<class Archive>
void serialize(Archive& archive, unsigned int version) {
archive & index;
archive & lastGeneratedTxNumber;
}
private:
std::unordered_map<uint32_t, uint64_t> index;
uint64_t lastGeneratedTxNumber;
};
class OrphanBlocksIndex {
public:
OrphanBlocksIndex() = default;
bool add(const Block& block);
bool remove(const Block& block);
bool find(uint32_t height, std::vector<Crypto::Hash>& blockHashes);
void clear();
private:
std::unordered_multimap<uint32_t, Crypto::Hash> index;
};
}