/bitcoin/src/wallet/walletdb.h
Line | Count | Source |
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 <util/transaction_identifier.h> |
11 | | #include <wallet/db.h> |
12 | | #include <wallet/walletutil.h> |
13 | | #include <key.h> |
14 | | |
15 | | #include <stdint.h> |
16 | | #include <string> |
17 | | #include <vector> |
18 | | |
19 | | class CScript; |
20 | | class uint160; |
21 | | class uint256; |
22 | | struct CBlockLocator; |
23 | | |
24 | | namespace wallet { |
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 | | |
37 | | /** Error statuses for the wallet database. |
38 | | * Values are in order of severity. When multiple errors occur, the most severe (highest value) will be returned. |
39 | | */ |
40 | | enum class DBErrors : int |
41 | | { |
42 | | LOAD_OK = 0, |
43 | | NEED_RESCAN = 1, |
44 | | NEED_REWRITE = 2, |
45 | | EXTERNAL_SIGNER_SUPPORT_REQUIRED = 3, |
46 | | NONCRITICAL_ERROR = 4, |
47 | | TOO_NEW = 5, |
48 | | UNKNOWN_DESCRIPTOR = 6, |
49 | | LOAD_FAIL = 7, |
50 | | UNEXPECTED_LEGACY_ENTRY = 8, |
51 | | LEGACY_WALLET = 9, |
52 | | CORRUPT = 10, |
53 | | }; |
54 | | |
55 | | namespace DBKeys { |
56 | | extern const std::string ACENTRY; |
57 | | extern const std::string ACTIVEEXTERNALSPK; |
58 | | extern const std::string ACTIVEINTERNALSPK; |
59 | | extern const std::string BESTBLOCK; |
60 | | extern const std::string BESTBLOCK_NOMERKLE; |
61 | | extern const std::string CRYPTED_KEY; |
62 | | extern const std::string CSCRIPT; |
63 | | extern const std::string DEFAULTKEY; |
64 | | extern const std::string DESTDATA; |
65 | | extern const std::string FLAGS; |
66 | | extern const std::string HDCHAIN; |
67 | | extern const std::string KEY; |
68 | | extern const std::string KEYMETA; |
69 | | extern const std::string LOCKED_UTXO; |
70 | | extern const std::string MASTER_KEY; |
71 | | extern const std::string MINVERSION; |
72 | | extern const std::string NAME; |
73 | | extern const std::string OLD_KEY; |
74 | | extern const std::string ORDERPOSNEXT; |
75 | | extern const std::string POOL; |
76 | | extern const std::string PURPOSE; |
77 | | extern const std::string SETTINGS; |
78 | | extern const std::string TX; |
79 | | extern const std::string VERSION; |
80 | | extern const std::string WALLETDESCRIPTOR; |
81 | | extern const std::string WALLETDESCRIPTORCKEY; |
82 | | extern const std::string WALLETDESCRIPTORKEY; |
83 | | extern const std::string WATCHMETA; |
84 | | extern const std::string WATCHS; |
85 | | |
86 | | // Keys in this set pertain only to the legacy wallet (LegacyScriptPubKeyMan) and are removed during migration from legacy to descriptors. |
87 | | extern const std::unordered_set<std::string> LEGACY_TYPES; |
88 | | } // namespace DBKeys |
89 | | |
90 | | /* simple HD chain data model */ |
91 | | class CHDChain |
92 | | { |
93 | | public: |
94 | | uint32_t nExternalChainCounter; |
95 | | uint32_t nInternalChainCounter; |
96 | | CKeyID seed_id; //!< seed hash160 |
97 | | int64_t m_next_external_index{0}; // Next index in the keypool to be used. Memory only. |
98 | | int64_t m_next_internal_index{0}; // Next index in the keypool to be used. Memory only. |
99 | | |
100 | | static const int VERSION_HD_BASE = 1; |
101 | | static const int VERSION_HD_CHAIN_SPLIT = 2; |
102 | | static const int CURRENT_VERSION = VERSION_HD_CHAIN_SPLIT; |
103 | | int nVersion; |
104 | | |
105 | 0 | CHDChain() { SetNull(); } |
106 | | |
107 | | SERIALIZE_METHODS(CHDChain, obj) |
108 | 0 | { |
109 | 0 | READWRITE(obj.nVersion, obj.nExternalChainCounter, obj.seed_id); |
110 | 0 | if (obj.nVersion >= VERSION_HD_CHAIN_SPLIT) { Branch (110:13): [True: 0, False: 0]
|
111 | 0 | READWRITE(obj.nInternalChainCounter); |
112 | 0 | } |
113 | 0 | } |
114 | | |
115 | | void SetNull() |
116 | 0 | { |
117 | 0 | nVersion = CHDChain::CURRENT_VERSION; |
118 | 0 | nExternalChainCounter = 0; |
119 | 0 | nInternalChainCounter = 0; |
120 | 0 | seed_id.SetNull(); |
121 | 0 | } |
122 | | |
123 | | bool operator==(const CHDChain& chain) const |
124 | 0 | { |
125 | 0 | return seed_id == chain.seed_id; |
126 | 0 | } |
127 | | }; |
128 | | |
129 | | class CKeyMetadata |
130 | | { |
131 | | public: |
132 | | static const int VERSION_BASIC=1; |
133 | | static const int VERSION_WITH_HDDATA=10; |
134 | | static const int VERSION_WITH_KEY_ORIGIN = 12; |
135 | | static const int CURRENT_VERSION=VERSION_WITH_KEY_ORIGIN; |
136 | | int nVersion; |
137 | | int64_t nCreateTime; // 0 means unknown |
138 | | std::string hdKeypath; //optional HD/bip32 keypath. Still used to determine whether a key is a seed. Also kept for backwards compatibility |
139 | | CKeyID hd_seed_id; //id of the HD seed used to derive this key |
140 | | KeyOriginInfo key_origin; // Key origin info with path and fingerprint |
141 | | bool has_key_origin = false; //!< Whether the key_origin is useful |
142 | | |
143 | | CKeyMetadata() |
144 | 0 | { |
145 | 0 | SetNull(); |
146 | 0 | } |
147 | | explicit CKeyMetadata(int64_t nCreateTime_) |
148 | 0 | { |
149 | 0 | SetNull(); |
150 | 0 | nCreateTime = nCreateTime_; |
151 | 0 | } |
152 | | |
153 | | SERIALIZE_METHODS(CKeyMetadata, obj) |
154 | 0 | { |
155 | 0 | READWRITE(obj.nVersion, obj.nCreateTime); |
156 | 0 | if (obj.nVersion >= VERSION_WITH_HDDATA) { Branch (156:13): [True: 0, False: 0]
Branch (156:13): [True: 0, False: 0]
|
157 | 0 | READWRITE(obj.hdKeypath, obj.hd_seed_id); |
158 | 0 | } |
159 | 0 | if (obj.nVersion >= VERSION_WITH_KEY_ORIGIN) Branch (159:13): [True: 0, False: 0]
Branch (159:13): [True: 0, False: 0]
|
160 | 0 | { |
161 | 0 | READWRITE(obj.key_origin); |
162 | 0 | READWRITE(obj.has_key_origin); |
163 | 0 | } |
164 | 0 | } Unexecuted instantiation: void wallet::CKeyMetadata::SerializationOps<DataStream, wallet::CKeyMetadata, ActionUnserialize>(wallet::CKeyMetadata&, DataStream&, ActionUnserialize) Unexecuted instantiation: void wallet::CKeyMetadata::SerializationOps<DataStream, wallet::CKeyMetadata const, ActionSerialize>(wallet::CKeyMetadata const&, DataStream&, ActionSerialize) |
165 | | |
166 | | void SetNull() |
167 | 0 | { |
168 | 0 | nVersion = CKeyMetadata::CURRENT_VERSION; |
169 | 0 | nCreateTime = 0; |
170 | 0 | hdKeypath.clear(); |
171 | 0 | hd_seed_id.SetNull(); |
172 | 0 | key_origin.clear(); |
173 | 0 | has_key_origin = false; |
174 | 0 | } |
175 | | }; |
176 | | |
177 | | struct DbTxnListener |
178 | | { |
179 | | std::function<void()> on_commit, on_abort; |
180 | | }; |
181 | | |
182 | | /** Access to the wallet database. |
183 | | * Opens the database and provides read and write access to it. Each read and write is its own transaction. |
184 | | * Multiple operation transactions can be started using TxnBegin() and committed using TxnCommit() |
185 | | * Otherwise the transaction will be committed when the object goes out of scope. |
186 | | * Optionally (on by default) it will flush to disk on close. |
187 | | * Every 1000 writes will automatically trigger a flush to disk. |
188 | | */ |
189 | | class WalletBatch |
190 | | { |
191 | | private: |
192 | | template <typename K, typename T> |
193 | | bool WriteIC(const K& key, const T& value, bool fOverwrite = true) |
194 | 784k | { |
195 | 784k | if (!m_batch->Write(key, value, fOverwrite)) { Branch (195:13): [True: 0, False: 0]
Branch (195:13): [True: 0, False: 0]
Branch (195:13): [True: 0, False: 0]
Branch (195:13): [True: 0, False: 0]
Branch (195:13): [True: 0, False: 0]
Branch (195:13): [True: 0, False: 0]
Branch (195:13): [True: 0, False: 0]
Branch (195:13): [True: 0, False: 0]
Branch (195:13): [True: 0, False: 52.1k]
Branch (195:13): [True: 0, False: 0]
Branch (195:13): [True: 0, False: 11.0k]
Branch (195:13): [True: 0, False: 88.7k]
Branch (195:13): [True: 0, False: 88.7k]
Branch (195:13): [True: 0, False: 0]
Branch (195:13): [True: 0, False: 266k]
Branch (195:13): [True: 0, False: 0]
Branch (195:13): [True: 0, False: 177k]
Branch (195:13): [True: 0, False: 0]
Branch (195:13): [True: 0, False: 0]
Branch (195:13): [True: 0, False: 99.8k]
|
196 | 0 | return false; |
197 | 0 | } |
198 | 784k | return true; |
199 | 784k | } Unexecuted instantiation: bool wallet::WalletBatch::WriteIC<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool) Unexecuted instantiation: bool wallet::WalletBatch::WriteIC<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, transaction_identifier<false> >, wallet::CWalletTx>(std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, transaction_identifier<false> > const&, wallet::CWalletTx const&, bool) Unexecuted instantiation: bool wallet::WalletBatch::WriteIC<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, CPubKey>, wallet::CKeyMetadata>(std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, CPubKey> const&, wallet::CKeyMetadata const&, bool) Unexecuted instantiation: bool wallet::WalletBatch::WriteIC<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, CPubKey>, std::pair<std::vector<unsigned char, secure_allocator<unsigned char> >, uint256> >(std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, CPubKey> const&, std::pair<std::vector<unsigned char, secure_allocator<unsigned char> >, uint256> const&, bool) Unexecuted instantiation: bool wallet::WalletBatch::WriteIC<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, CPubKey>, std::pair<std::vector<unsigned char, std::allocator<unsigned char> >, uint256> >(std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, CPubKey> const&, std::pair<std::vector<unsigned char, std::allocator<unsigned char> >, uint256> const&, bool) Unexecuted instantiation: bool wallet::WalletBatch::WriteIC<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, unsigned int>, wallet::CMasterKey>(std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, unsigned int> const&, wallet::CMasterKey const&, bool) Unexecuted instantiation: bool wallet::WalletBatch::WriteIC<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, CScript>, wallet::CKeyMetadata>(std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, CScript> const&, wallet::CKeyMetadata const&, bool) Unexecuted instantiation: bool wallet::WalletBatch::WriteIC<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, CScript>, unsigned char>(std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, CScript> const&, unsigned char const&, bool) bool wallet::WalletBatch::WriteIC<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, CBlockLocator>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, CBlockLocator const&, bool) Line | Count | Source | 194 | 52.1k | { | 195 | 52.1k | if (!m_batch->Write(key, value, fOverwrite)) { Branch (195:13): [True: 0, False: 52.1k]
| 196 | 0 | return false; | 197 | 0 | } | 198 | 52.1k | return true; | 199 | 52.1k | } |
Unexecuted instantiation: bool wallet::WalletBatch::WriteIC<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, long>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, long const&, bool) bool wallet::WalletBatch::WriteIC<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int const&, bool) Line | Count | Source | 194 | 11.0k | { | 195 | 11.0k | if (!m_batch->Write(key, value, fOverwrite)) { Branch (195:13): [True: 0, False: 11.0k]
| 196 | 0 | return false; | 197 | 0 | } | 198 | 11.0k | return true; | 199 | 11.0k | } |
bool wallet::WalletBatch::WriteIC<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, unsigned char>, uint256>(std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, unsigned char> const&, uint256 const&, bool) Line | Count | Source | 194 | 88.7k | { | 195 | 88.7k | if (!m_batch->Write(key, value, fOverwrite)) { Branch (195:13): [True: 0, False: 88.7k]
| 196 | 0 | return false; | 197 | 0 | } | 198 | 88.7k | return true; | 199 | 88.7k | } |
bool wallet::WalletBatch::WriteIC<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<uint256, CPubKey> >, std::pair<std::vector<unsigned char, secure_allocator<unsigned char> >, uint256> >(std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<uint256, CPubKey> > const&, std::pair<std::vector<unsigned char, secure_allocator<unsigned char> >, uint256> const&, bool) Line | Count | Source | 194 | 88.7k | { | 195 | 88.7k | if (!m_batch->Write(key, value, fOverwrite)) { Branch (195:13): [True: 0, False: 88.7k]
| 196 | 0 | return false; | 197 | 0 | } | 198 | 88.7k | return true; | 199 | 88.7k | } |
Unexecuted instantiation: bool wallet::WalletBatch::WriteIC<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<uint256, CPubKey> >, std::vector<unsigned char, std::allocator<unsigned char> > >(std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<uint256, CPubKey> > const&, std::vector<unsigned char, std::allocator<unsigned char> > const&, bool) bool wallet::WalletBatch::WriteIC<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, uint256>, wallet::WalletDescriptor>(std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, uint256> const&, wallet::WalletDescriptor const&, bool) Line | Count | Source | 194 | 266k | { | 195 | 266k | if (!m_batch->Write(key, value, fOverwrite)) { Branch (195:13): [True: 0, False: 266k]
| 196 | 0 | return false; | 197 | 0 | } | 198 | 266k | return true; | 199 | 266k | } |
Unexecuted instantiation: bool wallet::WalletBatch::WriteIC<std::pair<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, uint256>, std::pair<unsigned int, unsigned int> >, std::vector<unsigned char, std::allocator<unsigned char> > >(std::pair<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, uint256>, std::pair<unsigned int, unsigned int> > const&, std::vector<unsigned char, std::allocator<unsigned char> > const&, bool) bool wallet::WalletBatch::WriteIC<std::pair<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, uint256>, unsigned int>, std::vector<unsigned char, std::allocator<unsigned char> > >(std::pair<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, uint256>, unsigned int> const&, std::vector<unsigned char, std::allocator<unsigned char> > const&, bool) Line | Count | Source | 194 | 177k | { | 195 | 177k | if (!m_batch->Write(key, value, fOverwrite)) { Branch (195:13): [True: 0, False: 177k]
| 196 | 0 | return false; | 197 | 0 | } | 198 | 177k | return true; | 199 | 177k | } |
Unexecuted instantiation: bool wallet::WalletBatch::WriteIC<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<transaction_identifier<false>, unsigned int> >, unsigned char>(std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<transaction_identifier<false>, unsigned int> > const&, unsigned char const&, bool) Unexecuted instantiation: bool wallet::WalletBatch::WriteIC<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool) bool wallet::WalletBatch::WriteIC<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, unsigned long>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned long const&, bool) Line | Count | Source | 194 | 99.8k | { | 195 | 99.8k | if (!m_batch->Write(key, value, fOverwrite)) { Branch (195:13): [True: 0, False: 99.8k]
| 196 | 0 | return false; | 197 | 0 | } | 198 | 99.8k | return true; | 199 | 99.8k | } |
|
200 | | |
201 | | template <typename K> |
202 | | bool EraseIC(const K& key) |
203 | 0 | { |
204 | 0 | if (!m_batch->Erase(key)) { Branch (204:13): [True: 0, False: 0]
Branch (204:13): [True: 0, False: 0]
Branch (204:13): [True: 0, False: 0]
Branch (204:13): [True: 0, False: 0]
Branch (204:13): [True: 0, False: 0]
Branch (204:13): [True: 0, False: 0]
Branch (204:13): [True: 0, False: 0]
Branch (204:13): [True: 0, False: 0]
Branch (204:13): [True: 0, False: 0]
|
205 | 0 | return false; |
206 | 0 | } |
207 | 0 | return true; |
208 | 0 | } Unexecuted instantiation: bool wallet::WalletBatch::EraseIC<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >(std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > const&) Unexecuted instantiation: bool wallet::WalletBatch::EraseIC<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, uint256> >(std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, uint256> const&) Unexecuted instantiation: bool wallet::WalletBatch::EraseIC<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, CPubKey> >(std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, CPubKey> const&) Unexecuted instantiation: bool wallet::WalletBatch::EraseIC<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, unsigned int> >(std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, unsigned int> const&) Unexecuted instantiation: bool wallet::WalletBatch::EraseIC<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, CScript> >(std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, CScript> const&) Unexecuted instantiation: bool wallet::WalletBatch::EraseIC<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, unsigned char> >(std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, unsigned char> const&) Unexecuted instantiation: bool wallet::WalletBatch::EraseIC<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<uint256, CPubKey> > >(std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<uint256, CPubKey> > const&) Unexecuted instantiation: bool wallet::WalletBatch::EraseIC<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<transaction_identifier<false>, unsigned int> > >(std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<transaction_identifier<false>, unsigned int> > const&) Unexecuted instantiation: bool wallet::WalletBatch::EraseIC<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >(std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&) |
209 | | |
210 | | public: |
211 | | explicit WalletBatch(WalletDatabase &database) : |
212 | 181k | m_batch(database.MakeBatch()) |
213 | 181k | { |
214 | 181k | } |
215 | | WalletBatch(const WalletBatch&) = delete; |
216 | | WalletBatch& operator=(const WalletBatch&) = delete; |
217 | | |
218 | | bool WriteName(const std::string& strAddress, const std::string& strName); |
219 | | bool EraseName(const std::string& strAddress); |
220 | | |
221 | | bool WritePurpose(const std::string& strAddress, const std::string& purpose); |
222 | | bool ErasePurpose(const std::string& strAddress); |
223 | | |
224 | | bool WriteTx(const CWalletTx& wtx); |
225 | | bool EraseTx(Txid hash); |
226 | | |
227 | | bool WriteKeyMetadata(const CKeyMetadata& meta, const CPubKey& pubkey, const bool overwrite); |
228 | | bool WriteKey(const CPubKey& vchPubKey, const CPrivKey& vchPrivKey, const CKeyMetadata &keyMeta); |
229 | | bool WriteCryptedKey(const CPubKey& vchPubKey, const std::vector<unsigned char>& vchCryptedSecret, const CKeyMetadata &keyMeta); |
230 | | bool WriteMasterKey(unsigned int nID, const CMasterKey& kMasterKey); |
231 | | bool EraseMasterKey(unsigned int id); |
232 | | |
233 | | bool WriteWatchOnly(const CScript &script, const CKeyMetadata &keymeta); |
234 | | bool EraseWatchOnly(const CScript &script); |
235 | | |
236 | | bool WriteBestBlock(const CBlockLocator& locator); |
237 | | bool ReadBestBlock(CBlockLocator& locator); |
238 | | |
239 | | // Returns true if wallet stores encryption keys |
240 | | bool IsEncrypted(); |
241 | | |
242 | | bool WriteOrderPosNext(int64_t nOrderPosNext); |
243 | | |
244 | | bool WriteMinVersion(int nVersion); |
245 | | |
246 | | bool WriteDescriptorKey(const uint256& desc_id, const CPubKey& pubkey, const CPrivKey& privkey); |
247 | | bool WriteCryptedDescriptorKey(const uint256& desc_id, const CPubKey& pubkey, const std::vector<unsigned char>& secret); |
248 | | bool WriteDescriptor(const uint256& desc_id, const WalletDescriptor& descriptor); |
249 | | bool WriteDescriptorDerivedCache(const CExtPubKey& xpub, const uint256& desc_id, uint32_t key_exp_index, uint32_t der_index); |
250 | | bool WriteDescriptorParentCache(const CExtPubKey& xpub, const uint256& desc_id, uint32_t key_exp_index); |
251 | | bool WriteDescriptorLastHardenedCache(const CExtPubKey& xpub, const uint256& desc_id, uint32_t key_exp_index); |
252 | | bool WriteDescriptorCacheItems(const uint256& desc_id, const DescriptorCache& cache); |
253 | | |
254 | | bool WriteLockedUTXO(const COutPoint& output); |
255 | | bool EraseLockedUTXO(const COutPoint& output); |
256 | | |
257 | | bool WriteAddressPreviouslySpent(const CTxDestination& dest, bool previously_spent); |
258 | | bool WriteAddressReceiveRequest(const CTxDestination& dest, const std::string& id, const std::string& receive_request); |
259 | | bool EraseAddressReceiveRequest(const CTxDestination& dest, const std::string& id); |
260 | | bool EraseAddressData(const CTxDestination& dest); |
261 | | |
262 | | bool WriteActiveScriptPubKeyMan(uint8_t type, const uint256& id, bool internal); |
263 | | bool EraseActiveScriptPubKeyMan(uint8_t type, bool internal); |
264 | | |
265 | | DBErrors LoadWallet(CWallet* pwallet); |
266 | | |
267 | | //! Delete records of the given types |
268 | | bool EraseRecords(const std::unordered_set<std::string>& types); |
269 | | |
270 | | bool WriteWalletFlags(const uint64_t flags); |
271 | | //! Begin a new transaction |
272 | | bool TxnBegin(); |
273 | | //! Commit current transaction |
274 | | bool TxnCommit(); |
275 | | //! Abort current transaction |
276 | | bool TxnAbort(); |
277 | 0 | bool HasActiveTxn() { return m_batch->HasActiveTxn(); } |
278 | | |
279 | | //! Registers db txn callback functions |
280 | | void RegisterTxnListener(const DbTxnListener& l); |
281 | | |
282 | | private: |
283 | | std::unique_ptr<DatabaseBatch> m_batch; |
284 | | |
285 | | // External functions listening to the current db txn outcome. |
286 | | // Listeners are cleared at the end of the transaction. |
287 | | std::vector<DbTxnListener> m_txn_listeners; |
288 | | }; |
289 | | |
290 | | /** |
291 | | * Executes the provided function 'func' within a database transaction context. |
292 | | * |
293 | | * This function ensures that all db modifications performed within 'func()' are |
294 | | * atomically committed to the db at the end of the process. And, in case of a |
295 | | * failure during execution, all performed changes are rolled back. |
296 | | * |
297 | | * @param database The db connection instance to perform the transaction on. |
298 | | * @param process_desc A description of the process being executed, used for logging purposes in the event of a failure. |
299 | | * @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. |
300 | | * @return true if the db txn executed successfully, false otherwise. |
301 | | */ |
302 | | bool RunWithinTxn(WalletDatabase& database, std::string_view process_desc, const std::function<bool(WalletBatch&)>& func); |
303 | | |
304 | | bool LoadKey(CWallet* pwallet, DataStream& ssKey, DataStream& ssValue, std::string& strErr); |
305 | | bool LoadCryptedKey(CWallet* pwallet, DataStream& ssKey, DataStream& ssValue, std::string& strErr); |
306 | | bool LoadEncryptionKey(CWallet* pwallet, DataStream& ssKey, DataStream& ssValue, std::string& strErr); |
307 | | bool LoadHDChain(CWallet* pwallet, DataStream& ssValue, std::string& strErr); |
308 | | |
309 | | //! Returns true if there are any DBKeys::LEGACY_TYPES record in the wallet db |
310 | | bool HasLegacyRecords(CWallet& wallet); |
311 | | bool HasLegacyRecords(CWallet& wallet, DatabaseBatch& batch); |
312 | | } // namespace wallet |
313 | | |
314 | | #endif // BITCOIN_WALLET_WALLETDB_H |