Coverage Report

Created: 2026-06-16 16:41

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/tmp/bitcoin/src/dbwrapper.h
Line
Count
Source
1
// Copyright (c) 2012-present The Bitcoin Core developers
2
// Distributed under the MIT software license, see the accompanying
3
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5
#ifndef BITCOIN_DBWRAPPER_H
6
#define BITCOIN_DBWRAPPER_H
7
8
#include <attributes.h>
9
#include <serialize.h>
10
#include <span.h>
11
#include <streams.h>
12
#include <util/byte_units.h>
13
#include <util/check.h>
14
#include <util/fs.h>
15
16
#include <cstddef>
17
#include <exception>
18
#include <memory>
19
#include <optional>
20
#include <stdexcept>
21
#include <string>
22
23
namespace leveldb {
24
class Env;
25
} // namespace leveldb
26
27
static const size_t DBWRAPPER_PREALLOC_KEY_SIZE = 64;
28
static const size_t DBWRAPPER_PREALLOC_VALUE_SIZE = 1024;
29
static const size_t DBWRAPPER_MAX_FILE_SIZE{32_MiB};
30
31
//! User-controlled performance and debug options.
32
struct DBOptions {
33
    //! Compact database on startup.
34
    bool force_compact = false;
35
};
36
37
//! Application-specific storage settings.
38
struct DBParams {
39
    //! Location in the filesystem where leveldb data will be stored.
40
    fs::path path;
41
    //! Configures various leveldb cache settings.
42
    size_t cache_bytes;
43
    //! If true, use leveldb's memory environment.
44
    bool memory_only = false;
45
    //! If true, remove all existing data.
46
    bool wipe_data = false;
47
    //! If true, store data obfuscated via simple XOR. If false, XOR with a
48
    //! zero'd byte array.
49
    bool obfuscate = false;
50
    //! Passed-through options.
51
    DBOptions options{};
52
    //! If non-null, use this as the leveldb::Env instead of the default.
53
    //! Caller retains ownership.
54
    leveldb::Env* testing_env = nullptr;
55
    //! Maximum LevelDB SST file size. Larger values reduce the frequency
56
    //! of compactions but increase their duration.
57
    size_t max_file_size = DBWRAPPER_MAX_FILE_SIZE;
58
};
59
60
class dbwrapper_error : public std::runtime_error
61
{
62
public:
63
10
    explicit dbwrapper_error(const std::string& msg) : std::runtime_error(msg) {}
64
};
65
66
class CDBWrapper;
67
68
/** These should be considered an implementation detail of the specific database.
69
 */
70
namespace dbwrapper_private {
71
72
/** Work around circular dependency, as well as for testing in dbwrapper_tests.
73
 * Database obfuscation should be considered an implementation detail of the
74
 * specific database.
75
 */
76
const Obfuscation& GetObfuscation(const CDBWrapper&);
77
}; // namespace dbwrapper_private
78
79
bool DestroyDB(const std::string& path_str);
80
81
/** Batch of changes queued to be written to a CDBWrapper */
82
class CDBBatch
83
{
84
    friend class CDBWrapper;
85
86
private:
87
    const CDBWrapper &parent;
88
89
    struct WriteBatchImpl;
90
    const std::unique_ptr<WriteBatchImpl> m_impl_batch;
91
92
    DataStream m_key_scratch{};
93
    DataStream m_value_scratch{};
94
95
    void WriteImpl(std::span<const std::byte> key, DataStream& value);
96
    void EraseImpl(std::span<const std::byte> key);
97
98
public:
99
    /**
100
     * @param[in] _parent   CDBWrapper that this batch is to be submitted to
101
     */
102
    explicit CDBBatch(const CDBWrapper& _parent);
103
    ~CDBBatch();
104
    void Clear();
105
106
    template <typename K, typename V>
107
    void Write(const K& key, const V& value)
108
423k
    {
109
423k
        ScopedDataStreamUsage scoped_key{m_key_scratch}, scoped_value{m_value_scratch};
110
423k
        m_key_scratch << key;
111
423k
        m_value_scratch << value;
112
423k
        WriteImpl(m_key_scratch, m_value_scratch);
113
423k
    }
void CDBBatch::Write<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, uint256>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, uint256 const&)
Line
Count
Source
108
8
    {
109
8
        ScopedDataStreamUsage scoped_key{m_key_scratch}, scoped_value{m_value_scratch};
110
8
        m_key_scratch << key;
111
8
        m_value_scratch << value;
112
8
        WriteImpl(m_key_scratch, m_value_scratch);
113
8
    }
void CDBBatch::Write<unsigned char, unsigned int>(unsigned char const&, unsigned int const&)
Line
Count
Source
108
258
    {
109
258
        ScopedDataStreamUsage scoped_key{m_key_scratch}, scoped_value{m_value_scratch};
110
258
        m_key_scratch << key;
111
258
        m_value_scratch << value;
112
258
        WriteImpl(m_key_scratch, m_value_scratch);
113
258
    }
void CDBBatch::Write<unsigned char, bool>(unsigned char const&, bool const&)
Line
Count
Source
108
2
    {
109
2
        ScopedDataStreamUsage scoped_key{m_key_scratch}, scoped_value{m_value_scratch};
110
2
        m_key_scratch << key;
111
2
        m_value_scratch << value;
112
2
        WriteImpl(m_key_scratch, m_value_scratch);
113
2
    }
void CDBBatch::Write<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, bool>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, bool const&)
Line
Count
Source
108
2
    {
109
2
        ScopedDataStreamUsage scoped_key{m_key_scratch}, scoped_value{m_value_scratch};
110
2
        m_key_scratch << key;
111
2
        m_value_scratch << value;
112
2
        WriteImpl(m_key_scratch, m_value_scratch);
113
2
    }
void CDBBatch::Write<unsigned char, uint256>(unsigned char const&, uint256 const&)
Line
Count
Source
108
3.77k
    {
109
3.77k
        ScopedDataStreamUsage scoped_key{m_key_scratch}, scoped_value{m_value_scratch};
110
3.77k
        m_key_scratch << key;
111
3.77k
        m_value_scratch << value;
112
3.77k
        WriteImpl(m_key_scratch, m_value_scratch);
113
3.77k
    }
void CDBBatch::Write<dbwrapper_tests::StringContentsSerializer, unsigned int>(dbwrapper_tests::StringContentsSerializer const&, unsigned int const&)
Line
Count
Source
108
100
    {
109
100
        ScopedDataStreamUsage scoped_key{m_key_scratch}, scoped_value{m_value_scratch};
110
100
        m_key_scratch << key;
111
100
        m_value_scratch << value;
112
100
        WriteImpl(m_key_scratch, m_value_scratch);
113
100
    }
