Bitcoin Core  22.99.0
P2P Digital Currency
walletdb.cpp
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2021 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 #include <wallet/walletdb.h>
7 
8 #include <fs.h>
9 #include <key_io.h>
10 #include <protocol.h>
11 #include <serialize.h>
12 #include <sync.h>
13 #include <util/bip32.h>
14 #include <util/system.h>
15 #include <util/time.h>
16 #include <util/translation.h>
17 #ifdef USE_BDB
18 #include <wallet/bdb.h>
19 #endif
20 #ifdef USE_SQLITE
21 #include <wallet/sqlite.h>
22 #endif
23 #include <wallet/wallet.h>
24 
25 #include <atomic>
26 #include <optional>
27 #include <string>
28 
29 namespace wallet {
30 namespace DBKeys {
31 const std::string ACENTRY{"acentry"};
32 const std::string ACTIVEEXTERNALSPK{"activeexternalspk"};
33 const std::string ACTIVEINTERNALSPK{"activeinternalspk"};
34 const std::string BESTBLOCK_NOMERKLE{"bestblock_nomerkle"};
35 const std::string BESTBLOCK{"bestblock"};
36 const std::string CRYPTED_KEY{"ckey"};
37 const std::string CSCRIPT{"cscript"};
38 const std::string DEFAULTKEY{"defaultkey"};
39 const std::string DESTDATA{"destdata"};
40 const std::string FLAGS{"flags"};
41 const std::string HDCHAIN{"hdchain"};
42 const std::string KEYMETA{"keymeta"};
43 const std::string KEY{"key"};
44 const std::string LOCKED_UTXO{"lockedutxo"};
45 const std::string MASTER_KEY{"mkey"};
46 const std::string MINVERSION{"minversion"};
47 const std::string NAME{"name"};
48 const std::string OLD_KEY{"wkey"};
49 const std::string ORDERPOSNEXT{"orderposnext"};
50 const std::string POOL{"pool"};
51 const std::string PURPOSE{"purpose"};
52 const std::string SETTINGS{"settings"};
53 const std::string TX{"tx"};
54 const std::string VERSION{"version"};
55 const std::string WALLETDESCRIPTOR{"walletdescriptor"};
56 const std::string WALLETDESCRIPTORCACHE{"walletdescriptorcache"};
57 const std::string WALLETDESCRIPTORLHCACHE{"walletdescriptorlhcache"};
58 const std::string WALLETDESCRIPTORCKEY{"walletdescriptorckey"};
59 const std::string WALLETDESCRIPTORKEY{"walletdescriptorkey"};
60 const std::string WATCHMETA{"watchmeta"};
61 const std::string WATCHS{"watchs"};
62 } // namespace DBKeys
63 
64 //
65 // WalletBatch
66 //
67 
68 bool WalletBatch::WriteName(const std::string& strAddress, const std::string& strName)
69 {
70  return WriteIC(std::make_pair(DBKeys::NAME, strAddress), strName);
71 }
72 
73 bool WalletBatch::EraseName(const std::string& strAddress)
74 {
75  // This should only be used for sending addresses, never for receiving addresses,
76  // receiving addresses must always have an address book entry if they're not change return.
77  return EraseIC(std::make_pair(DBKeys::NAME, strAddress));
78 }
79 
80 bool WalletBatch::WritePurpose(const std::string& strAddress, const std::string& strPurpose)
81 {
82  return WriteIC(std::make_pair(DBKeys::PURPOSE, strAddress), strPurpose);
83 }
84 
85 bool WalletBatch::ErasePurpose(const std::string& strAddress)
86 {
87  return EraseIC(std::make_pair(DBKeys::PURPOSE, strAddress));
88 }
89 
91 {
92  return WriteIC(std::make_pair(DBKeys::TX, wtx.GetHash()), wtx);
93 }
94 
96 {
97  return EraseIC(std::make_pair(DBKeys::TX, hash));
98 }
99 
100 bool WalletBatch::WriteKeyMetadata(const CKeyMetadata& meta, const CPubKey& pubkey, const bool overwrite)
101 {
102  return WriteIC(std::make_pair(DBKeys::KEYMETA, pubkey), meta, overwrite);
103 }
104 
105 bool WalletBatch::WriteKey(const CPubKey& vchPubKey, const CPrivKey& vchPrivKey, const CKeyMetadata& keyMeta)
106 {
107  if (!WriteKeyMetadata(keyMeta, vchPubKey, false)) {
108  return false;
109  }
110 
111  // hash pubkey/privkey to accelerate wallet load
112  std::vector<unsigned char> vchKey;
113  vchKey.reserve(vchPubKey.size() + vchPrivKey.size());
114  vchKey.insert(vchKey.end(), vchPubKey.begin(), vchPubKey.end());
115  vchKey.insert(vchKey.end(), vchPrivKey.begin(), vchPrivKey.end());
116 
117  return WriteIC(std::make_pair(DBKeys::KEY, vchPubKey), std::make_pair(vchPrivKey, Hash(vchKey)), false);
118 }
119 
120 bool WalletBatch::WriteCryptedKey(const CPubKey& vchPubKey,
121  const std::vector<unsigned char>& vchCryptedSecret,
122  const CKeyMetadata &keyMeta)
123 {
124  if (!WriteKeyMetadata(keyMeta, vchPubKey, true)) {
125  return false;
126  }
127 
128  // Compute a checksum of the encrypted key
129  uint256 checksum = Hash(vchCryptedSecret);
130 
131  const auto key = std::make_pair(DBKeys::CRYPTED_KEY, vchPubKey);
132  if (!WriteIC(key, std::make_pair(vchCryptedSecret, checksum), false)) {
133  // It may already exist, so try writing just the checksum
134  std::vector<unsigned char> val;
135  if (!m_batch->Read(key, val)) {
136  return false;
137  }
138  if (!WriteIC(key, std::make_pair(val, checksum), true)) {
139  return false;
140  }
141  }
142  EraseIC(std::make_pair(DBKeys::KEY, vchPubKey));
143  return true;
144 }
145 
146 bool WalletBatch::WriteMasterKey(unsigned int nID, const CMasterKey& kMasterKey)
147 {
148  return WriteIC(std::make_pair(DBKeys::MASTER_KEY, nID), kMasterKey, true);
149 }
150 
151 bool WalletBatch::WriteCScript(const uint160& hash, const CScript& redeemScript)
152 {
153  return WriteIC(std::make_pair(DBKeys::CSCRIPT, hash), redeemScript, false);
154 }
155 
156 bool WalletBatch::WriteWatchOnly(const CScript &dest, const CKeyMetadata& keyMeta)
157 {
158  if (!WriteIC(std::make_pair(DBKeys::WATCHMETA, dest), keyMeta)) {
159  return false;
160  }
161  return WriteIC(std::make_pair(DBKeys::WATCHS, dest), uint8_t{'1'});
162 }
163 
165 {
166  if (!EraseIC(std::make_pair(DBKeys::WATCHMETA, dest))) {
167  return false;
168  }
169  return EraseIC(std::make_pair(DBKeys::WATCHS, dest));
170 }
171 
173 {
174  WriteIC(DBKeys::BESTBLOCK, CBlockLocator()); // Write empty block locator so versions that require a merkle branch automatically rescan
175  return WriteIC(DBKeys::BESTBLOCK_NOMERKLE, locator);
176 }
177 
179 {
180  if (m_batch->Read(DBKeys::BESTBLOCK, locator) && !locator.vHave.empty()) return true;
181  return m_batch->Read(DBKeys::BESTBLOCK_NOMERKLE, locator);
182 }
183 
184 bool WalletBatch::WriteOrderPosNext(int64_t nOrderPosNext)
185 {
186  return WriteIC(DBKeys::ORDERPOSNEXT, nOrderPosNext);
187 }
188 
189 bool WalletBatch::ReadPool(int64_t nPool, CKeyPool& keypool)
190 {
191  return m_batch->Read(std::make_pair(DBKeys::POOL, nPool), keypool);
192 }
193 
194 bool WalletBatch::WritePool(int64_t nPool, const CKeyPool& keypool)
195 {
196  return WriteIC(std::make_pair(DBKeys::POOL, nPool), keypool);
197 }
198 
199 bool WalletBatch::ErasePool(int64_t nPool)
200 {
201  return EraseIC(std::make_pair(DBKeys::POOL, nPool));
202 }
203 
205 {
206  return WriteIC(DBKeys::MINVERSION, nVersion);
207 }
208 
209 bool WalletBatch::WriteActiveScriptPubKeyMan(uint8_t type, const uint256& id, bool internal)
210 {
211  std::string key = internal ? DBKeys::ACTIVEINTERNALSPK : DBKeys::ACTIVEEXTERNALSPK;
212  return WriteIC(make_pair(key, type), id);
213 }
214 
215 bool WalletBatch::EraseActiveScriptPubKeyMan(uint8_t type, bool internal)
216 {
217  const std::string key{internal ? DBKeys::ACTIVEINTERNALSPK : DBKeys::ACTIVEEXTERNALSPK};
218  return EraseIC(make_pair(key, type));
219 }
220 
221 bool WalletBatch::WriteDescriptorKey(const uint256& desc_id, const CPubKey& pubkey, const CPrivKey& privkey)
222 {
223  // hash pubkey/privkey to accelerate wallet load
224  std::vector<unsigned char> key;
225  key.reserve(pubkey.size() + privkey.size());
226  key.insert(key.end(), pubkey.begin(), pubkey.end());
227  key.insert(key.end(), privkey.begin(), privkey.end());
228 
229  return WriteIC(std::make_pair(DBKeys::WALLETDESCRIPTORKEY, std::make_pair(desc_id, pubkey)), std::make_pair(privkey, Hash(key)), false);
230 }
231 
232 bool WalletBatch::WriteCryptedDescriptorKey(const uint256& desc_id, const CPubKey& pubkey, const std::vector<unsigned char>& secret)
233 {
234  if (!WriteIC(std::make_pair(DBKeys::WALLETDESCRIPTORCKEY, std::make_pair(desc_id, pubkey)), secret, false)) {
235  return false;
236  }
237  EraseIC(std::make_pair(DBKeys::WALLETDESCRIPTORKEY, std::make_pair(desc_id, pubkey)));
238  return true;
239 }
240 
241 bool WalletBatch::WriteDescriptor(const uint256& desc_id, const WalletDescriptor& descriptor)
242 {
243  return WriteIC(make_pair(DBKeys::WALLETDESCRIPTOR, desc_id), descriptor);
244 }
245 
246 bool WalletBatch::WriteDescriptorDerivedCache(const CExtPubKey& xpub, const uint256& desc_id, uint32_t key_exp_index, uint32_t der_index)
247 {
248  std::vector<unsigned char> ser_xpub(BIP32_EXTKEY_SIZE);
249  xpub.Encode(ser_xpub.data());
250  return WriteIC(std::make_pair(std::make_pair(DBKeys::WALLETDESCRIPTORCACHE, desc_id), std::make_pair(key_exp_index, der_index)), ser_xpub);
251 }
252 
253 bool WalletBatch::WriteDescriptorParentCache(const CExtPubKey& xpub, const uint256& desc_id, uint32_t key_exp_index)
254 {
255  std::vector<unsigned char> ser_xpub(BIP32_EXTKEY_SIZE);
256  xpub.Encode(ser_xpub.data());
257  return WriteIC(std::make_pair(std::make_pair(DBKeys::WALLETDESCRIPTORCACHE, desc_id), key_exp_index), ser_xpub);
258 }
259 
260 bool WalletBatch::WriteDescriptorLastHardenedCache(const CExtPubKey& xpub, const uint256& desc_id, uint32_t key_exp_index)
261 {
262  std::vector<unsigned char> ser_xpub(BIP32_EXTKEY_SIZE);
263  xpub.Encode(ser_xpub.data());
264  return WriteIC(std::make_pair(std::make_pair(DBKeys::WALLETDESCRIPTORLHCACHE, desc_id), key_exp_index), ser_xpub);
265 }
266 
268 {
269  for (const auto& parent_xpub_pair : cache.GetCachedParentExtPubKeys()) {
270  if (!WriteDescriptorParentCache(parent_xpub_pair.second, desc_id, parent_xpub_pair.first)) {
271  return false;
272  }
273  }
274  for (const auto& derived_xpub_map_pair : cache.GetCachedDerivedExtPubKeys()) {
275  for (const auto& derived_xpub_pair : derived_xpub_map_pair.second) {
276  if (!WriteDescriptorDerivedCache(derived_xpub_pair.second, desc_id, derived_xpub_map_pair.first, derived_xpub_pair.first)) {
277  return false;
278  }
279  }
280  }
281  for (const auto& lh_xpub_pair : cache.GetCachedLastHardenedExtPubKeys()) {
282  if (!WriteDescriptorLastHardenedCache(lh_xpub_pair.second, desc_id, lh_xpub_pair.first)) {
283  return false;
284  }
285  }
286  return true;
287 }
288 
290 {
291  return WriteIC(std::make_pair(DBKeys::LOCKED_UTXO, std::make_pair(output.hash, output.n)), uint8_t{'1'});
292 }
293 
295 {
296  return EraseIC(std::make_pair(DBKeys::LOCKED_UTXO, std::make_pair(output.hash, output.n)));
297 }
298 
300 public:
301  unsigned int nKeys{0};
302  unsigned int nCKeys{0};
303  unsigned int nWatchKeys{0};
304  unsigned int nKeyMeta{0};
305  unsigned int m_unknown_records{0};
306  bool fIsEncrypted{false};
307  bool fAnyUnordered{false};
308  std::vector<uint256> vWalletUpgrade;
309  std::map<OutputType, uint256> m_active_external_spks;
310  std::map<OutputType, uint256> m_active_internal_spks;
311  std::map<uint256, DescriptorCache> m_descriptor_caches;
312  std::map<std::pair<uint256, CKeyID>, CKey> m_descriptor_keys;
313  std::map<std::pair<uint256, CKeyID>, std::pair<CPubKey, std::vector<unsigned char>>> m_descriptor_crypt_keys;
314  std::map<uint160, CHDChain> m_hd_chains;
315  bool tx_corrupt{false};
316 
318  }
319 };
320 
321 static bool
322 ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue,
323  CWalletScanState &wss, std::string& strType, std::string& strErr, const KeyFilterFn& filter_fn = nullptr) EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet)
324 {
325  try {
326  // Unserialize
327  // Taking advantage of the fact that pair serialization
328  // is just the two items serialized one after the other
329  ssKey >> strType;
330  // If we have a filter, check if this matches the filter
331  if (filter_fn && !filter_fn(strType)) {
332  return true;
333  }
334  if (strType == DBKeys::NAME) {
335  std::string strAddress;
336  ssKey >> strAddress;
337  std::string label;
338  ssValue >> label;
339  pwallet->m_address_book[DecodeDestination(strAddress)].SetLabel(label);
340  } else if (strType == DBKeys::PURPOSE) {
341  std::string strAddress;
342  ssKey >> strAddress;
343  ssValue >> pwallet->m_address_book[DecodeDestination(strAddress)].purpose;
344  } else if (strType == DBKeys::TX) {
345  uint256 hash;
346  ssKey >> hash;
347  // LoadToWallet call below creates a new CWalletTx that fill_wtx
348  // callback fills with transaction metadata.
349  auto fill_wtx = [&](CWalletTx& wtx, bool new_tx) {
350  if(!new_tx) {
351  // There's some corruption here since the tx we just tried to load was already in the wallet.
352  // We don't consider this type of corruption critical, and can fix it by removing tx data and
353  // rescanning.
354  wss.tx_corrupt = true;
355  return false;
356  }
357  ssValue >> wtx;
358  if (wtx.GetHash() != hash)
359  return false;
360 
361  // Undo serialize changes in 31600
362  if (31404 <= wtx.fTimeReceivedIsTxTime && wtx.fTimeReceivedIsTxTime <= 31703)
363  {
364  if (!ssValue.empty())
365  {
366  uint8_t fTmp;
367  uint8_t fUnused;
368  std::string unused_string;
369  ssValue >> fTmp >> fUnused >> unused_string;
370  strErr = strprintf("LoadWallet() upgrading tx ver=%d %d %s",
371  wtx.fTimeReceivedIsTxTime, fTmp, hash.ToString());
372  wtx.fTimeReceivedIsTxTime = fTmp;
373  }
374  else
375  {
376  strErr = strprintf("LoadWallet() repairing tx ver=%d %s", wtx.fTimeReceivedIsTxTime, hash.ToString());
377  wtx.fTimeReceivedIsTxTime = 0;
378  }
379  wss.vWalletUpgrade.push_back(hash);
380  }
381 
382  if (wtx.nOrderPos == -1)
383  wss.fAnyUnordered = true;
384 
385  return true;
386  };
387  if (!pwallet->LoadToWallet(hash, fill_wtx)) {
388  return false;
389  }
390  } else if (strType == DBKeys::WATCHS) {
391  wss.nWatchKeys++;
392  CScript script;
393  ssKey >> script;
394  uint8_t fYes;
395  ssValue >> fYes;
396  if (fYes == '1') {
398  }
399  } else if (strType == DBKeys::KEY) {
400  CPubKey vchPubKey;
401  ssKey >> vchPubKey;
402  if (!vchPubKey.IsValid())
403  {
404  strErr = "Error reading wallet database: CPubKey corrupt";
405  return false;
406  }
407  CKey key;
408  CPrivKey pkey;
409  uint256 hash;
410 
411  wss.nKeys++;
412  ssValue >> pkey;
413 
414  // Old wallets store keys as DBKeys::KEY [pubkey] => [privkey]
415  // ... which was slow for wallets with lots of keys, because the public key is re-derived from the private key
416  // using EC operations as a checksum.
417  // Newer wallets store keys as DBKeys::KEY [pubkey] => [privkey][hash(pubkey,privkey)], which is much faster while
418  // remaining backwards-compatible.
419  try
420  {
421  ssValue >> hash;
422  }
423  catch (const std::ios_base::failure&) {}
424 
425  bool fSkipCheck = false;
426 
427  if (!hash.IsNull())
428  {
429  // hash pubkey/privkey to accelerate wallet load
430  std::vector<unsigned char> vchKey;
431  vchKey.reserve(vchPubKey.size() + pkey.size());
432  vchKey.insert(vchKey.end(), vchPubKey.begin(), vchPubKey.end());
433  vchKey.insert(vchKey.end(), pkey.begin(), pkey.end());
434 
435  if (Hash(vchKey) != hash)
436  {
437  strErr = "Error reading wallet database: CPubKey/CPrivKey corrupt";
438  return false;
439  }
440 
441  fSkipCheck = true;
442  }
443 
444  if (!key.Load(pkey, vchPubKey, fSkipCheck))
445  {
446  strErr = "Error reading wallet database: CPrivKey corrupt";
447  return false;
448  }
449  if (!pwallet->GetOrCreateLegacyScriptPubKeyMan()->LoadKey(key, vchPubKey))
450  {
451  strErr = "Error reading wallet database: LegacyScriptPubKeyMan::LoadKey failed";
452  return false;
453  }
454  } else if (strType == DBKeys::MASTER_KEY) {
455  // Master encryption key is loaded into only the wallet and not any of the ScriptPubKeyMans.
456  unsigned int nID;
457  ssKey >> nID;
458  CMasterKey kMasterKey;
459  ssValue >> kMasterKey;
460  if(pwallet->mapMasterKeys.count(nID) != 0)
461  {
462  strErr = strprintf("Error reading wallet database: duplicate CMasterKey id %u", nID);
463  return false;
464  }
465  pwallet->mapMasterKeys[nID] = kMasterKey;
466  if (pwallet->nMasterKeyMaxID < nID)
467  pwallet->nMasterKeyMaxID = nID;
468  } else if (strType == DBKeys::CRYPTED_KEY) {
469  CPubKey vchPubKey;
470  ssKey >> vchPubKey;
471  if (!vchPubKey.IsValid())
472  {
473  strErr = "Error reading wallet database: CPubKey corrupt";
474  return false;
475  }
476  std::vector<unsigned char> vchPrivKey;
477  ssValue >> vchPrivKey;
478 
479  // Get the checksum and check it
480  bool checksum_valid = false;
481  if (!ssValue.eof()) {
482  uint256 checksum;
483  ssValue >> checksum;
484  if ((checksum_valid = Hash(vchPrivKey) != checksum)) {
485  strErr = "Error reading wallet database: Encrypted key corrupt";
486  return false;
487  }
488  }
489 
490  wss.nCKeys++;
491 
492  if (!pwallet->GetOrCreateLegacyScriptPubKeyMan()->LoadCryptedKey(vchPubKey, vchPrivKey, checksum_valid))
493  {
494  strErr = "Error reading wallet database: LegacyScriptPubKeyMan::LoadCryptedKey failed";
495  return false;
496  }
497  wss.fIsEncrypted = true;
498  } else if (strType == DBKeys::KEYMETA) {
499  CPubKey vchPubKey;
500  ssKey >> vchPubKey;
501  CKeyMetadata keyMeta;
502  ssValue >> keyMeta;
503  wss.nKeyMeta++;
504  pwallet->GetOrCreateLegacyScriptPubKeyMan()->LoadKeyMetadata(vchPubKey.GetID(), keyMeta);
505 
506  // Extract some CHDChain info from this metadata if it has any
507  if (keyMeta.nVersion >= CKeyMetadata::VERSION_WITH_HDDATA && !keyMeta.hd_seed_id.IsNull() && keyMeta.hdKeypath.size() > 0) {
508  // Get the path from the key origin or from the path string
509  // Not applicable when path is "s" or "m" as those indicate a seed
510  // See https://github.com/bitcoin/bitcoin/pull/12924
511  bool internal = false;
512  uint32_t index = 0;
513  if (keyMeta.hdKeypath != "s" && keyMeta.hdKeypath != "m") {
514  std::vector<uint32_t> path;
515  if (keyMeta.has_key_origin) {
516  // We have a key origin, so pull it from its path vector
517  path = keyMeta.key_origin.path;
518  } else {
519  // No key origin, have to parse the string
520  if (!ParseHDKeypath(keyMeta.hdKeypath, path)) {
521  strErr = "Error reading wallet database: keymeta with invalid HD keypath";
522  return false;
523  }
524  }
525 
526  // Extract the index and internal from the path
527  // Path string is m/0'/k'/i'
528  // Path vector is [0', k', i'] (but as ints OR'd with the hardened bit
529  // k == 0 for external, 1 for internal. i is the index
530  if (path.size() != 3) {
531  strErr = "Error reading wallet database: keymeta found with unexpected path";
532  return false;
533  }
534  if (path[0] != 0x80000000) {
535  strErr = strprintf("Unexpected path index of 0x%08x (expected 0x80000000) for the element at index 0", path[0]);
536  return false;
537  }
538  if (path[1] != 0x80000000 && path[1] != (1 | 0x80000000)) {
539  strErr = strprintf("Unexpected path index of 0x%08x (expected 0x80000000 or 0x80000001) for the element at index 1", path[1]);
540  return false;
541  }
542  if ((path[2] & 0x80000000) == 0) {
543  strErr = strprintf("Unexpected path index of 0x%08x (expected to be greater than or equal to 0x80000000)", path[2]);
544  return false;
545  }
546  internal = path[1] == (1 | 0x80000000);
547  index = path[2] & ~0x80000000;
548  }
549 
550  // Insert a new CHDChain, or get the one that already exists
551  auto ins = wss.m_hd_chains.emplace(keyMeta.hd_seed_id, CHDChain());
552  CHDChain& chain = ins.first->second;
553  if (ins.second) {
554  // For new chains, we want to default to VERSION_HD_BASE until we see an internal
556  chain.seed_id = keyMeta.hd_seed_id;
557  }
558  if (internal) {
560  chain.nInternalChainCounter = std::max(chain.nInternalChainCounter, index);
561  } else {
562  chain.nExternalChainCounter = std::max(chain.nExternalChainCounter, index);
563  }
564  }
565  } else if (strType == DBKeys::WATCHMETA) {
566  CScript script;
567  ssKey >> script;
568  CKeyMetadata keyMeta;
569  ssValue >> keyMeta;
570  wss.nKeyMeta++;
571  pwallet->GetOrCreateLegacyScriptPubKeyMan()->LoadScriptMetadata(CScriptID(script), keyMeta);
572  } else if (strType == DBKeys::DEFAULTKEY) {
573  // We don't want or need the default key, but if there is one set,
574  // we want to make sure that it is valid so that we can detect corruption
575  CPubKey vchPubKey;
576  ssValue >> vchPubKey;
577  if (!vchPubKey.IsValid()) {
578  strErr = "Error reading wallet database: Default Key corrupt";
579  return false;
580  }
581  } else if (strType == DBKeys::POOL) {
582  int64_t nIndex;
583  ssKey >> nIndex;
584  CKeyPool keypool;
585  ssValue >> keypool;
586 
587  pwallet->GetOrCreateLegacyScriptPubKeyMan()->LoadKeyPool(nIndex, keypool);
588  } else if (strType == DBKeys::CSCRIPT) {
589  uint160 hash;
590  ssKey >> hash;
591  CScript script;
592  ssValue >> script;
593  if (!pwallet->GetOrCreateLegacyScriptPubKeyMan()->LoadCScript(script))
594  {
595  strErr = "Error reading wallet database: LegacyScriptPubKeyMan::LoadCScript failed";
596  return false;
597  }
598  } else if (strType == DBKeys::ORDERPOSNEXT) {
599  ssValue >> pwallet->nOrderPosNext;
600  } else if (strType == DBKeys::DESTDATA) {
601  std::string strAddress, strKey, strValue;
602  ssKey >> strAddress;
603  ssKey >> strKey;
604  ssValue >> strValue;
605  pwallet->LoadDestData(DecodeDestination(strAddress), strKey, strValue);
606  } else if (strType == DBKeys::HDCHAIN) {
607  CHDChain chain;
608  ssValue >> chain;
610  } else if (strType == DBKeys::OLD_KEY) {
611  strErr = "Found unsupported 'wkey' record, try loading with version 0.18";
612  return false;
613  } else if (strType == DBKeys::ACTIVEEXTERNALSPK || strType == DBKeys::ACTIVEINTERNALSPK) {
614  uint8_t type;
615  ssKey >> type;
616  uint256 id;
617  ssValue >> id;
618 
619  bool internal = strType == DBKeys::ACTIVEINTERNALSPK;
620  auto& spk_mans = internal ? wss.m_active_internal_spks : wss.m_active_external_spks;
621  if (spk_mans.count(static_cast<OutputType>(type)) > 0) {
622  strErr = "Multiple ScriptPubKeyMans specified for a single type";
623  return false;
624  }
625  spk_mans[static_cast<OutputType>(type)] = id;
626  } else if (strType == DBKeys::WALLETDESCRIPTOR) {
627  uint256 id;
628  ssKey >> id;
629  WalletDescriptor desc;
630  ssValue >> desc;
631  if (wss.m_descriptor_caches.count(id) == 0) {
633  }
634  pwallet->LoadDescriptorScriptPubKeyMan(id, desc);
635  } else if (strType == DBKeys::WALLETDESCRIPTORCACHE) {
636  bool parent = true;
637  uint256 desc_id;
638  uint32_t key_exp_index;
639  uint32_t der_index;
640  ssKey >> desc_id;
641  ssKey >> key_exp_index;
642 
643  // if the der_index exists, it's a derived xpub
644  try
645  {
646  ssKey >> der_index;
647  parent = false;
648  }
649  catch (...) {}
650 
651  std::vector<unsigned char> ser_xpub(BIP32_EXTKEY_SIZE);
652  ssValue >> ser_xpub;
653  CExtPubKey xpub;
654  xpub.Decode(ser_xpub.data());
655  if (parent) {
656  wss.m_descriptor_caches[desc_id].CacheParentExtPubKey(key_exp_index, xpub);
657  } else {
658  wss.m_descriptor_caches[desc_id].CacheDerivedExtPubKey(key_exp_index, der_index, xpub);
659  }
660  } else if (strType == DBKeys::WALLETDESCRIPTORLHCACHE) {
661  uint256 desc_id;
662  uint32_t key_exp_index;
663  ssKey >> desc_id;
664  ssKey >> key_exp_index;
665 
666  std::vector<unsigned char> ser_xpub(BIP32_EXTKEY_SIZE);
667  ssValue >> ser_xpub;
668  CExtPubKey xpub;
669  xpub.Decode(ser_xpub.data());
670  wss.m_descriptor_caches[desc_id].CacheLastHardenedExtPubKey(key_exp_index, xpub);
671  } else if (strType == DBKeys::WALLETDESCRIPTORKEY) {
672  uint256 desc_id;
673  CPubKey pubkey;
674  ssKey >> desc_id;
675  ssKey >> pubkey;
676  if (!pubkey.IsValid())
677  {
678  strErr = "Error reading wallet database: CPubKey corrupt";
679  return false;
680  }
681  CKey key;
682  CPrivKey pkey;
683  uint256 hash;
684 
685  wss.nKeys++;
686  ssValue >> pkey;
687  ssValue >> hash;
688 
689  // hash pubkey/privkey to accelerate wallet load
690  std::vector<unsigned char> to_hash;
691  to_hash.reserve(pubkey.size() + pkey.size());
692  to_hash.insert(to_hash.end(), pubkey.begin(), pubkey.end());
693  to_hash.insert(to_hash.end(), pkey.begin(), pkey.end());
694 
695  if (Hash(to_hash) != hash)
696  {
697  strErr = "Error reading wallet database: CPubKey/CPrivKey corrupt";
698  return false;
699  }
700 
701  if (!key.Load(pkey, pubkey, true))
702  {
703  strErr = "Error reading wallet database: CPrivKey corrupt";
704  return false;
705  }
706  wss.m_descriptor_keys.insert(std::make_pair(std::make_pair(desc_id, pubkey.GetID()), key));
707  } else if (strType == DBKeys::WALLETDESCRIPTORCKEY) {
708  uint256 desc_id;
709  CPubKey pubkey;
710  ssKey >> desc_id;
711  ssKey >> pubkey;
712  if (!pubkey.IsValid())
713  {
714  strErr = "Error reading wallet database: CPubKey corrupt";
715  return false;
716  }
717  std::vector<unsigned char> privkey;
718  ssValue >> privkey;
719  wss.nCKeys++;
720 
721  wss.m_descriptor_crypt_keys.insert(std::make_pair(std::make_pair(desc_id, pubkey.GetID()), std::make_pair(pubkey, privkey)));
722  wss.fIsEncrypted = true;
723  } else if (strType == DBKeys::LOCKED_UTXO) {
724  uint256 hash;
725  uint32_t n;
726  ssKey >> hash;
727  ssKey >> n;
728  pwallet->LockCoin(COutPoint(hash, n));
729  } else if (strType != DBKeys::BESTBLOCK && strType != DBKeys::BESTBLOCK_NOMERKLE &&
730  strType != DBKeys::MINVERSION && strType != DBKeys::ACENTRY &&
731  strType != DBKeys::VERSION && strType != DBKeys::SETTINGS &&
732  strType != DBKeys::FLAGS) {
733  wss.m_unknown_records++;
734  }
735  } catch (const std::exception& e) {
736  if (strErr.empty()) {
737  strErr = e.what();
738  }
739  return false;
740  } catch (...) {
741  if (strErr.empty()) {
742  strErr = "Caught unknown exception in ReadKeyValue";
743  }
744  return false;
745  }
746  return true;
747 }
748 
749 bool ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue, std::string& strType, std::string& strErr, const KeyFilterFn& filter_fn)
750 {
751  CWalletScanState dummy_wss;
752  LOCK(pwallet->cs_wallet);
753  return ReadKeyValue(pwallet, ssKey, ssValue, dummy_wss, strType, strErr, filter_fn);
754 }
755 
756 bool WalletBatch::IsKeyType(const std::string& strType)
757 {
758  return (strType == DBKeys::KEY ||
759  strType == DBKeys::MASTER_KEY || strType == DBKeys::CRYPTED_KEY);
760 }
761 
763 {
764  CWalletScanState wss;
765  bool fNoncriticalErrors = false;
766  bool rescan_required = false;
767  DBErrors result = DBErrors::LOAD_OK;
768 
769  LOCK(pwallet->cs_wallet);
770  try {
771  int nMinVersion = 0;
772  if (m_batch->Read(DBKeys::MINVERSION, nMinVersion)) {
773  if (nMinVersion > FEATURE_LATEST)
774  return DBErrors::TOO_NEW;
775  pwallet->LoadMinVersion(nMinVersion);
776  }
777 
778  // Load wallet flags, so they are known when processing other records.
779  // The FLAGS key is absent during wallet creation.
780  uint64_t flags;
781  if (m_batch->Read(DBKeys::FLAGS, flags)) {
782  if (!pwallet->LoadWalletFlags(flags)) {
783  pwallet->WalletLogPrintf("Error reading wallet database: Unknown non-tolerable wallet flags found\n");
784  return DBErrors::CORRUPT;
785  }
786  }
787 
788 #ifndef ENABLE_EXTERNAL_SIGNER
790  pwallet->WalletLogPrintf("Error: External signer wallet being loaded without external signer support compiled\n");
791  return DBErrors::TOO_NEW;
792  }
793 #endif
794 
795  // Get cursor
796  if (!m_batch->StartCursor())
797  {
798  pwallet->WalletLogPrintf("Error getting wallet database cursor\n");
799  return DBErrors::CORRUPT;
800  }
801 
802  while (true)
803  {
804  // Read next record
807  bool complete;
808  bool ret = m_batch->ReadAtCursor(ssKey, ssValue, complete);
809  if (complete) {
810  break;
811  }
812  else if (!ret)
813  {
814  m_batch->CloseCursor();
815  pwallet->WalletLogPrintf("Error reading next record from wallet database\n");
816  return DBErrors::CORRUPT;
817  }
818 
819  // Try to be tolerant of single corrupt records:
820  std::string strType, strErr;
821  if (!ReadKeyValue(pwallet, ssKey, ssValue, wss, strType, strErr))
822  {
823  // losing keys is considered a catastrophic error, anything else
824  // we assume the user can live with:
825  if (IsKeyType(strType) || strType == DBKeys::DEFAULTKEY) {
826  result = DBErrors::CORRUPT;
827  } else if (strType == DBKeys::FLAGS) {
828  // reading the wallet flags can only fail if unknown flags are present
829  result = DBErrors::TOO_NEW;
830  } else if (wss.tx_corrupt) {
831  pwallet->WalletLogPrintf("Error: Corrupt transaction found. This can be fixed by removing transactions from wallet and rescanning.\n");
832  // Set tx_corrupt back to false so that the error is only printed once (per corrupt tx)
833  wss.tx_corrupt = false;
834  result = DBErrors::CORRUPT;
835  } else {
836  // Leave other errors alone, if we try to fix them we might make things worse.
837  fNoncriticalErrors = true; // ... but do warn the user there is something wrong.
838  if (strType == DBKeys::TX)
839  // Rescan if there is a bad transaction record:
840  rescan_required = true;
841  }
842  }
843  if (!strErr.empty())
844  pwallet->WalletLogPrintf("%s\n", strErr);
845  }
846  } catch (...) {
847  result = DBErrors::CORRUPT;
848  }
849  m_batch->CloseCursor();
850 
851  // Set the active ScriptPubKeyMans
852  for (auto spk_man_pair : wss.m_active_external_spks) {
853  pwallet->LoadActiveScriptPubKeyMan(spk_man_pair.second, spk_man_pair.first, /* internal */ false);
854  }
855  for (auto spk_man_pair : wss.m_active_internal_spks) {
856  pwallet->LoadActiveScriptPubKeyMan(spk_man_pair.second, spk_man_pair.first, /* internal */ true);
857  }
858 
859  // Set the descriptor caches
860  for (auto desc_cache_pair : wss.m_descriptor_caches) {
861  auto spk_man = pwallet->GetScriptPubKeyMan(desc_cache_pair.first);
862  assert(spk_man);
863  ((DescriptorScriptPubKeyMan*)spk_man)->SetCache(desc_cache_pair.second);
864  }
865 
866  // Set the descriptor keys
867  for (auto desc_key_pair : wss.m_descriptor_keys) {
868  auto spk_man = pwallet->GetScriptPubKeyMan(desc_key_pair.first.first);
869  ((DescriptorScriptPubKeyMan*)spk_man)->AddKey(desc_key_pair.first.second, desc_key_pair.second);
870  }
871  for (auto desc_key_pair : wss.m_descriptor_crypt_keys) {
872  auto spk_man = pwallet->GetScriptPubKeyMan(desc_key_pair.first.first);
873  ((DescriptorScriptPubKeyMan*)spk_man)->AddCryptedKey(desc_key_pair.first.second, desc_key_pair.second.first, desc_key_pair.second.second);
874  }
875 
876  if (rescan_required && result == DBErrors::LOAD_OK) {
877  result = DBErrors::NEED_RESCAN;
878  } else if (fNoncriticalErrors && result == DBErrors::LOAD_OK) {
880  }
881 
882  // Any wallet corruption at all: skip any rewriting or
883  // upgrading, we don't want to make it worse.
884  if (result != DBErrors::LOAD_OK)
885  return result;
886 
887  // Last client version to open this wallet, was previously the file version number
888  int last_client = CLIENT_VERSION;
889  m_batch->Read(DBKeys::VERSION, last_client);
890 
891  int wallet_version = pwallet->GetVersion();
892  pwallet->WalletLogPrintf("Wallet File Version = %d\n", wallet_version > 0 ? wallet_version : last_client);
893 
894  pwallet->WalletLogPrintf("Keys: %u plaintext, %u encrypted, %u w/ metadata, %u total. Unknown wallet records: %u\n",
895  wss.nKeys, wss.nCKeys, wss.nKeyMeta, wss.nKeys + wss.nCKeys, wss.m_unknown_records);
896 
897  // nTimeFirstKey is only reliable if all keys have metadata
898  if (pwallet->IsLegacy() && (wss.nKeys + wss.nCKeys + wss.nWatchKeys) != wss.nKeyMeta) {
899  auto spk_man = pwallet->GetOrCreateLegacyScriptPubKeyMan();
900  if (spk_man) {
901  LOCK(spk_man->cs_KeyStore);
902  spk_man->UpdateTimeFirstKey(1);
903  }
904  }
905 
906  for (const uint256& hash : wss.vWalletUpgrade)
907  WriteTx(pwallet->mapWallet.at(hash));
908 
909  // Rewrite encrypted wallets of versions 0.4.0 and 0.5.0rc:
910  if (wss.fIsEncrypted && (last_client == 40000 || last_client == 50000))
911  return DBErrors::NEED_REWRITE;
912 
913  if (last_client < CLIENT_VERSION) // Update
915 
916  if (wss.fAnyUnordered)
917  result = pwallet->ReorderTransactions();
918 
919  // Upgrade all of the wallet keymetadata to have the hd master key id
920  // This operation is not atomic, but if it fails, updated entries are still backwards compatible with older software
921  try {
922  pwallet->UpgradeKeyMetadata();
923  } catch (...) {
924  result = DBErrors::CORRUPT;
925  }
926 
927  // Upgrade all of the descriptor caches to cache the last hardened xpub
928  // This operation is not atomic, but if it fails, only new entries are added so it is backwards compatible
929  try {
930  pwallet->UpgradeDescriptorCache();
931  } catch (...) {
932  result = DBErrors::CORRUPT;
933  }
934 
935  // Set the inactive chain
936  if (wss.m_hd_chains.size() > 0) {
937  LegacyScriptPubKeyMan* legacy_spkm = pwallet->GetLegacyScriptPubKeyMan();
938  if (!legacy_spkm) {
939  pwallet->WalletLogPrintf("Inactive HD Chains found but no Legacy ScriptPubKeyMan\n");
940  return DBErrors::CORRUPT;
941  }
942  for (const auto& chain_pair : wss.m_hd_chains) {
943  if (chain_pair.first != pwallet->GetLegacyScriptPubKeyMan()->GetHDChain().seed_id) {
944  pwallet->GetLegacyScriptPubKeyMan()->AddInactiveHDChain(chain_pair.second);
945  }
946  }
947  }
948 
949  return result;
950 }
951 
952 DBErrors WalletBatch::FindWalletTx(std::vector<uint256>& vTxHash, std::list<CWalletTx>& vWtx)
953 {
954  DBErrors result = DBErrors::LOAD_OK;
955 
956  try {
957  int nMinVersion = 0;
958  if (m_batch->Read(DBKeys::MINVERSION, nMinVersion)) {
959  if (nMinVersion > FEATURE_LATEST)
960  return DBErrors::TOO_NEW;
961  }
962 
963  // Get cursor
964  if (!m_batch->StartCursor())
965  {
966  LogPrintf("Error getting wallet database cursor\n");
967  return DBErrors::CORRUPT;
968  }
969 
970  while (true)
971  {
972  // Read next record
975  bool complete;
976  bool ret = m_batch->ReadAtCursor(ssKey, ssValue, complete);
977  if (complete) {
978  break;
979  } else if (!ret) {
980  m_batch->CloseCursor();
981  LogPrintf("Error reading next record from wallet database\n");
982  return DBErrors::CORRUPT;
983  }
984 
985  std::string strType;
986  ssKey >> strType;
987  if (strType == DBKeys::TX) {
988  uint256 hash;
989  ssKey >> hash;
990  vTxHash.push_back(hash);
991  vWtx.emplace_back(/*tx=*/nullptr, TxStateInactive{});
992  ssValue >> vWtx.back();
993  }
994  }
995  } catch (...) {
996  result = DBErrors::CORRUPT;
997  }
998  m_batch->CloseCursor();
999 
1000  return result;
1001 }
1002 
1003 DBErrors WalletBatch::ZapSelectTx(std::vector<uint256>& vTxHashIn, std::vector<uint256>& vTxHashOut)
1004 {
1005  // build list of wallet TXs and hashes
1006  std::vector<uint256> vTxHash;
1007  std::list<CWalletTx> vWtx;
1008  DBErrors err = FindWalletTx(vTxHash, vWtx);
1009  if (err != DBErrors::LOAD_OK) {
1010  return err;
1011  }
1012 
1013  std::sort(vTxHash.begin(), vTxHash.end());
1014  std::sort(vTxHashIn.begin(), vTxHashIn.end());
1015 
1016  // erase each matching wallet TX
1017  bool delerror = false;
1018  std::vector<uint256>::iterator it = vTxHashIn.begin();
1019  for (const uint256& hash : vTxHash) {
1020  while (it < vTxHashIn.end() && (*it) < hash) {
1021  it++;
1022  }
1023  if (it == vTxHashIn.end()) {
1024  break;
1025  }
1026  else if ((*it) == hash) {
1027  if(!EraseTx(hash)) {
1028  LogPrint(BCLog::WALLETDB, "Transaction was found for deletion but returned database error: %s\n", hash.GetHex());
1029  delerror = true;
1030  }
1031  vTxHashOut.push_back(hash);
1032  }
1033  }
1034 
1035  if (delerror) {
1036  return DBErrors::CORRUPT;
1037  }
1038  return DBErrors::LOAD_OK;
1039 }
1040 
1042 {
1043  static std::atomic<bool> fOneThread(false);
1044  if (fOneThread.exchange(true)) {
1045  return;
1046  }
1047 
1048  for (const std::shared_ptr<CWallet>& pwallet : GetWallets(context)) {
1049  WalletDatabase& dbh = pwallet->GetDatabase();
1050 
1051  unsigned int nUpdateCounter = dbh.nUpdateCounter;
1052 
1053  if (dbh.nLastSeen != nUpdateCounter) {
1054  dbh.nLastSeen = nUpdateCounter;
1055  dbh.nLastWalletUpdate = GetTime();
1056  }
1057 
1058  if (dbh.nLastFlushed != nUpdateCounter && GetTime() - dbh.nLastWalletUpdate >= 2) {
1059  if (dbh.PeriodicFlush()) {
1060  dbh.nLastFlushed = nUpdateCounter;
1061  }
1062  }
1063  }
1064 
1065  fOneThread = false;
1066 }
1067 
1068 bool WalletBatch::WriteDestData(const std::string &address, const std::string &key, const std::string &value)
1069 {
1070  return WriteIC(std::make_pair(DBKeys::DESTDATA, std::make_pair(address, key)), value);
1071 }
1072 
1073 bool WalletBatch::EraseDestData(const std::string &address, const std::string &key)
1074 {
1075  return EraseIC(std::make_pair(DBKeys::DESTDATA, std::make_pair(address, key)));
1076 }
1077 
1078 
1080 {
1081  return WriteIC(DBKeys::HDCHAIN, chain);
1082 }
1083 
1085 {
1086  return WriteIC(DBKeys::FLAGS, flags);
1087 }
1088 
1090 {
1091  return m_batch->TxnBegin();
1092 }
1093 
1095 {
1096  return m_batch->TxnCommit();
1097 }
1098 
1100 {
1101  return m_batch->TxnAbort();
1102 }
1103 
1104 std::unique_ptr<WalletDatabase> MakeDatabase(const fs::path& path, const DatabaseOptions& options, DatabaseStatus& status, bilingual_str& error)
1105 {
1106  bool exists;
1107  try {
1108  exists = fs::symlink_status(path).type() != fs::file_type::not_found;
1109  } catch (const fs::filesystem_error& e) {
1110  error = Untranslated(strprintf("Failed to access database path '%s': %s", fs::PathToString(path), fsbridge::get_filesystem_error_message(e)));
1112  return nullptr;
1113  }
1114 
1115  std::optional<DatabaseFormat> format;
1116  if (exists) {
1117  if (IsBDBFile(BDBDataFile(path))) {
1119  }
1120  if (IsSQLiteFile(SQLiteDataFile(path))) {
1121  if (format) {
1122  error = Untranslated(strprintf("Failed to load database path '%s'. Data is in ambiguous format.", fs::PathToString(path)));
1124  return nullptr;
1125  }
1127  }
1128  } else if (options.require_existing) {
1129  error = Untranslated(strprintf("Failed to load database path '%s'. Path does not exist.", fs::PathToString(path)));
1131  return nullptr;
1132  }
1133 
1134  if (!format && options.require_existing) {
1135  error = Untranslated(strprintf("Failed to load database path '%s'. Data is not in recognized format.", fs::PathToString(path)));
1137  return nullptr;
1138  }
1139 
1140  if (format && options.require_create) {
1141  error = Untranslated(strprintf("Failed to create database path '%s'. Database already exists.", fs::PathToString(path)));
1143  return nullptr;
1144  }
1145 
1146  // A db already exists so format is set, but options also specifies the format, so make sure they agree
1147  if (format && options.require_format && format != options.require_format) {
1148  error = Untranslated(strprintf("Failed to load database path '%s'. Data is not in required format.", fs::PathToString(path)));
1150  return nullptr;
1151  }
1152 
1153  // Format is not set when a db doesn't already exist, so use the format specified by the options if it is set.
1154  if (!format && options.require_format) format = options.require_format;
1155 
1156  // If the format is not specified or detected, choose the default format based on what is available. We prefer BDB over SQLite for now.
1157  if (!format) {
1158 #ifdef USE_SQLITE
1160 #endif
1161 #ifdef USE_BDB
1163 #endif
1164  }
1165 
1166  if (format == DatabaseFormat::SQLITE) {
1167 #ifdef USE_SQLITE
1168  return MakeSQLiteDatabase(path, options, status, error);
1169 #endif
1170  error = Untranslated(strprintf("Failed to open database path '%s'. Build does not support SQLite database format.", fs::PathToString(path)));
1172  return nullptr;
1173  }
1174 
1175 #ifdef USE_BDB
1176  return MakeBerkeleyDatabase(path, options, status, error);
1177 #endif
1178  error = Untranslated(strprintf("Failed to open database path '%s'. Build does not support Berkeley DB database format.", fs::PathToString(path)));
1180  return nullptr;
1181 }
1182 
1184 std::unique_ptr<WalletDatabase> CreateDummyWalletDatabase()
1185 {
1186  return std::make_unique<DummyDatabase>();
1187 }
1188 
1190 std::unique_ptr<WalletDatabase> CreateMockWalletDatabase()
1191 {
1192 #ifdef USE_SQLITE
1193  return std::make_unique<SQLiteDatabase>("", "", true);
1194 #elif USE_BDB
1195  return std::make_unique<BerkeleyDatabase>(std::make_shared<BerkeleyEnvironment>(), "");
1196 #endif
1197 }
1198 } // namespace wallet
wallet::WalletBatch::ZapSelectTx
DBErrors ZapSelectTx(std::vector< uint256 > &vHashIn, std::vector< uint256 > &vHashOut)
Definition: walletdb.cpp:1003
wallet::CWallet::LoadDestData
void LoadDestData(const CTxDestination &dest, const std::string &key, const std::string &value) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Adds a destination data tuple to the store, without saving it to disk.
Definition: wallet.cpp:2596
wallet::WalletDatabase
An instance of this class represents one database.
Definition: db.h:104
BIP32_EXTKEY_SIZE
const unsigned int BIP32_EXTKEY_SIZE
Definition: pubkey.h:19
wallet::DBKeys::NAME
const std::string NAME
Definition: walletdb.cpp:47
wallet::WalletBatch::WriteDescriptorCacheItems
bool WriteDescriptorCacheItems(const uint256 &desc_id, const DescriptorCache &cache)
Definition: walletdb.cpp:267
wallet::MakeBerkeleyDatabase
std::unique_ptr< BerkeleyDatabase > MakeBerkeleyDatabase(const fs::path &path, const DatabaseOptions &options, DatabaseStatus &status, bilingual_str &error)
Return object giving access to Berkeley database at specified path.
Definition: bdb.cpp:827
wallet::WalletBatch::EraseDestData
bool EraseDestData(const std::string &address, const std::string &key)
Erase destination data tuple from wallet database.
Definition: walletdb.cpp:1073
wallet::CWalletTx::GetHash
const uint256 & GetHash() const
Definition: transaction.h:298
wallet::LegacyScriptPubKeyMan::AddInactiveHDChain
void AddInactiveHDChain(const CHDChain &chain)
Definition: scriptpubkeyman.cpp:965
bip32.h
wallet::DBKeys::HDCHAIN
const std::string HDCHAIN
Definition: walletdb.cpp:41
wallet::DBKeys::ACENTRY
const std::string ACENTRY
Definition: walletdb.cpp:31
wallet::DBKeys::DESTDATA
const std::string DESTDATA
Definition: walletdb.cpp:39
fs::exists
static bool exists(const path &p)
Definition: fs.h:69
wallet::DBKeys::VERSION
const std::string VERSION
Definition: walletdb.cpp:54
OutputType
OutputType
Definition: outputtype.h:18
wallet::WalletBatch::WriteCryptedDescriptorKey
bool WriteCryptedDescriptorKey(const uint256 &desc_id, const CPubKey &pubkey, const std::vector< unsigned char > &secret)
Definition: walletdb.cpp:232
wallet::WalletBatch::WriteHDChain
bool WriteHDChain(const CHDChain &chain)
write the hdchain model (external chain child index counter)
Definition: walletdb.cpp:1079
wallet::CWallet::LoadToWallet
bool LoadToWallet(const uint256 &hash, const UpdateWalletTxFn &fill_wtx) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:1023
assert
assert(!tx.IsCoinBase())
wallet::DBKeys::MASTER_KEY
const std::string MASTER_KEY
Definition: walletdb.cpp:45
wallet::CWalletScanState::nKeyMeta
unsigned int nKeyMeta
Definition: walletdb.cpp:304
wallet::CKeyMetadata
Definition: walletdb.h:125
wallet::CWalletScanState::vWalletUpgrade
std::vector< uint256 > vWalletUpgrade
Definition: walletdb.cpp:308
wallet::WalletBatch::WriteMasterKey
bool WriteMasterKey(unsigned int nID, const CMasterKey &kMasterKey)
Definition: walletdb.cpp:146
tinyformat::format
void format(std::ostream &out, const char *fmt, const Args &... args)
Format list of arguments to the stream according to given format string.
Definition: tinyformat.h:1062
wallet::DBKeys::WALLETDESCRIPTORCKEY
const std::string WALLETDESCRIPTORCKEY
Definition: walletdb.cpp:58
wallet::DBKeys::CRYPTED_KEY
const std::string CRYPTED_KEY
Definition: walletdb.cpp:36
SER_DISK
@ SER_DISK
Definition: serialize.h:132
wallet::CWallet::GetVersion
int GetVersion() const
get the current wallet format (the oldest client version guaranteed to understand this wallet)
Definition: wallet.h:688
wallet::DBKeys::BESTBLOCK_NOMERKLE
const std::string BESTBLOCK_NOMERKLE
Definition: walletdb.cpp:34
wallet.h
wallet::DBKeys::SETTINGS
const std::string SETTINGS
Definition: walletdb.cpp:52
wallet::DescriptorScriptPubKeyMan
Definition: scriptpubkeyman.h:526
fs.h
wallet::CWallet::WalletLogPrintf
void WalletLogPrintf(std::string fmt, Params... parameters) const
Prepends the wallet name in logging output to ease debugging in multi-wallet use cases.
Definition: wallet.h:800
wallet::WalletBatch::WriteDescriptorLastHardenedCache
bool WriteDescriptorLastHardenedCache(const CExtPubKey &xpub, const uint256 &desc_id, uint32_t key_exp_index)
Definition: walletdb.cpp:260
wallet::BDBDataFile
fs::path BDBDataFile(const fs::path &wallet_path)
Definition: db.cpp:63
flags
int flags
Definition: bitcoin-tx.cpp:529
wallet::LegacyScriptPubKeyMan::LoadKeyPool
void LoadKeyPool(int64_t nIndex, const CKeyPool &keypool)
Load a keypool entry.
Definition: scriptpubkeyman.cpp:1140
key_io.h
wallet::DatabaseStatus
DatabaseStatus
Definition: db.h:213
wallet::WalletBatch::WriteMinVersion
bool WriteMinVersion(int nVersion)
Definition: walletdb.cpp:204
wallet::CKeyPool
A key from a CWallet's keypool.
Definition: scriptpubkeyman.h:103
sync.h
COutPoint::hash
uint256 hash
Definition: transaction.h:29
fsbridge::get_filesystem_error_message
std::string get_filesystem_error_message(const fs::filesystem_error &e)
Definition: fs.cpp:140
wallet::DBErrors::NONCRITICAL_ERROR
@ NONCRITICAL_ERROR
wallet::DBKeys::WALLETDESCRIPTOR
const std::string WALLETDESCRIPTOR
Definition: walletdb.cpp:55
DescriptorCache::GetCachedParentExtPubKeys
const ExtPubKeyMap GetCachedParentExtPubKeys() const
Retrieve all cached parent xpubs.
Definition: descriptor.cpp:1501
bilingual_str
Bilingual messages:
Definition: translation.h:16
wallet::WalletBatch::WriteLockedUTXO
bool WriteLockedUTXO(const COutPoint &output)
Definition: walletdb.cpp:289
wallet::DBKeys::KEY
const std::string KEY
Definition: walletdb.cpp:43
wallet::WalletBatch::WriteDescriptorKey
bool WriteDescriptorKey(const uint256 &desc_id, const CPubKey &pubkey, const CPrivKey &privkey)
Definition: walletdb.cpp:221
CPrivKey
std::vector< unsigned char, secure_allocator< unsigned char > > CPrivKey
CPrivKey is a serialized private key, with all parameters included (SIZE bytes)
Definition: key.h:23
wallet::WalletBatch::WritePool
bool WritePool(int64_t nPool, const CKeyPool &keypool)
Definition: walletdb.cpp:194
wallet::WalletBatch::WriteOrderPosNext
bool WriteOrderPosNext(int64_t nOrderPosNext)
Definition: walletdb.cpp:184
wallet::LegacyScriptPubKeyMan::LoadCryptedKey
bool LoadCryptedKey(const CPubKey &vchPubKey, const std::vector< unsigned char > &vchCryptedSecret, bool checksum_valid)
Adds an encrypted key to the store, without saving it to disk (used by LoadWallet)
Definition: scriptpubkeyman.cpp:817
wallet::DBErrors::NEED_REWRITE
@ NEED_REWRITE
GetTime
int64_t GetTime()
DEPRECATED Use either GetTimeSeconds (not mockable) or GetTime<T> (mockable)
Definition: time.cpp:26
wallet::WalletBatch::WriteBestBlock
bool WriteBestBlock(const CBlockLocator &locator)
Definition: walletdb.cpp:172
wallet::DBKeys::BESTBLOCK
const std::string BESTBLOCK
Definition: walletdb.cpp:35
wallet::DBKeys::MINVERSION
const std::string MINVERSION
Definition: walletdb.cpp:46
wallet::CHDChain::nVersion
int nVersion
Definition: walletdb.h:99
wallet::KeyFilterFn
std::function< bool(const std::string &)> KeyFilterFn
Callback for filtering key types to deserialize in ReadKeyValue.
Definition: walletdb.h:292
wallet::DBErrors
DBErrors
Error statuses for the wallet database.
Definition: walletdb.h:45
wallet
Definition: node.h:38
wallet::DBKeys::PURPOSE
const std::string PURPOSE
Definition: walletdb.cpp:51
wallet::DBKeys::CSCRIPT
const std::string CSCRIPT
Definition: walletdb.cpp:37
wallet::WalletBatch::WriteDescriptor
bool WriteDescriptor(const uint256 &desc_id, const WalletDescriptor &descriptor)
Definition: walletdb.cpp:241
wallet::DBKeys::WALLETDESCRIPTORKEY
const std::string WALLETDESCRIPTORKEY
Definition: walletdb.cpp:59
wallet::IsSQLiteFile
bool IsSQLiteFile(const fs::path &path)
Definition: db.cpp:107
wallet::CHDChain::VERSION_HD_BASE
static const int VERSION_HD_BASE
Definition: walletdb.h:96
fs::PathToString
static std::string PathToString(const path &path)
Convert path object to a byte string.
Definition: fs.h:112
wallet::DatabaseOptions::require_existing
bool require_existing
Definition: db.h:205
bdb.h
CExtPubKey::Decode
void Decode(const unsigned char code[BIP32_EXTKEY_SIZE])
Definition: pubkey.cpp:346
wallet::WalletBatch::TxnAbort
bool TxnAbort()
Abort current transaction.
Definition: walletdb.cpp:1099
wallet::CWalletScanState::fIsEncrypted
bool fIsEncrypted
Definition: walletdb.cpp:306
wallet::WalletDatabase::nLastWalletUpdate
int64_t nLastWalletUpdate
Definition: db.h:152
wallet::WalletBatch::FindWalletTx
DBErrors FindWalletTx(std::vector< uint256 > &vTxHash, std::list< CWalletTx > &vWtx)
Definition: walletdb.cpp:952
wallet::CWallet::LoadWalletFlags
bool LoadWalletFlags(uint64_t flags)
Loads the flags into the wallet.
Definition: wallet.cpp:1469
wallet::CWalletTx
A transaction with a bunch of additional info that only the owner cares about.
Definition: transaction.h:137
sqlite.h
wallet::WalletBatch::EraseName
bool EraseName(const std::string &strAddress)
Definition: walletdb.cpp:73
wallet::CWallet::LockCoin
bool LockCoin(const COutPoint &output, WalletBatch *batch=nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2394
wallet::CWallet::nMasterKeyMaxID
unsigned int nMasterKeyMaxID
Definition: wallet.h:366
wallet::WalletBatch::WriteActiveScriptPubKeyMan
bool WriteActiveScriptPubKeyMan(uint8_t type, const uint256 &id, bool internal)
Definition: walletdb.cpp:209
wallet::LegacyScriptPubKeyMan::LoadWatchOnly
bool LoadWatchOnly(const CScript &dest)
Adds a watch-only address to the store, without saving it to disk (used by LoadWallet)
Definition: scriptpubkeyman.cpp:895
wallet::CWalletScanState::m_active_external_spks
std::map< OutputType, uint256 > m_active_external_spks
Definition: walletdb.cpp:309
wallet::WalletBatch::ReadPool
bool ReadPool(int64_t nPool, CKeyPool &keypool)
Definition: walletdb.cpp:189
wallet::DBErrors::CORRUPT
@ CORRUPT
wallet::WalletBatch::EraseWatchOnly
bool EraseWatchOnly(const CScript &script)
Definition: walletdb.cpp:164
wallet::GetWallets
std::vector< std::shared_ptr< CWallet > > GetWallets(WalletContext &context)
Definition: wallet.cpp:148
wallet::CreateDummyWalletDatabase
std::unique_ptr< WalletDatabase > CreateDummyWalletDatabase()
Return object for accessing dummy database with no read/write capabilities.
Definition: walletdb.cpp:1184
wallet::DBKeys::WATCHMETA
const std::string WATCHMETA
Definition: walletdb.cpp:60
wallet::MakeDatabase
std::unique_ptr< WalletDatabase > MakeDatabase(const fs::path &path, const DatabaseOptions &options, DatabaseStatus &status, bilingual_str &error)
Definition: walletdb.cpp:1104
wallet::WALLET_FLAG_EXTERNAL_SIGNER
@ WALLET_FLAG_EXTERNAL_SIGNER
Indicates that the wallet needs an external signer.
Definition: walletutil.h:69
CPubKey::begin
const unsigned char * begin() const
Definition: pubkey.h:114
wallet::DatabaseOptions::require_create
bool require_create
Definition: db.h:206
wallet::CHDChain::VERSION_HD_CHAIN_SPLIT
static const int VERSION_HD_CHAIN_SPLIT
Definition: walletdb.h:97
wallet::WalletBatch::WriteCryptedKey
bool WriteCryptedKey(const CPubKey &vchPubKey, const std::vector< unsigned char > &vchCryptedSecret, const CKeyMetadata &keyMeta)
Definition: walletdb.cpp:120
wallet::WalletBatch::TxnCommit
bool TxnCommit()
Commit current transaction.
Definition: walletdb.cpp:1094
Hash
uint256 Hash(const T &in1)
Compute the 256-bit hash of an object.
Definition: hash.h:75
wallet::FEATURE_LATEST
@ FEATURE_LATEST
Definition: walletutil.h:30
BCLog::WALLETDB
@ WALLETDB
Definition: logging.h:45
wallet::CWalletScanState::tx_corrupt
bool tx_corrupt
Definition: walletdb.cpp:315
Untranslated
bilingual_str Untranslated(std::string original)
Mark a bilingual_str as untranslated.
Definition: translation.h:46
wallet::CWalletScanState::CWalletScanState
CWalletScanState()
Definition: walletdb.cpp:317
wallet::CWallet::mapMasterKeys
MasterKeyMap mapMasterKeys
Definition: wallet.h:365
wallet::LegacyScriptPubKeyMan
Definition: scriptpubkeyman.h:264
wallet::CWallet::IsLegacy
bool IsLegacy() const
Determine if we are a legacy wallet.
Definition: wallet.cpp:3387
wallet::CWallet
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
Definition: wallet.h:232
fs::path
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
Definition: fs.h:29
wallet::WalletBatch::m_batch
std::unique_ptr< DatabaseBatch > m_batch
Definition: walletdb.h:284
wallet::CWallet::LoadDescriptorScriptPubKeyMan
void LoadDescriptorScriptPubKeyMan(uint256 id, WalletDescriptor &desc)
Instantiate a descriptor ScriptPubKeyMan from the WalletDescriptor and load it.
Definition: wallet.cpp:3265
wallet::WalletBatch::ReadBestBlock
bool ReadBestBlock(CBlockLocator &locator)
Definition: walletdb.cpp:178
wallet::WalletBatch::WriteWalletFlags
bool WriteWalletFlags(const uint64_t flags)
Definition: walletdb.cpp:1084
wallet::DBErrors::LOAD_OK
@ LOAD_OK
CPubKey::end
const unsigned char * end() const
Definition: pubkey.h:115
wallet::CKeyMetadata::VERSION_WITH_HDDATA
static const int VERSION_WITH_HDDATA
Definition: walletdb.h:129
wallet::WalletBatch::WriteCScript
bool WriteCScript(const uint160 &hash, const CScript &redeemScript)
Definition: walletdb.cpp:151
wallet::CWalletScanState::nWatchKeys
unsigned int nWatchKeys
Definition: walletdb.cpp:303
wallet::DBKeys::POOL
const std::string POOL
Definition: walletdb.cpp:50
wallet::WalletBatch::WriteKeyMetadata
bool WriteKeyMetadata(const CKeyMetadata &meta, const CPubKey &pubkey, const bool overwrite)
Definition: walletdb.cpp:100
wallet::DatabaseOptions::require_format
std::optional< DatabaseFormat > require_format
Definition: db.h:207
wallet::CWallet::ReorderTransactions
DBErrors ReorderTransactions()
Definition: wallet.cpp:761
wallet::WalletBatch::LoadWallet
DBErrors LoadWallet(CWallet *pwallet)
Definition: walletdb.cpp:762
wallet::CWalletScanState::m_hd_chains
std::map< uint160, CHDChain > m_hd_chains
Definition: walletdb.cpp:314
wallet::WalletBatch::ErasePool
bool ErasePool(int64_t nPool)
Definition: walletdb.cpp:199
time.h
wallet::WalletBatch::WriteWatchOnly
bool WriteWatchOnly(const CScript &script, const CKeyMetadata &keymeta)
Definition: walletdb.cpp:156
LogPrintf
#define LogPrintf(...)
Definition: logging.h:188
context
WalletContext context
Definition: notifications.cpp:37
wallet::CWallet::LoadActiveScriptPubKeyMan
void LoadActiveScriptPubKeyMan(uint256 id, OutputType type, bool internal)
Loads an active ScriptPubKeyMan for the specified type and internal.
Definition: wallet.cpp:3350
wallet::CMasterKey
Private key encryption is done based on a CMasterKey, which holds a salt and random encryption key.
Definition: crypter.h:34
id
static NodeId id
Definition: denialofservice_tests.cpp:37
wallet::WalletBatch::WriteDescriptorDerivedCache
bool WriteDescriptorDerivedCache(const CExtPubKey &xpub, const uint256 &desc_id, uint32_t key_exp_index, uint32_t der_index)
Definition: walletdb.cpp:246
wallet::CWalletScanState::m_descriptor_keys
std::map< std::pair< uint256, CKeyID >, CKey > m_descriptor_keys
Definition: walletdb.cpp:312
CPubKey::size
unsigned int size() const
Simple read-only vector-like interface to the pubkey data.
Definition: pubkey.h:112
wallet::CHDChain
Definition: walletdb.h:89
uint256
256-bit opaque blob.
Definition: uint256.h:126
wallet::DBKeys::FLAGS
const std::string FLAGS
Definition: walletdb.cpp:40
wallet::CWallet::GetOrCreateLegacyScriptPubKeyMan
LegacyScriptPubKeyMan * GetOrCreateLegacyScriptPubKeyMan()
Definition: wallet.cpp:3227
wallet::CHDChain::seed_id
CKeyID seed_id
seed hash160
Definition: walletdb.h:94
wallet::WalletBatch::WriteTx
bool WriteTx(const CWalletTx &wtx)
Definition: walletdb.cpp:90
LogPrint
#define LogPrint(category,...)
Definition: logging.h:192
CExtPubKey::Encode
void Encode(unsigned char code[BIP32_EXTKEY_SIZE]) const
Definition: pubkey.cpp:337
CScript
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:405
wallet::CWalletScanState::m_active_internal_spks
std::map< OutputType, uint256 > m_active_internal_spks
Definition: walletdb.cpp:310
wallet::DBKeys::KEYMETA
const std::string KEYMETA
Definition: walletdb.cpp:42
wallet::CreateMockWalletDatabase
std::unique_ptr< WalletDatabase > CreateMockWalletDatabase()
Return object for accessing temporary in-memory database.
Definition: walletdb.cpp:1190
wallet::CWallet::UpgradeDescriptorCache
void UpgradeDescriptorCache() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Upgrade DescriptorCaches.
Definition: wallet.cpp:422
wallet::DatabaseStatus::FAILED_BAD_FORMAT
@ FAILED_BAD_FORMAT
wallet::CWalletScanState::m_descriptor_crypt_keys
std::map< std::pair< uint256, CKeyID >, std::pair< CPubKey, std::vector< unsigned char > > > m_descriptor_crypt_keys
Definition: walletdb.cpp:313
wallet::DatabaseStatus::FAILED_NOT_FOUND
@ FAILED_NOT_FOUND
DescriptorCache::GetCachedLastHardenedExtPubKeys
const ExtPubKeyMap GetCachedLastHardenedExtPubKeys() const
Retrieve all cached last hardened xpubs.
Definition: descriptor.cpp:1511
DescriptorCache
Cache for single descriptor's derived extended pubkeys.
Definition: descriptor.h:19
wallet::CWallet::cs_wallet
RecursiveMutex cs_wallet
Main wallet lock.
Definition: wallet.h:352
wallet::LegacyScriptPubKeyMan::GetHDChain
const CHDChain & GetHDChain() const
Definition: scriptpubkeyman.h:435
wallet::WalletBatch::EraseTx
bool EraseTx(uint256 hash)
Definition: walletdb.cpp:95
wallet::WalletDatabase::nUpdateCounter
std::atomic< unsigned int > nUpdateCounter
Definition: db.h:149
wallet::WalletBatch::TxnBegin
bool TxnBegin()
Begin a new transaction.
Definition: walletdb.cpp:1089
wallet::TxStateInactive
State of transaction not confirmed or conflicting with a known block and not in the mempool.
Definition: transaction.h:48
system.h
strprintf
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1164
wallet::WalletBatch::WriteDestData
bool WriteDestData(const std::string &address, const std::string &key, const std::string &value)
Write destination data key,value tuple to database.
Definition: walletdb.cpp:1068
wallet::LegacyScriptPubKeyMan::LoadKey
bool LoadKey(const CKey &key, const CPubKey &pubkey)
Adds a key to the store, without saving it to disk (used by LoadWallet)
Definition: scriptpubkeyman.cpp:713
uint160
160-bit opaque blob.
Definition: uint256.h:115
CPubKey
An encapsulated public key.
Definition: pubkey.h:33
wallet::CWallet::UpgradeKeyMetadata
void UpgradeKeyMetadata() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Upgrade stored CKeyMetadata objects to store key origin info as KeyOriginInfo.
Definition: wallet.cpp:407
base_blob::IsNull
bool IsNull() const
Definition: uint256.h:33
wallet::CWallet::GetScriptPubKeyMan
ScriptPubKeyMan * GetScriptPubKeyMan(const OutputType &type, bool internal) const
Get the ScriptPubKeyMan for the given OutputType and internal/external chain.
Definition: wallet.cpp:3169
wallet::DatabaseFormat::BERKELEY
@ BERKELEY
wallet::DBKeys::ACTIVEINTERNALSPK
const std::string ACTIVEINTERNALSPK
Definition: walletdb.cpp:33
CKey
An encapsulated private key.
Definition: key.h:26
wallet::DatabaseStatus::FAILED_BAD_PATH
@ FAILED_BAD_PATH
wallet::CWallet::GetLegacyScriptPubKeyMan
LegacyScriptPubKeyMan * GetLegacyScriptPubKeyMan() const
Get the LegacyScriptPubKeyMan which is used for all types, internal, and external.
Definition: wallet.cpp:3215
translation.h
wallet::DBErrors::NEED_RESCAN
@ NEED_RESCAN
wallet::CHDChain::nExternalChainCounter
uint32_t nExternalChainCounter
Definition: walletdb.h:92
wallet::CWalletScanState::nCKeys
unsigned int nCKeys
Definition: walletdb.cpp:302
EXCLUSIVE_LOCKS_REQUIRED
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:49
CBlockLocator::vHave
std::vector< uint256 > vHave
Definition: block.h:116
COutPoint::n
uint32_t n
Definition: transaction.h:30
wallet::WalletBatch::IsKeyType
static bool IsKeyType(const std::string &strType)
Definition: walletdb.cpp:756
wallet::WalletBatch::WriteName
bool WriteName(const std::string &strAddress, const std::string &strName)
Definition: walletdb.cpp:68
wallet::WalletBatch::WriteDescriptorParentCache
bool WriteDescriptorParentCache(const CExtPubKey &xpub, const uint256 &desc_id, uint32_t key_exp_index)
Definition: walletdb.cpp:253
LOCK
#define LOCK(cs)
Definition: sync.h:226
wallet::WalletBatch::EraseLockedUTXO
bool EraseLockedUTXO(const COutPoint &output)
Definition: walletdb.cpp:294
wallet::WalletBatch::ErasePurpose
bool ErasePurpose(const std::string &strAddress)
Definition: walletdb.cpp:85
wallet::DatabaseFormat::SQLITE
@ SQLITE
wallet::LegacyScriptPubKeyMan::LoadCScript
bool LoadCScript(const CScript &redeemScript)
Adds a CScript to the store.
Definition: scriptpubkeyman.cpp:765
wallet::LegacyScriptPubKeyMan::LoadScriptMetadata
void LoadScriptMetadata(const CScriptID &script_id, const CKeyMetadata &metadata)
Definition: scriptpubkeyman.cpp:787
wallet::DBKeys::WALLETDESCRIPTORCACHE
const std::string WALLETDESCRIPTORCACHE
Definition: walletdb.cpp:56
wallet::DBKeys::WALLETDESCRIPTORLHCACHE
const std::string WALLETDESCRIPTORLHCACHE
Definition: walletdb.cpp:57
CLIENT_VERSION
static const int CLIENT_VERSION
bitcoind-res.rc includes this file, but it cannot cope with real c++ code.
Definition: clientversion.h:33
DecodeDestination
CTxDestination DecodeDestination(const std::string &str, std::string &error_msg, std::vector< int > *error_locations)
Definition: key_io.cpp:281
wallet::WalletDatabase::PeriodicFlush
virtual bool PeriodicFlush()=0
wallet::MakeSQLiteDatabase
std::unique_ptr< SQLiteDatabase > MakeSQLiteDatabase(const fs::path &path, const DatabaseOptions &options, DatabaseStatus &status, bilingual_str &error)
Definition: sqlite.cpp:560
wallet::WalletBatch::WriteIC
bool WriteIC(const K &key, const T &value, bool fOverwrite=true)
Definition: walletdb.h:184
wallet::DBKeys::ACTIVEEXTERNALSPK
const std::string ACTIVEEXTERNALSPK
Definition: walletdb.cpp:32
wallet::WalletBatch::EraseIC
bool EraseIC(const K &key)
Definition: walletdb.h:197
wallet::CWalletScanState::m_unknown_records
unsigned int m_unknown_records
Definition: walletdb.cpp:305
wallet::ReadKeyValue
static bool ReadKeyValue(CWallet *pwallet, CDataStream &ssKey, CDataStream &ssValue, CWalletScanState &wss, std::string &strType, std::string &strErr, const KeyFilterFn &filter_fn=nullptr) EXCLUSIVE_LOCKS_REQUIRED(pwallet -> cs_wallet)
Definition: walletdb.cpp:322
wallet::IsBDBFile
bool IsBDBFile(const fs::path &path)
Definition: db.cpp:82
serialize.h
wallet::CWalletScanState::nKeys
unsigned int nKeys
Definition: walletdb.cpp:301
CDataStream
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:184
wallet::CWalletScanState::fAnyUnordered
bool fAnyUnordered
Definition: walletdb.cpp:307
wallet::WalletBatch::EraseActiveScriptPubKeyMan
bool EraseActiveScriptPubKeyMan(uint8_t type, bool internal)
Definition: walletdb.cpp:215
wallet::WalletDescriptor
Descriptor with some wallet metadata.
Definition: walletutil.h:76
walletdb.h
COutPoint
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:26
wallet::DBKeys::LOCKED_UTXO
const std::string LOCKED_UTXO
Definition: walletdb.cpp:44
wallet::CWalletScanState
Definition: walletdb.cpp:299
CDataStream::empty
bool empty() const
Definition: streams.h:237
wallet::DBKeys::WATCHS
const std::string WATCHS
Definition: walletdb.cpp:61
CKey::Load
bool Load(const CPrivKey &privkey, const CPubKey &vchPubKey, bool fSkipCheck)
Load private key and check that public key matches.
Definition: key.cpp:303
wallet::WalletContext
WalletContext struct containing references to state shared between CWallet instances,...
Definition: context.h:35
error
bool error(const char *fmt, const Args &... args)
Definition: system.h:49
wallet::DatabaseStatus::FAILED_ALREADY_EXISTS
@ FAILED_ALREADY_EXISTS
wallet::WalletBatch::WriteKey
bool WriteKey(const CPubKey &vchPubKey, const CPrivKey &vchPrivKey, const CKeyMetadata &keyMeta)
Definition: walletdb.cpp:105
CBlockLocator
Describes a place in the block chain to another node such that if the other node doesn't have the sam...
Definition: block.h:114
ParseHDKeypath
bool ParseHDKeypath(const std::string &keypath_str, std::vector< uint32_t > &keypath)
Parse an HD keypaths like "m/7/0'/2000".
Definition: bip32.cpp:12
wallet::DBKeys::TX
const std::string TX
Definition: walletdb.cpp:53
wallet::MaybeCompactWalletDB
void MaybeCompactWalletDB(WalletContext &context)
Compacts BDB state so that wallet.dat is self-contained (if there are changes)
Definition: walletdb.cpp:1041
DescriptorCache::GetCachedDerivedExtPubKeys
const std::unordered_map< uint32_t, ExtPubKeyMap > GetCachedDerivedExtPubKeys() const
Retrieve all cached derived xpubs.
Definition: descriptor.cpp:1506
wallet::DBKeys::OLD_KEY
const std::string OLD_KEY
Definition: walletdb.cpp:48
CScriptID
A reference to a CScript: the Hash160 of its serialization (see script.h)
Definition: standard.h:25
wallet::DatabaseOptions
Definition: db.h:204
wallet::CHDChain::nInternalChainCounter
uint32_t nInternalChainCounter
Definition: walletdb.h:93
wallet::LegacyScriptPubKeyMan::LoadHDChain
void LoadHDChain(const CHDChain &chain)
Load a HD chain model (used by LoadWallet)
Definition: scriptpubkeyman.cpp:944
wallet::WalletDatabase::nLastSeen
unsigned int nLastSeen
Definition: db.h:150
wallet::DBErrors::TOO_NEW
@ TOO_NEW
wallet::CWallet::LoadMinVersion
bool LoadMinVersion(int nVersion) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.h:481
wallet::DBKeys::DEFAULTKEY
const std::string DEFAULTKEY
Definition: walletdb.cpp:38
wallet::LegacyScriptPubKeyMan::LoadKeyMetadata
void LoadKeyMetadata(const CKeyID &keyID, const CKeyMetadata &metadata)
Load metadata (used by LoadWallet)
Definition: scriptpubkeyman.cpp:780
CExtPubKey
Definition: pubkey.h:291
wallet::CWallet::IsWalletFlagSet
bool IsWalletFlagSet(uint64_t flag) const override
check if a certain wallet flag is set
Definition: wallet.cpp:1464
CDataStream::eof
bool eof() const
Definition: streams.h:270
wallet::DBKeys::ORDERPOSNEXT
const std::string ORDERPOSNEXT
Definition: walletdb.cpp:49
wallet::WalletDatabase::nLastFlushed
unsigned int nLastFlushed
Definition: db.h:151
wallet::WalletBatch::WritePurpose
bool WritePurpose(const std::string &strAddress, const std::string &purpose)
Definition: walletdb.cpp:80
wallet::SQLiteDataFile
fs::path SQLiteDataFile(const fs::path &path)
Definition: db.cpp:77
wallet::CWalletScanState::m_descriptor_caches
std::map< uint256, DescriptorCache > m_descriptor_caches
Definition: walletdb.cpp:311