fuzz coverage

Coverage Report

Created: 2025-08-28 15:26

/Users/eugenesiegel/btc/bitcoin/src/wallet/walletdb.h
Line
Count
Source (jump to first uncovered line)
1
// Copyright (c) 2009-2010 Satoshi Nakamoto
2
// Copyright (c) 2009-2022 The Bitcoin Core developers
3
// Distributed under the MIT software license, see the accompanying
4
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
6
#ifndef BITCOIN_WALLET_WALLETDB_H
7
#define BITCOIN_WALLET_WALLETDB_H
8
9
#include <script/sign.h>
10
#include <wallet/db.h>
11
#include <wallet/walletutil.h>
12
#include <key.h>
13
14
#include <stdint.h>
15
#include <string>
16
#include <vector>
17
18
class CScript;
19
class uint160;
20
class uint256;
21
struct CBlockLocator;
22
23
namespace wallet {
24
class CKeyPool;
25
class CMasterKey;
26
class CWallet;
27
class CWalletTx;
28
struct WalletContext;
29
30
/**
31
 * Overview of wallet database classes:
32
 *
33
 * - WalletBatch is an abstract modifier object for the wallet database, and encapsulates a database
34
 *   batch update as well as methods to act on the database. It should be agnostic to the database implementation.
35
 *
36
 * The following classes are implementation specific:
37
 * - BerkeleyEnvironment is an environment in which the database exists.
38
 * - BerkeleyDatabase represents a wallet database.
39
 * - BerkeleyBatch is a low-level database batch update.
40
 */
41
42
static const bool DEFAULT_FLUSHWALLET = true;
43
44
/** Error statuses for the wallet database.
45
 * Values are in order of severity. When multiple errors occur, the most severe (highest value) will be returned.
46
 */
47
enum class DBErrors : int
48
{
49
    LOAD_OK = 0,
50
    NEED_RESCAN = 1,
51
    NEED_REWRITE = 2,
52
    EXTERNAL_SIGNER_SUPPORT_REQUIRED = 3,
53
    NONCRITICAL_ERROR = 4,
54
    TOO_NEW = 5,
55
    UNKNOWN_DESCRIPTOR = 6,
56
    LOAD_FAIL = 7,
57
    UNEXPECTED_LEGACY_ENTRY = 8,
58
    LEGACY_WALLET = 9,
59
    CORRUPT = 10,
60
};
61
62
namespace DBKeys {
63
extern const std::string ACENTRY;
64
extern const std::string ACTIVEEXTERNALSPK;
65
extern const std::string ACTIVEINTERNALSPK;
66
extern const std::string BESTBLOCK;
67
extern const std::string BESTBLOCK_NOMERKLE;
68
extern const std::string CRYPTED_KEY;
69
extern const std::string CSCRIPT;
70
extern const std::string DEFAULTKEY;
71
extern const std::string DESTDATA;
72
extern const std::string FLAGS;
73
extern const std::string HDCHAIN;
74
extern const std::string KEY;
75
extern const std::string KEYMETA;
76
extern const std::string LOCKED_UTXO;
77
extern const std::string MASTER_KEY;
78
extern const std::string MINVERSION;
79
extern const std::string NAME;
80
extern const std::string OLD_KEY;
81
extern const std::string ORDERPOSNEXT;
82
extern const std::string POOL;
83
extern const std::string PURPOSE;
84
extern const std::string SETTINGS;
85
extern const std::string TX;
86
extern const std::string VERSION;
87
extern const std::string WALLETDESCRIPTOR;
88
extern const std::string WALLETDESCRIPTORCKEY;
89
extern const std::string WALLETDESCRIPTORKEY;
90
extern const std::string WATCHMETA;
91
extern const std::string WATCHS;
92
93
// Keys in this set pertain only to the legacy wallet (LegacyScriptPubKeyMan) and are removed during migration from legacy to descriptors.
94
extern const std::unordered_set<std::string> LEGACY_TYPES;
95
} // namespace DBKeys
96
97
/* simple HD chain data model */
98
class CHDChain
99
{
100
public:
101
    uint32_t nExternalChainCounter;
102
    uint32_t nInternalChainCounter;
103
    CKeyID seed_id; //!< seed hash160
104
    int64_t m_next_external_index{0}; // Next index in the keypool to be used. Memory only.
105
    int64_t m_next_internal_index{0}; // Next index in the keypool to be used. Memory only.
106
107
    static const int VERSION_HD_BASE        = 1;
108
    static const int VERSION_HD_CHAIN_SPLIT = 2;
109
    static const int CURRENT_VERSION        = VERSION_HD_CHAIN_SPLIT;
110
    int nVersion;
111
112
0
    CHDChain() { SetNull(); }
113
114
    SERIALIZE_METHODS(CHDChain, obj)
115
0
    {
116
0
        READWRITE(obj.nVersion, obj.nExternalChainCounter, obj.seed_id);
Line
Count
Source
156
0
#define READWRITE(...) (ser_action.SerReadWriteMany(s, __VA_ARGS__))
        READWRITE(obj.nVersion, obj.nExternalChainCounter, obj.seed_id);
Line
Count
Source
156
0
#define READWRITE(...) (ser_action.SerReadWriteMany(s, __VA_ARGS__))
117
0
        if (obj.nVersion >= VERSION_HD_CHAIN_SPLIT) {
118
0
            READWRITE(obj.nInternalChainCounter);
Line
Count
Source
156
0
#define READWRITE(...) (ser_action.SerReadWriteMany(s, __VA_ARGS__))
            READWRITE(obj.nInternalChainCounter);
Line
Count
Source
156
0
#define READWRITE(...) (ser_action.SerReadWriteMany(s, __VA_ARGS__))
119
0
        }
120
0
    }
Unexecuted instantiation: _ZN6wallet8CHDChain16SerializationOpsI10DataStreamS0_17ActionUnserializeEEvRT0_RT_T1_
Unexecuted instantiation: _ZN6wallet8CHDChain16SerializationOpsI10DataStreamKS0_15ActionSerializeEEvRT0_RT_T1_
121
122
    void SetNull()
123
0
    {
124
0
        nVersion = CHDChain::CURRENT_VERSION;
125
0
        nExternalChainCounter = 0;
126
0
        nInternalChainCounter = 0;
127
0
        seed_id.SetNull();
128
0
    }
129
130
    bool operator==(const CHDChain& chain) const
131
0
    {
132
0
        return seed_id == chain.seed_id;
133
0
    }
134
};
135
136
class CKeyMetadata
137
{
138
public:
139
    static const int VERSION_BASIC=1;
140
    static const int VERSION_WITH_HDDATA=10;
141
    static const int VERSION_WITH_KEY_ORIGIN = 12;
142
    static const int CURRENT_VERSION=VERSION_WITH_KEY_ORIGIN;
143
    int nVersion;
144
    int64_t nCreateTime; // 0 means unknown
145
    std::string hdKeypath; //optional HD/bip32 keypath. Still used to determine whether a key is a seed. Also kept for backwards compatibility
146
    CKeyID hd_seed_id; //id of the HD seed used to derive this key
147
    KeyOriginInfo key_origin; // Key origin info with path and fingerprint
148
    bool has_key_origin = false; //!< Whether the key_origin is useful
149
150
    CKeyMetadata()
151
0
    {
152
0
        SetNull();
153
0
    }
154
    explicit CKeyMetadata(int64_t nCreateTime_)
155
0
    {
156
0
        SetNull();
157
0
        nCreateTime = nCreateTime_;
158
0
    }
159
160
    SERIALIZE_METHODS(CKeyMetadata, obj)
161
0
    {
162
0
        READWRITE(obj.nVersion, obj.nCreateTime);
Line
Count
Source
156
0
#define READWRITE(...) (ser_action.SerReadWriteMany(s, __VA_ARGS__))
        READWRITE(obj.nVersion, obj.nCreateTime);
Line
Count
Source
156
0
#define READWRITE(...) (ser_action.SerReadWriteMany(s, __VA_ARGS__))
163
0
        if (obj.nVersion >= VERSION_WITH_HDDATA) {
164
0
            READWRITE(obj.hdKeypath, obj.hd_seed_id);
Line
Count
Source
156
0
#define READWRITE(...) (ser_action.SerReadWriteMany(s, __VA_ARGS__))
            READWRITE(obj.hdKeypath, obj.hd_seed_id);
Line
Count
Source
156
0
#define READWRITE(...) (ser_action.SerReadWriteMany(s, __VA_ARGS__))
165
0
        }
166
0
        if (obj.nVersion >= VERSION_WITH_KEY_ORIGIN)
167
0
        {
168
0
            READWRITE(obj.key_origin);
Line
Count
Source
156
0
#define READWRITE(...) (ser_action.SerReadWriteMany(s, __VA_ARGS__))
            READWRITE(obj.key_origin);
Line
Count
Source
156
0
#define READWRITE(...) (ser_action.SerReadWriteMany(s, __VA_ARGS__))
169
0
            READWRITE(obj.has_key_origin);
Line
Count
Source
156
0
#define READWRITE(...) (ser_action.SerReadWriteMany(s, __VA_ARGS__))
            READWRITE(obj.has_key_origin);
Line
Count
Source
156
0
#define READWRITE(...) (ser_action.SerReadWriteMany(s, __VA_ARGS__))
170
0
        }
171
0
    }
Unexecuted instantiation: _ZN6wallet12CKeyMetadata16SerializationOpsI10DataStreamS0_17ActionUnserializeEEvRT0_RT_T1_
Unexecuted instantiation: _ZN6wallet12CKeyMetadata16SerializationOpsI10DataStreamKS0_15ActionSerializeEEvRT0_RT_T1_
172
173
    void SetNull()
174
0
    {
175
0
        nVersion = CKeyMetadata::CURRENT_VERSION;
176
0
        nCreateTime = 0;
177
0
        hdKeypath.clear();
178
0
        hd_seed_id.SetNull();
179
0
        key_origin.clear();
180
0
        has_key_origin = false;
181
0
    }
182
};
183
184
struct DbTxnListener
185
{
186
    std::function<void()> on_commit, on_abort;
187
};
188
189
/** Access to the wallet database.
190
 * Opens the database and provides read and write access to it. Each read and write is its own transaction.
191
 * Multiple operation transactions can be started using TxnBegin() and committed using TxnCommit()
192
 * Otherwise the transaction will be committed when the object goes out of scope.
193
 * Optionally (on by default) it will flush to disk on close.
194
 * Every 1000 writes will automatically trigger a flush to disk.
195
 */
196
class WalletBatch
197
{
198
private:
199
    template <typename K, typename T>
200
    bool WriteIC(const K& key, const T& value, bool fOverwrite = true)
201
0
    {
202
0
        if (!m_batch->Write(key, value, fOverwrite)) {
203
0
            return false;
204
0
        }
205
0
        m_database.IncrementUpdateCounter();
206
0
        if (m_database.nUpdateCounter % 1000 == 0) {
207
0
            m_batch->Flush();
208
0
        }
209
0
        return true;
210
0
    }
Unexecuted instantiation: _ZN6wallet11WalletBatch7WriteICINSt3__14pairINS2_12basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEES9_EES9_EEbRKT_RKT0_b
Unexecuted instantiation: _ZN6wallet11WalletBatch7WriteICINSt3__14pairINS2_12basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEE22transaction_identifierILb0EEEENS_9CWalletTxEEEbRKT_RKT0_b
Unexecuted instantiation: _ZN6wallet11WalletBatch7WriteICINSt3__14pairINS2_12basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEE7CPubKeyEENS_12CKeyMetadataEEEbRKT_RKT0_b
Unexecuted instantiation: _ZN6wallet11WalletBatch7WriteICINSt3__14pairINS2_12basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEE7CPubKeyEENS3_INS2_6vectorIh16secure_allocatorIhEEE7uint256EEEEbRKT_RKT0_b
Unexecuted instantiation: _ZN6wallet11WalletBatch7WriteICINSt3__14pairINS2_12basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEE7CPubKeyEENS3_INS2_6vectorIhNS7_IhEEEE7uint256EEEEbRKT_RKT0_b
Unexecuted instantiation: _ZN6wallet11WalletBatch7WriteICINSt3__14pairINS2_12basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEjEENS_10CMasterKeyEEEbRKT_RKT0_b
Unexecuted instantiation: _ZN6wallet11WalletBatch7WriteICINSt3__14pairINS2_12basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEE7uint160EE7CScriptEEbRKT_RKT0_b
Unexecuted instantiation: _ZN6wallet11WalletBatch7WriteICINSt3__14pairINS2_12basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEE7CScriptEENS_12CKeyMetadataEEEbRKT_RKT0_b
Unexecuted instantiation: _ZN6wallet11WalletBatch7WriteICINSt3__14pairINS2_12basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEE7CScriptEEhEEbRKT_RKT0_b
Unexecuted instantiation: _ZN6wallet11WalletBatch7WriteICINSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEE13CBlockLocatorEEbRKT_RKT0_b
Unexecuted instantiation: _ZN6wallet11WalletBatch7WriteICINSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEExEEbRKT_RKT0_b
Unexecuted instantiation: _ZN6wallet11WalletBatch7WriteICINSt3__14pairINS2_12basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEExEENS_8CKeyPoolEEEbRKT_RKT0_b
Unexecuted instantiation: _ZN6wallet11WalletBatch7WriteICINSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEiEEbRKT_RKT0_b
Unexecuted instantiation: _ZN6wallet11WalletBatch7WriteICINSt3__14pairINS2_12basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEhEE7uint256EEbRKT_RKT0_b
Unexecuted instantiation: _ZN6wallet11WalletBatch7WriteICINSt3__14pairINS2_12basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEENS3_I7uint2567CPubKeyEEEENS3_INS2_6vectorIh16secure_allocatorIhEEESA_EEEEbRKT_RKT0_b
Unexecuted instantiation: _ZN6wallet11WalletBatch7WriteICINSt3__14pairINS2_12basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEENS3_I7uint2567CPubKeyEEEENS2_6vectorIhNS7_IhEEEEEEbRKT_RKT0_b
Unexecuted instantiation: _ZN6wallet11WalletBatch7WriteICINSt3__14pairINS2_12basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEE7uint256EENS_16WalletDescriptorEEEbRKT_RKT0_b
Unexecuted instantiation: _ZN6wallet11WalletBatch7WriteICINSt3__14pairINS3_INS2_12basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEE7uint256EENS3_IjjEEEENS2_6vectorIhNS7_IhEEEEEEbRKT_RKT0_b
Unexecuted instantiation: _ZN6wallet11WalletBatch7WriteICINSt3__14pairINS3_INS2_12basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEE7uint256EEjEENS2_6vectorIhNS7_IhEEEEEEbRKT_RKT0_b
Unexecuted instantiation: _ZN6wallet11WalletBatch7WriteICINSt3__14pairINS2_12basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEENS3_I22transaction_identifierILb0EEjEEEEhEEbRKT_RKT0_b
Unexecuted instantiation: _ZN6wallet11WalletBatch7WriteICINSt3__14pairINS2_12basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEENS3_IS9_S9_EEEES9_EEbRKT_RKT0_b
Unexecuted instantiation: _ZN6wallet11WalletBatch7WriteICINSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEENS_8CHDChainEEEbRKT_RKT0_b
Unexecuted instantiation: _ZN6wallet11WalletBatch7WriteICINSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEyEEbRKT_RKT0_b
211
212
    template <typename K>
213
    bool EraseIC(const K& key)
214
0
    {
215
0
        if (!m_batch->Erase(key)) {
216
0
            return false;
217
0
        }
218
0
        m_database.IncrementUpdateCounter();
219
0
        if (m_database.nUpdateCounter % 1000 == 0) {
220
0
            m_batch->Flush();
221
0
        }
222
0
        return true;
223
0
    }
Unexecuted instantiation: _ZN6wallet11WalletBatch7EraseICINSt3__14pairINS2_12basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEES9_EEEEbRKT_
Unexecuted instantiation: _ZN6wallet11WalletBatch7EraseICINSt3__14pairINS2_12basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEE7uint256EEEEbRKT_
Unexecuted instantiation: _ZN6wallet11WalletBatch7EraseICINSt3__14pairINS2_12basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEE7CPubKeyEEEEbRKT_
Unexecuted instantiation: _ZN6wallet11WalletBatch7EraseICINSt3__14pairINS2_12basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEjEEEEbRKT_
Unexecuted instantiation: _ZN6wallet11WalletBatch7EraseICINSt3__14pairINS2_12basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEE7CScriptEEEEbRKT_
Unexecuted instantiation: _ZN6wallet11WalletBatch7EraseICINSt3__14pairINS2_12basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEExEEEEbRKT_
Unexecuted instantiation: _ZN6wallet11WalletBatch7EraseICINSt3__14pairINS2_12basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEhEEEEbRKT_
Unexecuted instantiation: _ZN6wallet11WalletBatch7EraseICINSt3__14pairINS2_12basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEENS3_I7uint2567CPubKeyEEEEEEbRKT_
Unexecuted instantiation: _ZN6wallet11WalletBatch7EraseICINSt3__14pairINS2_12basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEENS3_I22transaction_identifierILb0EEjEEEEEEbRKT_
Unexecuted instantiation: _ZN6wallet11WalletBatch7EraseICINSt3__14pairINS2_12basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEENS3_IS9_S9_EEEEEEbRKT_
224
225
public:
226
    explicit WalletBatch(WalletDatabase &database, bool _fFlushOnClose = true) :
227
0
        m_batch(database.MakeBatch(_fFlushOnClose)),
228
0
        m_database(database)
229
0
    {
230
0
    }
231
    WalletBatch(const WalletBatch&) = delete;
232
    WalletBatch& operator=(const WalletBatch&) = delete;
233
234
    bool WriteName(const std::string& strAddress, const std::string& strName);
235
    bool EraseName(const std::string& strAddress);
236
237
    bool WritePurpose(const std::string& strAddress, const std::string& purpose);
238
    bool ErasePurpose(const std::string& strAddress);
239
240
    bool WriteTx(const CWalletTx& wtx);
241
    bool EraseTx(uint256 hash);
242
243
    bool WriteKeyMetadata(const CKeyMetadata& meta, const CPubKey& pubkey, const bool overwrite);
244
    bool WriteKey(const CPubKey& vchPubKey, const CPrivKey& vchPrivKey, const CKeyMetadata &keyMeta);
245
    bool WriteCryptedKey(const CPubKey& vchPubKey, const std::vector<unsigned char>& vchCryptedSecret, const CKeyMetadata &keyMeta);
246
    bool WriteMasterKey(unsigned int nID, const CMasterKey& kMasterKey);
247
    bool EraseMasterKey(unsigned int id);
248
249
    bool WriteCScript(const uint160& hash, const CScript& redeemScript);
250
251
    bool WriteWatchOnly(const CScript &script, const CKeyMetadata &keymeta);
252
    bool EraseWatchOnly(const CScript &script);
253
254
    bool WriteBestBlock(const CBlockLocator& locator);
255
    bool ReadBestBlock(CBlockLocator& locator);
256
257
    // Returns true if wallet stores encryption keys
258
    bool IsEncrypted();
259
260
    bool WriteOrderPosNext(int64_t nOrderPosNext);
261
262
    bool ReadPool(int64_t nPool, CKeyPool& keypool);
263
    bool WritePool(int64_t nPool, const CKeyPool& keypool);
264
    bool ErasePool(int64_t nPool);
265
266
    bool WriteMinVersion(int nVersion);
267
268
    bool WriteDescriptorKey(const uint256& desc_id, const CPubKey& pubkey, const CPrivKey& privkey);
269
    bool WriteCryptedDescriptorKey(const uint256& desc_id, const CPubKey& pubkey, const std::vector<unsigned char>& secret);
270
    bool WriteDescriptor(const uint256& desc_id, const WalletDescriptor& descriptor);
271
    bool WriteDescriptorDerivedCache(const CExtPubKey& xpub, const uint256& desc_id, uint32_t key_exp_index, uint32_t der_index);
272
    bool WriteDescriptorParentCache(const CExtPubKey& xpub, const uint256& desc_id, uint32_t key_exp_index);
273
    bool WriteDescriptorLastHardenedCache(const CExtPubKey& xpub, const uint256& desc_id, uint32_t key_exp_index);
274
    bool WriteDescriptorCacheItems(const uint256& desc_id, const DescriptorCache& cache);
275
276
    bool WriteLockedUTXO(const COutPoint& output);
277
    bool EraseLockedUTXO(const COutPoint& output);
278
279
    bool WriteAddressPreviouslySpent(const CTxDestination& dest, bool previously_spent);
280
    bool WriteAddressReceiveRequest(const CTxDestination& dest, const std::string& id, const std::string& receive_request);
281
    bool EraseAddressReceiveRequest(const CTxDestination& dest, const std::string& id);
282
    bool EraseAddressData(const CTxDestination& dest);
283
284
    bool WriteActiveScriptPubKeyMan(uint8_t type, const uint256& id, bool internal);
285
    bool EraseActiveScriptPubKeyMan(uint8_t type, bool internal);
286
287
    DBErrors LoadWallet(CWallet* pwallet);
288
289
    //! write the hdchain model (external chain child index counter)
290
    bool WriteHDChain(const CHDChain& chain);
291
292
    //! Delete records of the given types
293
    bool EraseRecords(const std::unordered_set<std::string>& types);
294
295
    bool WriteWalletFlags(const uint64_t flags);
296
    //! Begin a new transaction
297
    bool TxnBegin();
298
    //! Commit current transaction
299
    bool TxnCommit();
300
    //! Abort current transaction
301
    bool TxnAbort();
302
0
    bool HasActiveTxn() { return m_batch->HasActiveTxn(); }
303
304
    //! Registers db txn callback functions
305
    void RegisterTxnListener(const DbTxnListener& l);
306
307
private:
308
    std::unique_ptr<DatabaseBatch> m_batch;
309
    WalletDatabase& m_database;
310
311
    // External functions listening to the current db txn outcome.
312
    // Listeners are cleared at the end of the transaction.
313
    std::vector<DbTxnListener> m_txn_listeners;
314
};
315
316
/**
317
 * Executes the provided function 'func' within a database transaction context.
318
 *
319
 * This function ensures that all db modifications performed within 'func()' are
320
 * atomically committed to the db at the end of the process. And, in case of a
321
 * failure during execution, all performed changes are rolled back.
322
 *
323
 * @param database The db connection instance to perform the transaction on.
324
 * @param process_desc A description of the process being executed, used for logging purposes in the event of a failure.
325
 * @param func The function to be executed within the db txn context. It returns a boolean indicating whether to commit or roll back the txn.
326
 * @return true if the db txn executed successfully, false otherwise.
327
 */
328
bool RunWithinTxn(WalletDatabase& database, std::string_view process_desc, const std::function<bool(WalletBatch&)>& func);
329
330
//! Compacts BDB state so that wallet.dat is self-contained (if there are changes)
331
void MaybeCompactWalletDB(WalletContext& context);
332
333
bool LoadKey(CWallet* pwallet, DataStream& ssKey, DataStream& ssValue, std::string& strErr);
334
bool LoadCryptedKey(CWallet* pwallet, DataStream& ssKey, DataStream& ssValue, std::string& strErr);
335
bool LoadEncryptionKey(CWallet* pwallet, DataStream& ssKey, DataStream& ssValue, std::string& strErr);
336
bool LoadHDChain(CWallet* pwallet, DataStream& ssValue, std::string& strErr);
337
338
//! Returns true if there are any DBKeys::LEGACY_TYPES record in the wallet db
339
bool HasLegacyRecords(CWallet& wallet);
340
bool HasLegacyRecords(CWallet& wallet, DatabaseBatch& batch);
341
} // namespace wallet
342
343
#endif // BITCOIN_WALLET_WALLETDB_H