void CDBBatch::Write<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, Obfuscation>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, Obfuscation const&)
Line
Count
Source
108
512
    {
109
512
        ScopedDataStreamUsage scoped_key{m_key_scratch}, scoped_value{m_value_scratch};
110
512
        m_key_scratch << key;
111
512
        m_value_scratch << value;
112
512
        WriteImpl(m_key_scratch, m_value_scratch);
113
512
    }
void CDBBatch::Write<unsigned char, CBlockLocator>(unsigned char const&, CBlockLocator const&)
Line
Count
Source
108
281
    {
109
281
        ScopedDataStreamUsage scoped_key{m_key_scratch}, scoped_value{m_value_scratch};
110
281
        m_key_scratch << key;
111
281
        m_value_scratch << value;
112
281
        WriteImpl(m_key_scratch, m_value_scratch);
113
281
    }
void CDBBatch::Write<unsigned char, FlatFilePos>(unsigned char const&, FlatFilePos const&)
Line
Count
Source
108
182
    {
109
182
        ScopedDataStreamUsage scoped_key{m_key_scratch}, scoped_value{m_value_scratch};
110
182
        m_key_scratch << key;
111
182
        m_value_scratch << value;
112
182
        WriteImpl(m_key_scratch, m_value_scratch);
113
182
    }
blockfilterindex.cpp:void CDBBatch::Write<index_util::DBHeightKey, std::pair<uint256, (anonymous namespace)::DBVal>>(index_util::DBHeightKey const&, std::pair<uint256, (anonymous namespace)::DBVal> const&)
Line
Count
Source
108
7.54k
    {
109
7.54k
        ScopedDataStreamUsage scoped_key{m_key_scratch}, scoped_value{m_value_scratch};
110
7.54k
        m_key_scratch << key;
111
7.54k
        m_value_scratch << value;
112
7.54k
        WriteImpl(m_key_scratch, m_value_scratch);
113
7.54k
    }
blockfilterindex.cpp:void CDBBatch::Write<index_util::DBHashKey, (anonymous namespace)::DBVal>(index_util::DBHashKey const&, (anonymous namespace)::DBVal const&)
Line
Count
Source
108
111
    {
109
111
        ScopedDataStreamUsage scoped_key{m_key_scratch}, scoped_value{m_value_scratch};
110
111
        m_key_scratch << key;
111
111
        m_value_scratch << value;
112
111
        WriteImpl(m_key_scratch, m_value_scratch);
113
111
    }
coinstatsindex.cpp:void CDBBatch::Write<index_util::DBHeightKey, std::pair<uint256, (anonymous namespace)::DBVal>>(index_util::DBHeightKey const&, std::pair<uint256, (anonymous namespace)::DBVal> const&)
Line
Count
Source
108
3.86k
    {
109
3.86k
        ScopedDataStreamUsage scoped_key{m_key_scratch}, scoped_value{m_value_scratch};
110
3.86k
        m_key_scratch << key;
111
3.86k
        m_value_scratch << value;
112
3.86k
        WriteImpl(m_key_scratch, m_value_scratch);
113
3.86k
    }
coinstatsindex.cpp:void CDBBatch::Write<index_util::DBHashKey, (anonymous namespace)::DBVal>(index_util::DBHashKey const&, (anonymous namespace)::DBVal const&)
Line
Count
Source
108
121
    {
109
121
        ScopedDataStreamUsage scoped_key{m_key_scratch}, scoped_value{m_value_scratch};
110
121
        m_key_scratch << key;
111
121
        m_value_scratch << value;
112
121
        WriteImpl(m_key_scratch, m_value_scratch);
113
121
    }
void CDBBatch::Write<unsigned char, MuHash3072>(unsigned char const&, MuHash3072 const&)
Line
Count
Source
108
124
    {
109
124
        ScopedDataStreamUsage scoped_key{m_key_scratch}, scoped_value{m_value_scratch};
110
124
        m_key_scratch << key;
111
124
        m_value_scratch << value;
112
124
        WriteImpl(m_key_scratch, m_value_scratch);
113
124
    }
void CDBBatch::Write<std::pair<unsigned char, uint256>, CDiskTxPos>(std::pair<unsigned char, uint256> const&, CDiskTxPos const&)
Line
Count
Source
108
3.74k
    {
109
3.74k
        ScopedDataStreamUsage scoped_key{m_key_scratch}, scoped_value{m_value_scratch};
110
3.74k
        m_key_scratch << key;
111
3.74k
        m_value_scratch << value;
112
3.74k
        WriteImpl(m_key_scratch, m_value_scratch);
113
3.74k
    }
void CDBBatch::Write<char [12], std::pair<unsigned long, unsigned long>>(char const (&) [12], std::pair<unsigned long, unsigned long> const&)
Line
Count
Source
108
6
    {
109
6
        ScopedDataStreamUsage scoped_key{m_key_scratch}, scoped_value{m_value_scratch};
110
6
        m_key_scratch << key;
111
6
        m_value_scratch << value;
112
6
        WriteImpl(m_key_scratch, m_value_scratch);
113
6
    }
void CDBBatch::Write<DBKey, char [1]>(DBKey const&, char const (&) [1])
Line
Count
Source
108
38
    {
109
38
        ScopedDataStreamUsage scoped_key{m_key_scratch}, scoped_value{m_value_scratch};
110
38
        m_key_scratch << key;
111
38
        m_value_scratch << value;
112
38
        WriteImpl(m_key_scratch, m_value_scratch);
113
38
    }
void CDBBatch::Write<unsigned char, unsigned char>(unsigned char const&, unsigned char const&)
Line
Count
Source
108
14
    {
109
14
        ScopedDataStreamUsage scoped_key{m_key_scratch}, scoped_value{m_value_scratch};
110
14
        m_key_scratch << key;
111
14
        m_value_scratch << value;
112
14
        WriteImpl(m_key_scratch, m_value_scratch);
113
14
    }
void CDBBatch::Write<std::pair<unsigned char, int>, kernel::CBlockFileInfo>(std::pair<unsigned char, int> const&, kernel::CBlockFileInfo const&)
Line
Count
Source
108
1.64k
    {
109
1.64k
        ScopedDataStreamUsage scoped_key{m_key_scratch}, scoped_value{m_value_scratch};
110
1.64k
        m_key_scratch << key;
111
1.64k
        m_value_scratch << value;
112
1.64k
        WriteImpl(m_key_scratch, m_value_scratch);
113
1.64k
    }
void CDBBatch::Write<unsigned char, int>(unsigned char const&, int const&)
Line
Count
Source
108
3.42k
    {
109
3.42k
        ScopedDataStreamUsage scoped_key{m_key_scratch}, scoped_value{m_value_scratch};
110
3.42k
        m_key_scratch << key;
111
3.42k
        m_value_scratch << value;
112
3.42k
        WriteImpl(m_key_scratch, m_value_scratch);
113
3.42k
    }
void CDBBatch::Write<std::pair<unsigned char, uint256>, CDiskBlockIndex>(std::pair<unsigned char, uint256> const&, CDiskBlockIndex const&)
Line
Count
Source
108
119k
    {
109
119k
        ScopedDataStreamUsage scoped_key{m_key_scratch}, scoped_value{m_value_scratch};
110
119k
        m_key_scratch << key;
111
119k
        m_value_scratch << value;
112
119k
        WriteImpl(m_key_scratch, m_value_scratch);
113
119k
    }
void CDBBatch::Write<std::pair<unsigned char, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, unsigned char>(std::pair<unsigned char, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>> const&, unsigned char const&)
Line
Count
Source
108
8
    {
109
8
        ScopedDataStreamUsage scoped_key{m_key_scratch}, scoped_value{m_value_scratch};
110
8
        m_key_scratch << key;
111
8
        m_value_scratch << value;
112
8
        WriteImpl(m_key_scratch, m_value_scratch);
113
8
    }
void CDBBatch::Write<unsigned char, std::vector<uint256, std::allocator<uint256>>>(unsigned char const&, std::vector<uint256, std::allocator<uint256>> const&)
Line
Count
Source
108
3.73k
    {
109
3.73k
        ScopedDataStreamUsage scoped_key{m_key_scratch}, scoped_value{m_value_scratch};
110
3.73k
        m_key_scratch << key;
111
3.73k
        m_value_scratch << value;
112
3.73k
        WriteImpl(m_key_scratch, m_value_scratch);
113
3.73k
    }
txdb.cpp:void CDBBatch::Write<(anonymous namespace)::CoinEntry, Coin>((anonymous namespace)::CoinEntry const&, Coin const&)
Line
Count
Source
108
274k
    {
109
274k
        ScopedDataStreamUsage scoped_key{m_key_scratch}, scoped_value{m_value_scratch};
110
274k
        m_key_scratch << key;
111
274k
        m_value_scratch << value;
112
274k
        WriteImpl(m_key_scratch, m_value_scratch);
113
274k
    }
114
115
    template <typename K>
116
    void Erase(const K& key)
117
41.3k
    {
118
41.3k
        ScopedDataStreamUsage scoped_key{m_key_scratch};
119
41.3k
        m_key_scratch << key;
120
41.3k
        EraseImpl(m_key_scratch);
121
41.3k
    }
void CDBBatch::Erase<unsigned char>(unsigned char const&)
Line
Count
Source
117
7.49k
    {
118
7.49k
        ScopedDataStreamUsage scoped_key{m_key_scratch};
119
7.49k
        m_key_scratch << key;
120
7.49k
        EraseImpl(m_key_scratch);
121
7.49k
    }
void CDBBatch::Erase<DBKey>(DBKey const&)
Line
Count
Source
117
6
    {
118
6
        ScopedDataStreamUsage scoped_key{m_key_scratch};
119
6
        m_key_scratch << key;
120
6
        EraseImpl(m_key_scratch);
121
6
    }
txdb.cpp:void CDBBatch::Erase<(anonymous namespace)::CoinEntry>((anonymous namespace)::CoinEntry const&)
Line
Count
Source
117
33.8k
    {
118
33.8k
        ScopedDataStreamUsage scoped_key{m_key_scratch};
119
33.8k
        m_key_scratch << key;
120
33.8k
        EraseImpl(m_key_scratch);
121
33.8k
    }
122
123
    size_t ApproximateSize() const;
124
};
125
126
class CDBIterator
127
{
128
public:
129
    struct IteratorImpl;
130
131
private:
132
    const CDBWrapper &parent;
133
    const std::unique_ptr<IteratorImpl> m_impl_iter;
134
    DataStream m_scratch{};
135
136
    void SeekImpl(std::span<const std::byte> key);
137
    std::span<const std::byte> GetKeyImpl() const;
138
    std::span<const std::byte> GetValueImpl() const;
139
140
public:
141
142
    /**
143
     * @param[in] _parent          Parent CDBWrapper instance.
144
     * @param[in] _piter           The original leveldb iterator.
145
     */
146
    CDBIterator(const CDBWrapper& _parent, std::unique_ptr<IteratorImpl> _piter);
147
    ~CDBIterator();
148
149
    bool Valid() const;
150
151
    void SeekToFirst();
152
153
4.35k
    template<typename K> void Seek(const K& key) {
154
4.35k
        ScopedDataStreamUsage scoped_scratch{m_scratch};
155
4.35k
        m_scratch << key;
156
4.35k
        SeekImpl(m_scratch);
157
4.35k
    }
void CDBIterator::Seek<unsigned char>(unsigned char const&)
Line
Count
Source
153
1.24k
    template<typename K> void Seek(const K& key) {
154
1.24k
        ScopedDataStreamUsage scoped_scratch{m_scratch};
155
1.24k
        m_scratch << key;
156
1.24k
        SeekImpl(m_scratch);
157
1.24k
    }
void CDBIterator::Seek<dbwrapper_tests::StringContentsSerializer>(dbwrapper_tests::StringContentsSerializer const&)
Line
Count
Source
153
2
    template<typename K> void Seek(const K& key) {
154
2
        ScopedDataStreamUsage scoped_scratch{m_scratch};
155
2
        m_scratch << key;
156
2
        SeekImpl(m_scratch);
157
2
    }
void CDBIterator::Seek<index_util::DBHeightKey>(index_util::DBHeightKey const&)
Line
Count
Source
153
680
    template<typename K> void Seek(const K& key) {
154
680
        ScopedDataStreamUsage scoped_scratch{m_scratch};
155
680
        m_scratch << key;
156
680
        SeekImpl(m_scratch);
157
680
    }
void CDBIterator::Seek<std::pair<unsigned char, unsigned long>>(std::pair<unsigned char, unsigned long> const&)
Line
Count
Source
153
35
    template<typename K> void Seek(const K& key) {
154
35
        ScopedDataStreamUsage scoped_scratch{m_scratch};
155
35
        m_scratch << key;
156
35
        SeekImpl(m_scratch);
157
35
    }
void CDBIterator::Seek<std::pair<unsigned char, uint256>>(std::pair<unsigned char, uint256> const&)
Line
Count
Source
153
2.39k
    template<typename K> void Seek(const K& key) {
154
2.39k
        ScopedDataStreamUsage scoped_scratch{m_scratch};
155
2.39k
        m_scratch << key;
156
2.39k
        SeekImpl(m_scratch);
157
2.39k
    }
158
159
    void Next();
160
161
366k
    template<typename K> bool GetKey(K& key) {
162
366k
        try {
163
366k
            SpanReader ssKey{GetKeyImpl()};
164
366k
            ssKey >> key;
165
366k
        } catch (const std::exception&) {
166
746
            return false;
167
746
        }
168
365k
        return true;
169
366k
    }
bool CDBIterator::GetKey<unsigned short>(unsigned short&)
Line
Count
Source
161
2
    template<typename K> bool GetKey(K& key) {
162
2
        try {
163
2
            SpanReader ssKey{GetKeyImpl()};
164
2
            ssKey >> key;
165
2
        } catch (const std::exception&) {
166
2
            return false;
167
2
        }
168
0
        return true;
169
2
    }
bool CDBIterator::GetKey<unsigned char>(unsigned char&)
Line
Count
Source
161
390
    template<typename K> bool GetKey(K& key) {
162
390
        try {
163
390
            SpanReader ssKey{GetKeyImpl()};
164
390
            ssKey >> key;
165
390
        } catch (const std::exception&) {
166
0
            return false;
167
0
        }
168
390
        return true;
169
390
    }
bool CDBIterator::GetKey<dbwrapper_tests::StringContentsSerializer>(dbwrapper_tests::StringContentsSerializer&)
Line
Count
Source
161
150
    template<typename K> bool GetKey(K& key) {
162
150
        try {
163
150
            SpanReader ssKey{GetKeyImpl()};
164
150
            ssKey >> key;
165
150
        } catch (const std::exception&) {
166
0
            return false;
167
0
        }
168
150
        return true;
169
150
    }
bool CDBIterator::GetKey<index_util::DBHeightKey>(index_util::DBHeightKey&)
Line
Count
Source
161
3.09k
    template<typename K> bool GetKey(K& key) {
162
3.09k
        try {
163
3.09k
            SpanReader ssKey{GetKeyImpl()};
164
3.09k
            ssKey >> key;
165
3.09k
        } catch (const std::exception&) {
166
0
            return false;
167
0
        }
168
3.09k
        return true;
169
3.09k
    }
bool CDBIterator::GetKey<DBKey>(DBKey&)
Line
Count
Source
161
23
    template<typename K> bool GetKey(K& key) {
162
23
        try {
163
23
            SpanReader ssKey{GetKeyImpl()};
164
23
            ssKey >> key;
165
23
        } catch (const std::exception&) {
166
0
            return false;
167
0
        }
168
23
        return true;
169
23
    }
bool CDBIterator::GetKey<std::pair<unsigned char, uint256>>(std::pair<unsigned char, uint256>&)
Line
Count
Source
161
135k
    template<typename K> bool GetKey(K& key) {
162
135k
        try {
163
135k
            SpanReader ssKey{GetKeyImpl()};
164
135k
            ssKey >> key;
165
135k
        } catch (const std::exception&) {
166
744
            return false;
167
744
        }
168
135k
        return true;
169
135k
    }
txdb.cpp:bool CDBIterator::GetKey<(anonymous namespace)::CoinEntry>((anonymous namespace)::CoinEntry&)
Line
Count
Source
161
226k
    template<typename K> bool GetKey(K& key) {
162
226k
        try {
163
226k
            SpanReader ssKey{GetKeyImpl()};
164
226k
            ssKey >> key;
165
226k
        } catch (const std::exception&) {
166
0
            return false;
167
0
        }
168
226k
        return true;
169
226k
    }
170
171
365k
    template<typename V> bool GetValue(V& value) {
172
365k
        try {
173
365k
            ScopedDataStreamUsage scoped_scratch{m_scratch};
174
365k
            m_scratch.write(GetValueImpl());
175
365k
            dbwrapper_private::GetObfuscation(parent)(m_scratch);
176
365k
            m_scratch >> value;
177
365k
        } catch (const std::exception&) {
178
2
            return false;
179
2
        }
180
365k
        return true;
181
365k
    }
bool CDBIterator::GetValue<std::pair<uint256, unsigned char>>(std::pair<uint256, unsigned char>&)
Line
Count
Source
171
2
    template<typename V> bool GetValue(V& value) {
172
2
        try {
173
2
            ScopedDataStreamUsage scoped_scratch{m_scratch};
174
2
            m_scratch.write(GetValueImpl());
175
2
            dbwrapper_private::GetObfuscation(parent)(m_scratch);
176
2
            m_scratch >> value;
177
2
        } catch (const std::exception&) {
178
2
            return false;
179
2
        }
180
0
        return true;
181
2
    }
bool CDBIterator::GetValue<uint256>(uint256&)
Line
Count
Source
171
8
    template<typename V> bool GetValue(V& value) {
172
8
        try {
173
8
            ScopedDataStreamUsage scoped_scratch{m_scratch};
174
8
            m_scratch.write(GetValueImpl());
175
8
            dbwrapper_private::GetObfuscation(parent)(m_scratch);
176
8
            m_scratch >> value;
177
8
        } catch (const std::exception&) {
178
0
            return false;
179
0
        }
180
8
        return true;
181
8
    }
bool CDBIterator::GetValue<unsigned int>(unsigned int&)
Line
Count
Source
171
342
    template<typename V> bool GetValue(V& value) {
172
342
        try {
173
342
            ScopedDataStreamUsage scoped_scratch{m_scratch};
174
342
            m_scratch.write(GetValueImpl());
175
342
            dbwrapper_private::GetObfuscation(parent)(m_scratch);
176
342
            m_scratch >> value;
177
342
        } catch (const std::exception&) {
178
0
            return false;
179
0
        }
180
342
        return true;
181
342
    }
blockfilterindex.cpp:bool CDBIterator::GetValue<std::pair<uint256, (anonymous namespace)::DBVal>>(std::pair<uint256, (anonymous namespace)::DBVal>&)
Line
Count
Source
171
2.97k
    template<typename V> bool GetValue(V& value) {
172
2.97k
        try {
173
2.97k
            ScopedDataStreamUsage scoped_scratch{m_scratch};
174
2.97k
            m_scratch.write(GetValueImpl());
175
2.97k
            dbwrapper_private::GetObfuscation(parent)(m_scratch);
176
2.97k
            m_scratch >> value;
177
2.97k
        } catch (const std::exception&) {
178
0
            return false;
179
0
        }
180
2.97k
        return true;
181
2.97k
    }
coinstatsindex.cpp:bool CDBIterator::GetValue<std::pair<uint256, (anonymous namespace)::DBVal>>(std::pair<uint256, (anonymous namespace)::DBVal>&)
Line
Count
Source
171
121
    template<typename V> bool GetValue(V& value) {
172
121
        try {
173
121
            ScopedDataStreamUsage scoped_scratch{m_scratch};
174
121
            m_scratch.write(GetValueImpl());
175
121
            dbwrapper_private::GetObfuscation(parent)(m_scratch);
176
121
            m_scratch >> value;
177
121
        } catch (const std::exception&) {
178
0
            return false;
179
0
        }
180
121
        return true;
181
121
    }
bool CDBIterator::GetValue<CDiskBlockIndex>(CDiskBlockIndex&)
Line
Count
Source
171
135k
    template<typename V> bool GetValue(V& value) {
172
135k
        try {
173
135k
            ScopedDataStreamUsage scoped_scratch{m_scratch};
174
135k
            m_scratch.write(GetValueImpl());
175
135k
            dbwrapper_private::GetObfuscation(parent)(m_scratch);
176
135k
            m_scratch >> value;
177
135k
        } catch (const std::exception&) {
178
0
            return false;
179
0
        }
180
135k
        return true;
181
135k
    }
bool CDBIterator::GetValue<Coin>(Coin&)
Line
Count
Source
171
226k
    template<typename V> bool GetValue(V& value) {
172
226k
        try {
173
226k
            ScopedDataStreamUsage scoped_scratch{m_scratch};
174
226k
            m_scratch.write(GetValueImpl());
175
226k
            dbwrapper_private::GetObfuscation(parent)(m_scratch);
176
226k
            m_scratch >> value;
177
226k
        } catch (const std::exception&) {
178
0
            return false;
179
0
        }
180
226k
        return true;
181
226k
    }
182
};
183
184
struct LevelDBContext;
185
186
class CDBWrapper
187
{
188
    friend const Obfuscation& dbwrapper_private::GetObfuscation(const CDBWrapper&);
189
private:
190
    //! holds all leveldb-specific fields of this class
191
    std::unique_ptr<LevelDBContext> m_db_context;
192
193
    //! the name of this database
194
    std::string m_name;
195
196
    //! optional XOR-obfuscation of the database
197
    Obfuscation m_obfuscation;
198
199
    //! obfuscation key storage key, null-prefixed to avoid collisions
200
    inline static const std::string OBFUSCATION_KEY{"\000obfuscate_key", 14}; // explicit size to avoid truncation at leading \0
201
202
    std::optional<std::string> ReadImpl(std::span<const std::byte> key) const;
203
    bool ExistsImpl(std::span<const std::byte> key) const;
204
    size_t EstimateSizeImpl(std::span<const std::byte> key1, std::span<const std::byte> key2) const;
205
13.4M
    auto& DBContext() const LIFETIMEBOUND { return *Assert(m_db_context); }
206
207
public:
208
    CDBWrapper(const DBParams& params);
209
    ~CDBWrapper();
210
211
    CDBWrapper(const CDBWrapper&) = delete;
212
    CDBWrapper& operator=(const CDBWrapper&) = delete;
213
214
    template <typename K, typename V>
215
    bool Read(const K& key, V& value) const
216
6.68M
    {
217
6.68M
        DataStream ssKey{};
218
6.68M
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
219
6.68M
        ssKey << key;
220
6.68M
        std::optional<std::string> strValue{ReadImpl(ssKey)};
221
6.68M
        if (!strValue) {
222
6.58M
            return false;
223
6.58M
        }
224
102k
        try {
225
102k
            std::span ssValue{MakeWritableByteSpan(*strValue)};
226
102k
            m_obfuscation(ssValue);
227
102k
            SpanReader{ssValue} >> value;
228
102k
        } catch (const std::exception&) {
229
0
            return false;
230
0
        }
231
102k
        return true;
232
102k
    }
bool CDBWrapper::Read<unsigned char, uint256>(unsigned char const&, uint256&) const
Line
Count
Source
216
7.71k
    {
217
7.71k
        DataStream ssKey{};
218
7.71k
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
219
7.71k
        ssKey << key;
220
7.71k
        std::optional<std::string> strValue{ReadImpl(ssKey)};
221
7.71k
        if (!strValue) {
222
1.71k
            return false;
223
1.71k
        }
224
6.00k
        try {
225
6.00k
            std::span ssValue{MakeWritableByteSpan(*strValue)};
226
6.00k
            m_obfuscation(ssValue);
227
6.00k
            SpanReader{ssValue} >> value;
228
6.00k
        } catch (const std::exception&) {
229
0
            return false;
230
0
        }
231
6.00k
        return true;
232
6.00k
    }
bool CDBWrapper::Read<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, uint256>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, uint256&) const
Line
Count
Source
216
8
    {
217
8
        DataStream ssKey{};
218
8
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
219
8
        ssKey << key;
220
8
        std::optional<std::string> strValue{ReadImpl(ssKey)};
221
8
        if (!strValue) {
222
0
            return false;
223
0
        }
224
8
        try {
225
8
            std::span ssValue{MakeWritableByteSpan(*strValue)};
226
8
            m_obfuscation(ssValue);
227
8
            SpanReader{ssValue} >> value;
228
8
        } catch (const std::exception&) {
229
0
            return false;
230
0
        }
231
8
        return true;
232
8
    }
bool CDBWrapper::Read<unsigned char, unsigned int>(unsigned char const&, unsigned int&) const
Line
Count
Source
216
2
    {
217
2
        DataStream ssKey{};
218
2
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
219
2
        ssKey << key;
220
2
        std::optional<std::string> strValue{ReadImpl(ssKey)};
221
2
        if (!strValue) {
222
0
            return false;
223
0
        }
224
2
        try {
225
2
            std::span ssValue{MakeWritableByteSpan(*strValue)};
226
2
            m_obfuscation(ssValue);
227
2
            SpanReader{ssValue} >> value;
228
2
        } catch (const std::exception&) {
229
0
            return false;
230
0
        }
231
2
        return true;
232
2
    }
bool CDBWrapper::Read<unsigned char, bool>(unsigned char const&, bool&) const
Line
Count
Source
216
2
    {
217
2
        DataStream ssKey{};
218
2
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
219
2
        ssKey << key;
220
2
        std::optional<std::string> strValue{ReadImpl(ssKey)};
221
2
        if (!strValue) {
222
0
            return false;
223
0
        }
224
2
        try {
225
2
            std::span ssValue{MakeWritableByteSpan(*strValue)};
226
2
            m_obfuscation(ssValue);
227
2
            SpanReader{ssValue} >> value;
228
2
        } catch (const std::exception&) {
229
0
            return false;
230
0
        }
231
2
        return true;
232
2
    }
bool CDBWrapper::Read<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, bool>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, bool&) const
Line
Count
Source
216
2
    {
217
2
        DataStream ssKey{};
218
2
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
219
2
        ssKey << key;
220
2
        std::optional<std::string> strValue{ReadImpl(ssKey)};
221
2
        if (!strValue) {
222
0
            return false;
223
0
        }
224
2
        try {
225
2
            std::span ssValue{MakeWritableByteSpan(*strValue)};
226
2
            m_obfuscation(ssValue);
227
2
            SpanReader{ssValue} >> value;
228
2
        } catch (const std::exception&) {
229
0
            return false;
230
0
        }
231
2
        return true;
232
2
    }
bool CDBWrapper::Read<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, Obfuscation>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, Obfuscation&) const
Line
Count
Source
216
2.74k
    {
217
2.74k
        DataStream ssKey{};
218
2.74k
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
219
2.74k
        ssKey << key;
220
2.74k
        std::optional<std::string> strValue{ReadImpl(ssKey)};
221
2.74k
        if (!strValue) {
222
1.89k
            return false;
223
1.89k
        }
224
858
        try {
225
858
            std::span ssValue{MakeWritableByteSpan(*strValue)};
226
858
            m_obfuscation(ssValue);
227
858
            SpanReader{ssValue} >> value;
228
858
        } catch (const std::exception&) {
229
0
            return false;
230
0
        }
231
857
        return true;
232
858
    }
bool CDBWrapper::Read<unsigned char, CBlockLocator>(unsigned char const&, CBlockLocator&) const
Line
Count
Source
216
145
    {
217
145
        DataStream ssKey{};
218
145
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
219
145
        ssKey << key;
220
145
        std::optional<std::string> strValue{ReadImpl(ssKey)};
221
145
        if (!strValue) {
222
56
            return false;
223
56
        }
224
89
        try {
225
89
            std::span ssValue{MakeWritableByteSpan(*strValue)};
226
89
            m_obfuscation(ssValue);
227
89
            SpanReader{ssValue} >> value;
228
89
        } catch (const std::exception&) {
229
0
            return false;
230
0
        }
231
89
        return true;
232
89
    }
blockfilterindex.cpp:bool CDBWrapper::Read<index_util::DBHashKey, (anonymous namespace)::DBVal>(index_util::DBHashKey const&, (anonymous namespace)::DBVal&) const
Line
Count
Source
216
29
    {
217
29
        DataStream ssKey{};
218
29
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
219
29
        ssKey << key;
220
29
        std::optional<std::string> strValue{ReadImpl(ssKey)};
221
29
        if (!strValue) {
222
0
            return false;
223
0
        }
224
29
        try {
225
29
            std::span ssValue{MakeWritableByteSpan(*strValue)};
226
29
            m_obfuscation(ssValue);
227
29
            SpanReader{ssValue} >> value;
228
29
        } catch (const std::exception&) {
229
0
            return false;
230
0
        }
231
29
        return true;
232
29
    }
bool CDBWrapper::Read<unsigned char, FlatFilePos>(unsigned char const&, FlatFilePos&) const
Line
Count
Source
216
42
    {
217
42
        DataStream ssKey{};
218
42
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
219
42
        ssKey << key;
220
42
        std::optional<std::string> strValue{ReadImpl(ssKey)};
221
42
        if (!strValue) {
222
18
            return false;
223
18
        }
224
24
        try {
225
24
            std::span ssValue{MakeWritableByteSpan(*strValue)};
226
24
            m_obfuscation(ssValue);
227
24
            SpanReader{ssValue} >> value;
228
24
        } catch (const std::exception&) {
229
0
            return false;
230
0
        }
231
24
        return true;
232
24
    }
blockfilterindex.cpp:bool CDBWrapper::Read<index_util::DBHeightKey, std::pair<uint256, (anonymous namespace)::DBVal>>(index_util::DBHeightKey const&, std::pair<uint256, (anonymous namespace)::DBVal>&) const
Line
Count
Source
216
1.21k
    {
217
1.21k
        DataStream ssKey{};
218
1.21k
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
219
1.21k
        ssKey << key;
220
1.21k
        std::optional<std::string> strValue{ReadImpl(ssKey)};
221
1.21k
        if (!strValue) {
222
202
            return false;
223
202
        }
224
1.01k
        try {
225
1.01k
            std::span ssValue{MakeWritableByteSpan(*strValue)};
226
1.01k
            m_obfuscation(ssValue);
227
1.01k
            SpanReader{ssValue} >> value;
228
1.01k
        } catch (const std::exception&) {
229
0
            return false;
230
0
        }
231
1.01k
        return true;
232
1.01k
    }
coinstatsindex.cpp:bool CDBWrapper::Read<index_util::DBHashKey, (anonymous namespace)::DBVal>(index_util::DBHashKey const&, (anonymous namespace)::DBVal&) const
Line
Count
Source
216
2
    {
217
2
        DataStream ssKey{};
218
2
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
219
2
        ssKey << key;
220
2
        std::optional<std::string> strValue{ReadImpl(ssKey)};
221
2
        if (!strValue) {
222
0
            return false;
223
0
        }
224
2
        try {
225
2
            std::span ssValue{MakeWritableByteSpan(*strValue)};
226
2
            m_obfuscation(ssValue);
227
2
            SpanReader{ssValue} >> value;
228
2
        } catch (const std::exception&) {
229
0
            return false;
230
0
        }
231
2
        return true;
232
2
    }
bool CDBWrapper::Read<unsigned char, MuHash3072>(unsigned char const&, MuHash3072&) const
Line
Count
Source
216
45
    {
217
45
        DataStream ssKey{};
218
45
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
219
45
        ssKey << key;
220
45
        std::optional<std::string> strValue{ReadImpl(ssKey)};
221
45
        if (!strValue) {
222
16
            return false;
223
16
        }
224
29
        try {
225
29
            std::span ssValue{MakeWritableByteSpan(*strValue)};
226
29
            m_obfuscation(ssValue);
227
29
            SpanReader{ssValue} >> value;
228
29
        } catch (const std::exception&) {
229
0
            return false;
230
0
        }
231
29
        return true;
232
29
    }
coinstatsindex.cpp:bool CDBWrapper::Read<index_util::DBHeightKey, std::pair<uint256, (anonymous namespace)::DBVal>>(index_util::DBHeightKey const&, std::pair<uint256, (anonymous namespace)::DBVal>&) const
Line
Count
Source
216
220
    {
217
220
        DataStream ssKey{};
218
220
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
219
220
        ssKey << key;
220
220
        std::optional<std::string> strValue{ReadImpl(ssKey)};
221
220
        if (!strValue) {
222
1
            return false;
223
1
        }
224
219
        try {
225
219
            std::span ssValue{MakeWritableByteSpan(*strValue)};
226
219
            m_obfuscation(ssValue);
227
219
            SpanReader{ssValue} >> value;
228
219
        } catch (const std::exception&) {
229
0
            return false;
230
0
        }
231
219
        return true;
232
219
    }
Unexecuted instantiation: coinstatsindex.cpp:bool CDBWrapper::Read<index_util::DBHashKey, std::pair<uint256, (anonymous namespace)::DBVal>>(index_util::DBHashKey const&, std::pair<uint256, (anonymous namespace)::DBVal>&) const
bool CDBWrapper::Read<std::pair<unsigned char, uint256>, CDiskTxPos>(std::pair<unsigned char, uint256> const&, CDiskTxPos&) const
Line
Count
Source
216
243
    {
217
243
        DataStream ssKey{};
218
243
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
219
243
        ssKey << key;
220
243
        std::optional<std::string> strValue{ReadImpl(ssKey)};
221
243
        if (!strValue) {
222
101
            return false;
223
101
        }
224
142
        try {
225
142
            std::span ssValue{MakeWritableByteSpan(*strValue)};
226
142
            m_obfuscation(ssValue);
227
142
            SpanReader{ssValue} >> value;
228
142
        } catch (const std::exception&) {
229
0
            return false;
230
0
        }
231
142
        return true;
232
142
    }
bool CDBWrapper::Read<char [12], std::pair<unsigned long, unsigned long>>(char const (&) [12], std::pair<unsigned long, unsigned long>&) const
Line
Count
Source
216
22
    {
217
22
        DataStream ssKey{};
218
22
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
219
22
        ssKey << key;
220
22
        std::optional<std::string> strValue{ReadImpl(ssKey)};
221
22
        if (!strValue) {
222
6
            return false;
223
6
        }
224
16
        try {
225
16
            std::span ssValue{MakeWritableByteSpan(*strValue)};
226
16
            m_obfuscation(ssValue);
227
16
            SpanReader{ssValue} >> value;
228
16
        } catch (const std::exception&) {
229
0
            return false;
230
0
        }
231
16
        return true;
232
16
    }
bool CDBWrapper::Read<std::pair<unsigned char, int>, kernel::CBlockFileInfo>(std::pair<unsigned char, int> const&, kernel::CBlockFileInfo&) const
Line
Count
Source
216
2.39k
    {
217
2.39k
        DataStream ssKey{};
218
2.39k
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
219
2.39k
        ssKey << key;
220
2.39k
        std::optional<std::string> strValue{ReadImpl(ssKey)};
221
2.39k
        if (!strValue) {
222
1.63k
            return false;
223
1.63k
        }
224
760
        try {
225
760
            std::span ssValue{MakeWritableByteSpan(*strValue)};
226
760
            m_obfuscation(ssValue);
227
760
            SpanReader{ssValue} >> value;
228
760
        } catch (const std::exception&) {
229
0
            return false;
230
0
        }
231
760
        return true;
232
760
    }
bool CDBWrapper::Read<unsigned char, int>(unsigned char const&, int&) const
Line
Count
Source
216
1.18k
    {
217
1.18k
        DataStream ssKey{};
218
1.18k
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
219
1.18k
        ssKey << key;
220
1.18k
        std::optional<std::string> strValue{ReadImpl(ssKey)};
221
1.18k
        if (!strValue) {
222
447
            return false;
223
447
        }
224
742
        try {
225
742
            std::span ssValue{MakeWritableByteSpan(*strValue)};
226
742
            m_obfuscation(ssValue);
227
742
            SpanReader{ssValue} >> value;
228
742
        } catch (const std::exception&) {
229
0
            return false;
230
0
        }
231
742
        return true;
232
742
    }
bool CDBWrapper::Read<std::pair<unsigned char, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, unsigned char>(std::pair<unsigned char, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>> const&, unsigned char&) const
Line
Count
Source
216
1.18k
    {
217
1.18k
        DataStream ssKey{};
218
1.18k
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
219
1.18k
        ssKey << key;
220
1.18k
        std::optional<std::string> strValue{ReadImpl(ssKey)};
221
1.18k
        if (!strValue) {
222
1.18k
            return false;
223
1.18k
        }
224
2
        try {
225
2
            std::span ssValue{MakeWritableByteSpan(*strValue)};
226
2
            m_obfuscation(ssValue);
227
2
            SpanReader{ssValue} >> value;
228
2
        } catch (const std::exception&) {
229
0
            return false;
230
0
        }
231
2
        return true;
232
2
    }
txdb.cpp:bool CDBWrapper::Read<(anonymous namespace)::CoinEntry, Coin>((anonymous namespace)::CoinEntry const&, Coin&) const
Line
Count
Source
216
6.66M
    {
217
6.66M
        DataStream ssKey{};
218
6.66M
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
219
6.66M
        ssKey << key;
220
6.66M
        std::optional<std::string> strValue{ReadImpl(ssKey)};
221
6.66M
        if (!strValue) {
222
6.57M
            return false;
223
6.57M
        }
224
92.5k
        try {
225
92.5k
            std::span ssValue{MakeWritableByteSpan(*strValue)};
226
92.5k
            m_obfuscation(ssValue);
227
92.5k
            SpanReader{ssValue} >> value;
228
92.5k
        } catch (const std::exception&) {
229
0
            return false;
230
0
        }
231
92.5k
        return true;
232
92.5k
    }
bool CDBWrapper::Read<unsigned char, std::vector<uint256, std::allocator<uint256>>>(unsigned char const&, std::vector<uint256, std::allocator<uint256>>&) const
Line
Count
Source
216
1.55k
    {
217
1.55k
        DataStream ssKey{};
218
1.55k
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
219
1.55k
        ssKey << key;
220
1.55k
        std::optional<std::string> strValue{ReadImpl(ssKey)};
221
1.55k
        if (!strValue) {
222
1.55k
            return false;
223
1.55k
        }
224
0
        try {
225
0
            std::span ssValue{MakeWritableByteSpan(*strValue)};
226
0
            m_obfuscation(ssValue);
227
0
            SpanReader{ssValue} >> value;
228
0
        } catch (const std::exception&) {
229
0
            return false;
230
0
        }
231
0
        return true;
232
0
    }
233
234
    template <typename K, typename V>
235
    void Write(const K& key, const V& value, bool fSync = false)
236
12.3k
    {
237
12.3k
        CDBBatch batch(*this);
238
12.3k
        batch.Write(key, value);
239
12.3k
        WriteBatch(batch, fSync);
240
12.3k
    }
void CDBWrapper::Write<unsigned char, uint256>(unsigned char const&, uint256 const&, bool)
Line
Count
Source
236
30
    {
237
30
        CDBBatch batch(*this);
238
30
        batch.Write(key, value);
239
30
        WriteBatch(batch, fSync);
240
30
    }
void CDBWrapper::Write<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, uint256>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, uint256 const&, bool)
Line
Count
Source
236
8
    {
237
8
        CDBBatch batch(*this);
238
8
        batch.Write(key, value);
239
8
        WriteBatch(batch, fSync);
240
8
    }
void CDBWrapper::Write<unsigned char, unsigned int>(unsigned char const&, unsigned int const&, bool)
Line
Count
Source
236
258
    {
237
258
        CDBBatch batch(*this);
238
258
        batch.Write(key, value);
239
258
        WriteBatch(batch, fSync);
240
258
    }
void CDBWrapper::Write<unsigned char, bool>(unsigned char const&, bool const&, bool)
Line
Count
Source
236
2
    {
237
2
        CDBBatch batch(*this);
238
2
        batch.Write(key, value);
239
2
        WriteBatch(batch, fSync);
240
2
    }
void CDBWrapper::Write<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, bool>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, bool const&, bool)
Line
Count
Source
236
2
    {
237
2
        CDBBatch batch(*this);
238
2
        batch.Write(key, value);
239
2
        WriteBatch(batch, fSync);
240
2
    }
void CDBWrapper::Write<dbwrapper_tests::StringContentsSerializer, unsigned int>(dbwrapper_tests::StringContentsSerializer const&, unsigned int const&, bool)
Line
Count
Source
236
100
    {
237
100
        CDBBatch batch(*this);
238
100
        batch.Write(key, value);
239
100
        WriteBatch(batch, fSync);
240
100
    }
void CDBWrapper::Write<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, Obfuscation>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, Obfuscation const&, bool)
Line
Count
Source
236
512
    {
237
512
        CDBBatch batch(*this);
238
512
        batch.Write(key, value);
239
512
        WriteBatch(batch, fSync);
240
512
    }
blockfilterindex.cpp:void CDBWrapper::Write<index_util::DBHeightKey, std::pair<uint256, (anonymous namespace)::DBVal>>(index_util::DBHeightKey const&, std::pair<uint256, (anonymous namespace)::DBVal> const&, bool)
Line
Count
Source
236
7.54k
    {
237
7.54k
        CDBBatch batch(*this);
238
7.54k
        batch.Write(key, value);
239
7.54k
        WriteBatch(batch, fSync);
240
7.54k
    }
coinstatsindex.cpp:void CDBWrapper::Write<index_util::DBHeightKey, std::pair<uint256, (anonymous namespace)::DBVal>>(index_util::DBHeightKey const&, std::pair<uint256, (anonymous namespace)::DBVal> const&, bool)
Line
Count
Source
236
3.86k
    {
237
3.86k
        CDBBatch batch(*this);
238
3.86k
        batch.Write(key, value);
239
3.86k
        WriteBatch(batch, fSync);
240
3.86k
    }
void CDBWrapper::Write<char [12], std::pair<unsigned long, unsigned long>>(char const (&) [12], std::pair<unsigned long, unsigned long> const&, bool)
Line
Count
Source
236
6
    {
237
6
        CDBBatch batch(*this);
238
6
        batch.Write(key, value);
239
6
        WriteBatch(batch, fSync);
240
6
    }
void CDBWrapper::Write<unsigned char, unsigned char>(unsigned char const&, unsigned char const&, bool)
Line
Count
Source
236
14
    {
237
14
        CDBBatch batch(*this);
238
14
        batch.Write(key, value);
239
14
        WriteBatch(batch, fSync);
240
14
    }
void CDBWrapper::Write<std::pair<unsigned char, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, unsigned char>(std::pair<unsigned char, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>> const&, unsigned char const&, bool)
Line
Count
Source
236
8
    {
237
8
        CDBBatch batch(*this);
238
8
        batch.Write(key, value);
239
8
        WriteBatch(batch, fSync);
240
8
    }
241
242
    template <typename K>
243
    bool Exists(const K& key) const
244
1.26k
    {
245
1.26k
        DataStream ssKey{};
246
1.26k
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
247
1.26k
        ssKey << key;
248
1.26k
        return ExistsImpl(ssKey);
249
1.26k
    }
bool CDBWrapper::Exists<unsigned char>(unsigned char const&) const
Line
Count
Source
244
1.22k
    {
245
1.22k
        DataStream ssKey{};
246
1.22k
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
247
1.22k
        ssKey << key;
248
1.22k
        return ExistsImpl(ssKey);
249
1.22k
    }
txdb.cpp:bool CDBWrapper::Exists<(anonymous namespace)::CoinEntry>((anonymous namespace)::CoinEntry const&) const
Line
Count
Source
244
44
    {
245
44
        DataStream ssKey{};
246
44
        ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
247
44
        ssKey << key;
248
44
        return ExistsImpl(ssKey);
249
44
    }
250
251
    template <typename K>
252
    void Erase(const K& key, bool fSync = false)
253
13
    {
254
13
        CDBBatch batch(*this);
255
13
        batch.Erase(key);
256
13
        WriteBatch(batch, fSync);
257
13
    }
258
259
    void WriteBatch(CDBBatch& batch, bool fSync = false);
260
261
    // Get an estimate of LevelDB memory usage (in bytes).
262
    size_t DynamicMemoryUsage() const;
263
264
    CDBIterator* NewIterator();
265
266
    /**
267
     * Return true if the database managed by this class contains no entries.
268
     */
269
    bool IsEmpty();
270
271
    template<typename K>
272
    size_t EstimateSize(const K& key_begin, const K& key_end) const
273
102
    {
274
102
        DataStream ssKey1{}, ssKey2{};
275
102
        ssKey1.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
276
102
        ssKey2.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
277
102
        ssKey1 << key_begin;
278
102
        ssKey2 << key_end;
279
102
        return EstimateSizeImpl(ssKey1, ssKey2);
280
102
    }
281
};
282
283
#endif // BITCOIN_DBWRAPPER_H