PRCYCoin  2.0.0.7rc1
P2P Digital Currency
walletdb.cpp
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2014 The Bitcoin developers
3 // Copyright (c) 2014-2015 The Dash developers
4 // Copyright (c) 2015-2018 The PIVX developers
5 // Copyright (c) 2018-2020 The DAPS Project developers
6 // Distributed under the MIT/X11 software license, see the accompanying
7 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
8 
9 #include "wallet/walletdb.h"
10 
11 #include "base58.h"
12 #include "protocol.h"
13 #include "serialize.h"
14 #include "sync.h"
15 #include "util.h"
16 #include "utiltime.h"
17 #include "wallet/wallet.h"
18 
19 #include <atomic>
20 #include <boost/scoped_ptr.hpp>
21 #include <boost/thread.hpp>
22 #include <fstream>
23 
24 
25 static uint64_t nAccountingEntryNumber = 0;
26 
27 static std::atomic<unsigned int> nWalletDBUpdateCounter;
28 
29 //
30 // CWalletDB
31 //
32 
33 bool CWalletDB::AppendStealthAccountList(const std::string& accountName) {
34  std::string currentList;
35  if (!ReadStealthAccountList(currentList)) {
36  currentList = accountName;
37  } else {
38  currentList = currentList + "," + accountName;
39  nWalletDBUpdateCounter++;
40  Erase(std::string("accountlist"));
41  }
42  nWalletDBUpdateCounter++;
43  return Write(std::string("accountlist"), currentList);
44 }
45 
46 bool CWalletDB::ReadStealthAccountList(std::string& accountList) {
47  return Read(std::string("accountlist"), accountList);
48 }
49 
50 bool CWalletDB::WriteName(const std::string& strAddress, const std::string& strName)
51 {
52  nWalletDBUpdateCounter++;
53  return Write(std::make_pair(std::string("name"), strAddress), strName);
54 }
55 
56 bool CWalletDB::EraseName(const std::string& strAddress)
57 {
58  // This should only be used for sending addresses, never for receiving addresses,
59  // receiving addresses must always have an address book entry if they're not change return.
60  nWalletDBUpdateCounter++;
61  return Erase(std::make_pair(std::string("name"), strAddress));
62 }
63 
64 bool CWalletDB::WritePurpose(const std::string& strAddress, const std::string& strPurpose)
65 {
66  nWalletDBUpdateCounter++;
67  return Write(std::make_pair(std::string("purpose"), strAddress), strPurpose);
68 }
69 
70 bool CWalletDB::ErasePurpose(const std::string& strPurpose)
71 {
72  nWalletDBUpdateCounter++;
73  return Erase(std::make_pair(std::string("purpose"), strPurpose));
74 }
75 
76 bool CWalletDB::WriteTx(uint256 hash, const CWalletTx& wtx)
77 {
78  nWalletDBUpdateCounter++;
79  return Write(std::make_pair(std::string("tx"), hash), wtx);
80 }
81 
83 {
84  nWalletDBUpdateCounter++;
85  return Erase(std::make_pair(std::string("tx"), hash));
86 }
87 
88 bool CWalletDB::WriteKey(const CPubKey& vchPubKey, const CPrivKey& vchPrivKey, const CKeyMetadata& keyMeta)
89 {
90  nWalletDBUpdateCounter++;
91 
92  if (!Write(std::make_pair(std::string("keymeta"), vchPubKey),
93  keyMeta, false))
94  return false;
95 
96  // hash pubkey/privkey to accelerate wallet load
97  std::vector<unsigned char> vchKey;
98  vchKey.reserve(vchPubKey.size() + vchPrivKey.size());
99  vchKey.insert(vchKey.end(), vchPubKey.begin(), vchPubKey.end());
100  vchKey.insert(vchKey.end(), vchPrivKey.begin(), vchPrivKey.end());
101 
102  return Write(std::make_pair(std::string("key"), vchPubKey), std::make_pair(vchPrivKey, Hash(vchKey.begin(), vchKey.end())), false);
103 }
104 
105 bool CWalletDB::WriteCryptedKey(const CPubKey& vchPubKey,
106  const std::vector<unsigned char>& vchCryptedSecret,
107  const CKeyMetadata& keyMeta)
108 {
109  const bool fEraseUnencryptedKey = true;
110  nWalletDBUpdateCounter++;
111 
112  if (!Write(std::make_pair(std::string("keymeta"), vchPubKey),
113  keyMeta))
114  return false;
115 
116  if (!Write(std::make_pair(std::string("ckey"), vchPubKey), vchCryptedSecret, false))
117  return false;
118  if (fEraseUnencryptedKey) {
119  Erase(std::make_pair(std::string("key"), vchPubKey));
120  Erase(std::make_pair(std::string("wkey"), vchPubKey));
121  }
122  return true;
123 }
124 
125 bool CWalletDB::WriteMasterKey(unsigned int nID, const CMasterKey& kMasterKey)
126 {
127  nWalletDBUpdateCounter++;
128  return Write(std::make_pair(std::string("mkey"), nID), kMasterKey, true);
129 }
130 
131 bool CWalletDB::WriteCScript(const uint160& hash, const CScript& redeemScript)
132 {
133  nWalletDBUpdateCounter++;
134  return Write(std::make_pair(std::string("cscript"), hash), *(const CScriptBase*)(&redeemScript), false);
135 }
136 
138 {
139  nWalletDBUpdateCounter++;
140  return Write(std::make_pair(std::string("watchs"), *(const CScriptBase*)(&dest)), '1');
141 }
142 
144 {
145  nWalletDBUpdateCounter++;
146  return Erase(std::make_pair(std::string("watchs"), *(const CScriptBase*)(&dest)));
147 }
148 
150 {
151  nWalletDBUpdateCounter++;
152  return Write(std::make_pair(std::string("multisig"), *(const CScriptBase*)(&dest)), '1');
153 }
154 
156 {
157  nWalletDBUpdateCounter++;
158  return Erase(std::make_pair(std::string("multisig"), *(const CScriptBase*)(&dest)));
159 }
160 
161 bool CWalletDB::WriteReserveAmount(const double& amount)
162 {
163  nWalletDBUpdateCounter++;
164  return Write(std::string("reservebalance"), amount);
165 }
166 
167 bool CWalletDB::ReadReserveAmount(double& amount)
168 {
169  return Read(std::string("reservebalance"), amount);
170 }
171 
173 {
174  nWalletDBUpdateCounter++;
175  Write(std::string("bestblock"), CBlockLocator()); // Write empty block locator so versions that require a merkle branch automatically rescan
176  return Write(std::string("bestblock_nomerkle"), locator);
177 }
178 
180 {
181  if (Read(std::string("bestblock"), locator) && !locator.vHave.empty()) return true;
182  return Read(std::string("bestblock_nomerkle"), locator);
183 }
184 
185 bool CWalletDB::WriteOrderPosNext(int64_t nOrderPosNext)
186 {
187  nWalletDBUpdateCounter++;
188  return Write(std::string("orderposnext"), nOrderPosNext);
189 }
190 
191 // presstab HyperStake
192 bool CWalletDB::WriteStakeSplitThreshold(uint64_t nStakeSplitThreshold)
193 {
194  nWalletDBUpdateCounter++;
195  return Write(std::string("stakeSplitThreshold"), nStakeSplitThreshold);
196 }
197 
198 //presstab HyperStake
199 bool CWalletDB::WriteMultiSend(std::vector<std::pair<std::string, int> > vMultiSend)
200 {
201  nWalletDBUpdateCounter++;
202  bool ret = true;
203  for (unsigned int i = 0; i < vMultiSend.size(); i++) {
204  std::pair<std::string, int> pMultiSend;
205  pMultiSend = vMultiSend[i];
206  if (!Write(std::make_pair(std::string("multisend"), i), pMultiSend, true))
207  ret = false;
208  }
209  return ret;
210 }
211 //presstab HyperStake
212 bool CWalletDB::EraseMultiSend(std::vector<std::pair<std::string, int> > vMultiSend)
213 {
214  nWalletDBUpdateCounter++;
215  bool ret = true;
216  for (unsigned int i = 0; i < vMultiSend.size(); i++) {
217  std::pair<std::string, int> pMultiSend;
218  pMultiSend = vMultiSend[i];
219  if (!Erase(std::make_pair(std::string("multisend"), i)))
220  ret = false;
221  }
222  return ret;
223 }
224 //presstab HyperStake
225 bool CWalletDB::WriteMSettings(bool fMultiSendStake, bool fMultiSendMasternode, int nLastMultiSendHeight)
226 {
227  nWalletDBUpdateCounter++;
228  std::pair<bool, bool> enabledMS(fMultiSendStake, fMultiSendMasternode);
229  std::pair<std::pair<bool, bool>, int> pSettings(enabledMS, nLastMultiSendHeight);
230 
231  return Write(std::string("msettingsv2"), pSettings, true);
232 }
233 //presstab HyperStake
234 bool CWalletDB::WriteMSDisabledAddresses(std::vector<std::string> vDisabledAddresses)
235 {
236  nWalletDBUpdateCounter++;
237  bool ret = true;
238  for (unsigned int i = 0; i < vDisabledAddresses.size(); i++) {
239  if (!Write(std::make_pair(std::string("mdisabled"), i), vDisabledAddresses[i]))
240  ret = false;
241  }
242  return ret;
243 }
244 //presstab HyperStake
245 bool CWalletDB::EraseMSDisabledAddresses(std::vector<std::string> vDisabledAddresses)
246 {
247  nWalletDBUpdateCounter++;
248  bool ret = true;
249  for (unsigned int i = 0; i < vDisabledAddresses.size(); i++) {
250  if (!Erase(std::make_pair(std::string("mdisabled"), i)))
251  ret = false;
252  }
253  return ret;
254 }
255 bool CWalletDB::WriteAutoCombineSettings(bool fEnable, CAmount nCombineThreshold)
256 {
257  nWalletDBUpdateCounter++;
258  std::pair<bool, CAmount> pSettings;
259  pSettings.first = fEnable;
260  pSettings.second = nCombineThreshold;
261  return Write(std::string("autocombinesettings"), pSettings, true);
262 }
263 
264 bool CWalletDB::WriteDefaultKey(const CPubKey& vchPubKey)
265 {
266  nWalletDBUpdateCounter++;
267  return Write(std::string("defaultkey"), vchPubKey);
268 }
269 
270 bool CWalletDB::ReadPool(int64_t nPool, CKeyPool& keypool)
271 {
272  return Read(std::make_pair(std::string("pool"), nPool), keypool);
273 }
274 
275 bool CWalletDB::WritePool(int64_t nPool, const CKeyPool& keypool)
276 {
277  nWalletDBUpdateCounter++;
278  return Write(std::make_pair(std::string("pool"), nPool), keypool);
279 }
280 
281 bool CWalletDB::ErasePool(int64_t nPool)
282 {
283  nWalletDBUpdateCounter++;
284  return Erase(std::make_pair(std::string("pool"), nPool));
285 }
286 
287 bool CWalletDB::WriteMinVersion(int nVersion)
288 {
289  return Write(std::string("minversion"), nVersion);
290 }
291 
292 bool CWalletDB::WriteStakingStatus(bool status) {
293  return Write(std::string("stakingstatus"), status);
294 }
295 
297  bool status;
298  if (!Read(std::string("stakingstatus"), status)) {
299  return false;
300  }
301  return status;
302 }
303 
305 {
306  return Write(std::string("scannedblockheight"), height);
307 }
309 {
310  return Read(std::string("scannedblockheight"), height);
311 }
312 
313 bool CWalletDB::Write2FA(bool status)
314 {
315  return Write(std::string("2fa"), status);
316 }
318 {
319  bool status;
320  if (!Read(std::string("2fa"), status)) {
321  return false;
322  }
323  return status;
324 }
325 
326 bool CWalletDB::Write2FASecret(std::string secret)
327 {
328  return Write(std::string("2fasecret"), secret);
329 }
331 {
332  std::string secret;
333  if (!Read(std::string("2fasecret"), secret))
334  return "";
335  return secret;
336 }
337 
339 {
340  return Write(std::string("2faperiod"), period);
341 }
343 {
344  int period;
345  if (!Read(std::string("2faperiod"), period))
346  return 0;
347  return period;
348 }
349 
350 bool CWalletDB::Write2FALastTime(uint64_t lastTime)
351 {
352  return Write(std::string("2falasttime"), lastTime);
353 }
355 {
356  uint64_t lastTime;
357  if (!Read(std::string("2falasttime"), lastTime))
358  return 0;
359  return lastTime;
360 }
361 
362 bool CWalletDB::ReadAccount(const std::string& strAccount, CAccount& account)
363 {
364  account.SetNull();
365  return Read(std::make_pair(std::string("acc"), strAccount), account);
366 }
367 
369 {
370  return Write(std::string("autoconsolidatetime"), settingTime);
371 }
372 
374 {
375  uint32_t settingTime = 0;
376  if (!Read(std::string("autoconsolidatetime"), settingTime)) {
377  return 0;
378  }
379  return settingTime;
380 }
381 
382 
383 bool CWalletDB::WriteAccount(const std::string& strAccount, const CAccount& account)
384 {
385  return Write(std::make_pair(std::string("acc"), strAccount), account);
386 }
387 
388 bool CWalletDB::ReadStealthAccount(const std::string& strAccount, CStealthAccount& account)
389 {
390  if (strAccount == "masteraccount") {
391  return ReadAccount("spendaccount", account.spendAccount) && ReadAccount("viewaccount", account.viewAccount);
392  }
393  return ReadAccount(strAccount + "spend", account.spendAccount) && ReadAccount(strAccount + "view", account.viewAccount);
394 }
395 
396 bool CWalletDB::WriteStealthAccount(const std::string& strAccount, const CStealthAccount& account) {
397  if (strAccount == "masteraccount") {
398  return WriteAccount("spendaccount", account.spendAccount) && WriteAccount("viewaccount", account.viewAccount);
399  }
400  return WriteAccount(strAccount + "spend", account.spendAccount) && WriteAccount(strAccount + "view", account.viewAccount);
401 }
402 
403 bool CWalletDB::WriteAccountingEntry(const uint64_t nAccEntryNum, const CAccountingEntry& acentry)
404 {
405  return Write(std::make_pair(std::string("acentry"), std::make_pair(acentry.strAccount, nAccEntryNum)), acentry);
406 }
407 
409 {
410  return WriteAccountingEntry(++nAccountingEntryNumber, acentry);
411 }
412 
413 CAmount CWalletDB::GetAccountCreditDebit(const std::string& strAccount)
414 {
415  std::list<CAccountingEntry> entries;
416  ListAccountCreditDebit(strAccount, entries);
417 
418  CAmount nCreditDebit = 0;
419  for (const CAccountingEntry& entry : entries)
420  nCreditDebit += entry.nCreditDebit;
421 
422  return nCreditDebit;
423 }
424 
425 void CWalletDB::ListAccountCreditDebit(const std::string& strAccount, std::list<CAccountingEntry>& entries)
426 {
427  bool fAllAccounts = (strAccount == "*");
428 
429  Dbc* pcursor = GetCursor();
430  if (!pcursor)
431  throw std::runtime_error("CWalletDB::ListAccountCreditDebit() : cannot create DB cursor");
432  unsigned int fFlags = DB_SET_RANGE;
433  while (true) {
434  // Read next record
435  CDataStream ssKey(SER_DISK, CLIENT_VERSION);
436  if (fFlags == DB_SET_RANGE)
437  ssKey << std::make_pair(std::string("acentry"), std::make_pair((fAllAccounts ? std::string("") : strAccount), uint64_t(0)));
438  CDataStream ssValue(SER_DISK, CLIENT_VERSION);
439  int ret = ReadAtCursor(pcursor, ssKey, ssValue, fFlags);
440  fFlags = DB_NEXT;
441  if (ret == DB_NOTFOUND)
442  break;
443  else if (ret != 0) {
444  pcursor->close();
445  throw std::runtime_error("CWalletDB::ListAccountCreditDebit() : error scanning DB");
446  }
447 
448  // Unserialize
449  std::string strType;
450  ssKey >> strType;
451  if (strType != "acentry")
452  break;
453  CAccountingEntry acentry;
454  ssKey >> acentry.strAccount;
455  if (!fAllAccounts && acentry.strAccount != strAccount)
456  break;
457 
458  ssValue >> acentry;
459  ssKey >> acentry.nEntryNo;
460  entries.push_back(acentry);
461  }
462 
463  pcursor->close();
464 }
465 
467 {
468  LOCK(pwallet->cs_wallet);
469  // Old wallets didn't have any defined order for transactions
470  // Probably a bad idea to change the output of this
471 
472  // First: get all CWalletTx and CAccountingEntry into a sorted-by-time multimap.
473  typedef std::pair<CWalletTx*, CAccountingEntry*> TxPair;
474  typedef std::multimap<int64_t, TxPair> TxItems;
475  TxItems txByTime;
476 
477  for (std::map<uint256, CWalletTx>::iterator it = pwallet->mapWallet.begin(); it != pwallet->mapWallet.end(); ++it) {
478  CWalletTx* wtx = &((*it).second);
479  txByTime.insert(std::make_pair(wtx->nTimeReceived, TxPair(wtx, (CAccountingEntry*)0)));
480  }
481  std::list<CAccountingEntry> acentries;
482  ListAccountCreditDebit("", acentries);
483  for (CAccountingEntry& entry : acentries) {
484  txByTime.insert(std::make_pair(entry.nTime, TxPair((CWalletTx*)0, &entry)));
485  }
486 
487  int64_t& nOrderPosNext = pwallet->nOrderPosNext;
488  nOrderPosNext = 0;
489  std::vector<int64_t> nOrderPosOffsets;
490  for (TxItems::iterator it = txByTime.begin(); it != txByTime.end(); ++it) {
491  CWalletTx* const pwtx = (*it).second.first;
492  CAccountingEntry* const pacentry = (*it).second.second;
493  int64_t& nOrderPos = (pwtx != 0) ? pwtx->nOrderPos : pacentry->nOrderPos;
494 
495  if (nOrderPos == -1) {
496  nOrderPos = nOrderPosNext++;
497  nOrderPosOffsets.push_back(nOrderPos);
498 
499  if (pwtx) {
500  if (!WriteTx(pwtx->GetHash(), *pwtx))
501  return DB_LOAD_FAIL;
502  } else if (!WriteAccountingEntry(pacentry->nEntryNo, *pacentry))
503  return DB_LOAD_FAIL;
504  } else {
505  int64_t nOrderPosOff = 0;
506  for (const int64_t& nOffsetStart : nOrderPosOffsets) {
507  if (nOrderPos >= nOffsetStart)
508  ++nOrderPosOff;
509  }
510  nOrderPos += nOrderPosOff;
511  nOrderPosNext = std::max(nOrderPosNext, nOrderPos + 1);
512 
513  if (!nOrderPosOff)
514  continue;
515 
516  // Since we're changing the order, write it back
517  if (pwtx) {
518  if (!WriteTx(pwtx->GetHash(), *pwtx))
519  return DB_LOAD_FAIL;
520  } else if (!WriteAccountingEntry(pacentry->nEntryNo, *pacentry))
521  return DB_LOAD_FAIL;
522  }
523  }
524  WriteOrderPosNext(nOrderPosNext);
525 
526  return DB_LOAD_OK;
527 }
528 
530 {
531 public:
532  unsigned int nKeys;
533  unsigned int nCKeys;
534  unsigned int nKeyMeta;
538  std::vector<uint256> vWalletUpgrade;
539 
541  {
542  nKeys = nCKeys = nKeyMeta = 0;
543  fIsEncrypted = false;
544  fAnyUnordered = false;
545  nFileVersion = 0;
546  }
547 };
548 
549 bool ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue, CWalletScanState& wss, std::string& strType, std::string& strErr)
550 {
551  try {
552  // Unserialize
553  // Taking advantage of the fact that pair serialization
554  // is just the two items serialized one after the other
555  ssKey >> strType;
556  if (strType == "name") {
557  std::string strAddress;
558  ssKey >> strAddress;
559  ssValue >> pwallet->mapAddressBook[CBitcoinAddress(strAddress).Get()].name;
560  } else if (strType == "purpose") {
561  std::string strAddress;
562  ssKey >> strAddress;
563  ssValue >> pwallet->mapAddressBook[CBitcoinAddress(strAddress).Get()].purpose;
564  } else if (strType == "tx") {
565  uint256 hash;
566  ssKey >> hash;
567  CWalletTx wtx;
568  ssValue >> wtx;
569  if (wtx.GetHash() != hash)
570  return false;
571 
572  if (wtx.nOrderPos == -1)
573  wss.fAnyUnordered = true;
574 
575  pwallet->AddToWallet(wtx, true, nullptr);
576  } else if (strType == "acentry") {
577  std::string strAccount;
578  ssKey >> strAccount;
579  uint64_t nNumber;
580  ssKey >> nNumber;
581  if (nNumber > nAccountingEntryNumber)
582  nAccountingEntryNumber = nNumber;
583 
584  if (!wss.fAnyUnordered) {
585  CAccountingEntry acentry;
586  ssValue >> acentry;
587  if (acentry.nOrderPos == -1)
588  wss.fAnyUnordered = true;
589  }
590  } else if (strType == "watchs") {
591  CScript script;
592  ssKey >> *(CScriptBase*)(&script);
593  char fYes;
594  ssValue >> fYes;
595  if (fYes == '1')
596  pwallet->LoadWatchOnly(script);
597 
598  // Watch-only addresses have no birthday information for now,
599  // so set the wallet birthday to the beginning of time.
600  pwallet->nTimeFirstKey = 1;
601  } else if (strType == "key" || strType == "wkey") {
602  CPubKey vchPubKey;
603  ssKey >> vchPubKey;
604  if (!vchPubKey.IsValid()) {
605  strErr = "Error reading wallet database: CPubKey corrupt";
606  return false;
607  }
608  CKey key;
609  CPrivKey pkey;
610  uint256 hash;
611 
612  if (strType == "key") {
613  wss.nKeys++;
614  ssValue >> pkey;
615  } else {
616  CWalletKey wkey;
617  ssValue >> wkey;
618  pkey = wkey.vchPrivKey;
619  }
620 
621  // Old wallets store keys as "key" [pubkey] => [privkey]
622  // ... which was slow for wallets with lots of keys, because the public key is re-derived from the private key
623  // using EC operations as a checksum.
624  // Newer wallets store keys as "key"[pubkey] => [privkey][hash(pubkey,privkey)], which is much faster while
625  // remaining backwards-compatible.
626  try {
627  ssValue >> hash;
628  } catch (...) {
629  }
630 
631  bool fSkipCheck = false;
632 
633  if (!hash.IsNull()) {
634  // hash pubkey/privkey to accelerate wallet load
635  std::vector<unsigned char> vchKey;
636  vchKey.reserve(vchPubKey.size() + pkey.size());
637  vchKey.insert(vchKey.end(), vchPubKey.begin(), vchPubKey.end());
638  vchKey.insert(vchKey.end(), pkey.begin(), pkey.end());
639 
640  if (Hash(vchKey.begin(), vchKey.end()) != hash) {
641  strErr = "Error reading wallet database: CPubKey/CPrivKey corrupt";
642  return false;
643  }
644 
645  fSkipCheck = true;
646  }
647 
648  if (!key.Load(pkey, vchPubKey, fSkipCheck)) {
649  strErr = "Error reading wallet database: CPrivKey corrupt";
650  return false;
651  }
652  if (!pwallet->LoadKey(key, vchPubKey)) {
653  strErr = "Error reading wallet database: LoadKey failed";
654  return false;
655  }
656  } else if (strType == "mkey") {
657  unsigned int nID;
658  ssKey >> nID;
659  CMasterKey kMasterKey;
660  ssValue >> kMasterKey;
661  if (pwallet->mapMasterKeys.count(nID) != 0) {
662  strErr = strprintf("Error reading wallet database: duplicate CMasterKey id %u", nID);
663  return false;
664  }
665  pwallet->mapMasterKeys[nID] = kMasterKey;
666  if (pwallet->nMasterKeyMaxID < nID)
667  pwallet->nMasterKeyMaxID = nID;
668  } else if (strType == "ckey") {
669  std::vector<unsigned char> vchPubKey;
670  ssKey >> vchPubKey;
671  std::vector<unsigned char> vchPrivKey;
672  ssValue >> vchPrivKey;
673  wss.nCKeys++;
674 
675  if (!pwallet->LoadCryptedKey(vchPubKey, vchPrivKey)) {
676  strErr = "Error reading wallet database: LoadCryptedKey failed";
677  return false;
678  }
679  wss.fIsEncrypted = true;
680  } else if (strType == "keymeta") {
681  CPubKey vchPubKey;
682  ssKey >> vchPubKey;
683  CKeyMetadata keyMeta;
684  ssValue >> keyMeta;
685  wss.nKeyMeta++;
686 
687  pwallet->LoadKeyMetadata(vchPubKey, keyMeta);
688 
689  // find earliest key creation time, as wallet birthday
690  if (!pwallet->nTimeFirstKey ||
691  (keyMeta.nCreateTime < pwallet->nTimeFirstKey))
692  pwallet->nTimeFirstKey = keyMeta.nCreateTime;
693  } else if (strType == "defaultkey") {
694  ssValue >> pwallet->vchDefaultKey;
695  } else if (strType == "pool") {
696  int64_t nIndex;
697  ssKey >> nIndex;
698  CKeyPool keypool;
699  ssValue >> keypool;
700  pwallet->setKeyPool.insert(nIndex);
701 
702  // If no metadata exists yet, create a default with the pool key's
703  // creation time. Note that this may be overwritten by actually
704  // stored metadata for that key later, which is fine.
705  CKeyID keyid = keypool.vchPubKey.GetID();
706  if (pwallet->mapKeyMetadata.count(keyid) == 0)
707  pwallet->mapKeyMetadata[keyid] = CKeyMetadata(keypool.nTime);
708  } else if (strType == "version") {
709  ssValue >> wss.nFileVersion;
710  if (wss.nFileVersion == 10300)
711  wss.nFileVersion = 300;
712  } else if (strType == "cscript") {
713  uint160 hash;
714  ssKey >> hash;
715  CScript script;
716  ssValue >> *(CScriptBase*)(&script);
717  if (!pwallet->LoadCScript(script)) {
718  strErr = "Error reading wallet database: LoadCScript failed";
719  return false;
720  }
721  } else if (strType == "orderposnext") {
722  ssValue >> pwallet->nOrderPosNext;
723  } else if (strType == "stakeSplitThreshold") //presstab HyperStake
724  {
725  ssValue >> pwallet->nStakeSplitThreshold;
726  } else if (strType == "multisend") //presstab HyperStake
727  {
728  unsigned int i;
729  ssKey >> i;
730  std::pair<std::string, int> pMultiSend;
731  ssValue >> pMultiSend;
732  if (CBitcoinAddress(pMultiSend.first).IsValid()) {
733  pwallet->vMultiSend.push_back(pMultiSend);
734  }
735  } else if (strType == "msettingsv2") //presstab HyperStake
736  {
737  std::pair<std::pair<bool, bool>, int> pSettings;
738  ssValue >> pSettings;
739  pwallet->fMultiSendStake = pSettings.first.first;
740  pwallet->fMultiSendMasternodeReward = pSettings.first.second;
741  pwallet->nLastMultiSendHeight = pSettings.second;
742  } else if (strType == "mdisabled") //presstab HyperStake
743  {
744  std::string strDisabledAddress;
745  ssValue >> strDisabledAddress;
746  pwallet->vDisabledAddresses.push_back(strDisabledAddress);
747  } else if (strType == "autocombinesettings") {
748  std::pair<bool, CAmount> pSettings;
749  ssValue >> pSettings;
750  pwallet->fCombineDust = true;//pSettings.first;
751  pwallet->nAutoCombineThreshold = 150;//pSettings.second;
752  } else if (strType == "destdata") {
753  std::string strAddress, strKey, strValue;
754  ssKey >> strAddress;
755  ssKey >> strKey;
756  ssValue >> strValue;
757  if (!pwallet->LoadDestData(CBitcoinAddress(strAddress).Get(), strKey, strValue)) {
758  strErr = "Error reading wallet database: LoadDestData failed";
759  return false;
760  }
761  } else if (strType == "hdchain") {
762  CHDChain chain;
763  ssValue >> chain;
764  if (!pwallet->SetHDChain(chain, true))
765  {
766  strErr = "Error reading wallet database: SetHDChain failed";
767  return false;
768  }
769  }
770  else if (strType == "chdchain")
771  {
772  CHDChain chain;
773  ssValue >> chain;
774  if (!pwallet->SetCryptedHDChain(chain, true))
775  {
776  strErr = "Error reading wallet database: SetHDCryptedChain failed";
777  return false;
778  }
779  }
780  else if (strType == "hdpubkey")
781  {
782  CPubKey vchPubKey;
783  ssKey >> vchPubKey;
784 
785  CHDPubKey hdPubKey;
786  ssValue >> hdPubKey;
787 
788  if(vchPubKey != hdPubKey.extPubKey.pubkey)
789  {
790  strErr = "Error reading wallet database: CHDPubKey corrupt";
791  return false;
792  }
793  if (!pwallet->LoadHDPubKey(hdPubKey))
794  {
795  strErr = "Error reading wallet database: LoadHDPubKey failed";
796  return false;
797  }
798  }
799  } catch (...) {
800  return false;
801  }
802  return true;
803 }
804 
805 static bool IsKeyType(std::string strType)
806 {
807  return (strType == "key" || strType == "wkey" ||
808  strType == "mkey" || strType == "ckey");
809 }
810 
812 {
813  pwallet->vchDefaultKey = CPubKey();
814  CWalletScanState wss;
815  bool fNoncriticalErrors = false;
816  DBErrors result = DB_LOAD_OK;
817 
818  LOCK(pwallet->cs_wallet);
819  try {
820  int nMinVersion = 0;
821  if (Read((std::string) "minversion", nMinVersion)) {
822  if (nMinVersion > CLIENT_VERSION)
823  return DB_TOO_NEW;
824  pwallet->LoadMinVersion(nMinVersion);
825  }
826 
827  // Get cursor
828  Dbc* pcursor = GetCursor();
829  if (!pcursor) {
830  LogPrintf("Error getting wallet database cursor\n");
831  return DB_CORRUPT;
832  }
833 
834  while (true) {
835  // Read next record
836  CDataStream ssKey(SER_DISK, CLIENT_VERSION);
837  CDataStream ssValue(SER_DISK, CLIENT_VERSION);
838  int ret = ReadAtCursor(pcursor, ssKey, ssValue);
839  if (ret == DB_NOTFOUND)
840  break;
841  else if (ret != 0) {
842  LogPrintf("Error reading next record from wallet database\n");
843  return DB_CORRUPT;
844  }
845 
846  // Try to be tolerant of single corrupt records:
847  std::string strType, strErr;
848  if (!ReadKeyValue(pwallet, ssKey, ssValue, wss, strType, strErr)) {
849  // losing keys is considered a catastrophic error, anything else
850  // we assume the user can live with:
851  if (IsKeyType(strType))
852  result = DB_CORRUPT;
853  else {
854  // Leave other errors alone, if we try to fix them we might make things worse.
855  fNoncriticalErrors = true; // ... but do warn the user there is something wrong.
856  if (strType == "tx")
857  // Rescan if there is a bad transaction record:
858  SoftSetBoolArg("-rescan", true);
859  }
860  }
861  if (!strErr.empty())
862  LogPrintf("%s\n", strErr);
863  }
864  pcursor->close();
865  } catch (const boost::thread_interrupted&) {
866  throw;
867  } catch (...) {
868  result = DB_CORRUPT;
869  }
870 
871  if (fNoncriticalErrors && result == DB_LOAD_OK)
872  result = DB_NONCRITICAL_ERROR;
873 
874  // Any wallet corruption at all: skip any rewriting or
875  // upgrading, we don't want to make it worse.
876  if (result != DB_LOAD_OK)
877  return result;
878 
879  LogPrintf("nFileVersion = %d\n", wss.nFileVersion);
880 
881  LogPrintf("Keys: %u plaintext, %u encrypted, %u w/ metadata, %u total\n",
882  wss.nKeys, wss.nCKeys, wss.nKeyMeta, wss.nKeys + wss.nCKeys);
883 
884  // nTimeFirstKey is only reliable if all keys have metadata
885  if ((wss.nKeys + wss.nCKeys) != wss.nKeyMeta)
886  pwallet->nTimeFirstKey = 1; // 0 would be considered 'no value'
887 
888  for (uint256 hash : wss.vWalletUpgrade)
889  WriteTx(hash, pwallet->mapWallet[hash]);
890 
891  // Rewrite encrypted wallets of versions 0.4.0 and 0.5.0rc:
892  if (wss.fIsEncrypted && (wss.nFileVersion == 40000 || wss.nFileVersion == 50000))
893  return DB_NEED_REWRITE;
894 
895  if (wss.nFileVersion < CLIENT_VERSION) // Update
896  WriteVersion(CLIENT_VERSION);
897 
898  pwallet->laccentries.clear();
899  ListAccountCreditDebit("*", pwallet->laccentries);
900  for(CAccountingEntry& entry : pwallet->laccentries) {
901  pwallet->wtxOrdered.insert(std::make_pair(entry.nOrderPos, CWallet::TxPair((CWalletTx*)0, &entry)));
902  }
903 
904  return result;
905 }
906 
907 DBErrors CWalletDB::FindWalletTx(CWallet* pwallet, std::vector<uint256>& vTxHash, std::vector<CWalletTx>& vWtx)
908 {
909  pwallet->vchDefaultKey = CPubKey();
910  bool fNoncriticalErrors = false;
911  DBErrors result = DB_LOAD_OK;
912 
913  try {
914  LOCK(pwallet->cs_wallet);
915  int nMinVersion = 0;
916  if (Read((std::string) "minversion", nMinVersion)) {
917  if (nMinVersion > CLIENT_VERSION)
918  return DB_TOO_NEW;
919  pwallet->LoadMinVersion(nMinVersion);
920  }
921 
922  // Get cursor
923  Dbc* pcursor = GetCursor();
924  if (!pcursor) {
925  LogPrintf("Error getting wallet database cursor\n");
926  return DB_CORRUPT;
927  }
928 
929  while (true) {
930  // Read next record
931  CDataStream ssKey(SER_DISK, CLIENT_VERSION);
932  CDataStream ssValue(SER_DISK, CLIENT_VERSION);
933  int ret = ReadAtCursor(pcursor, ssKey, ssValue);
934  if (ret == DB_NOTFOUND)
935  break;
936  else if (ret != 0) {
937  LogPrintf("Error reading next record from wallet database\n");
938  return DB_CORRUPT;
939  }
940 
941  std::string strType;
942  ssKey >> strType;
943  if (strType == "tx") {
944  uint256 hash;
945  ssKey >> hash;
946 
947  CWalletTx wtx;
948  ssValue >> wtx;
949 
950  vTxHash.push_back(hash);
951  vWtx.push_back(wtx);
952  }
953  }
954  pcursor->close();
955  } catch (const boost::thread_interrupted&) {
956  throw;
957  } catch (...) {
958  result = DB_CORRUPT;
959  }
960 
961  if (fNoncriticalErrors && result == DB_LOAD_OK)
962  result = DB_NONCRITICAL_ERROR;
963 
964  return result;
965 }
966 
967 DBErrors CWalletDB::ZapWalletTx(CWallet* pwallet, std::vector<CWalletTx>& vWtx)
968 {
969  // build list of wallet TXs
970  std::vector<uint256> vTxHash;
971  DBErrors err = FindWalletTx(pwallet, vTxHash, vWtx);
972  if (err != DB_LOAD_OK)
973  return err;
974 
975  // erase each wallet TX
976  for (uint256& hash : vTxHash) {
977  if (!EraseTx(hash))
978  return DB_CORRUPT;
979  }
980 
981  return DB_LOAD_OK;
982 }
983 
984 void ThreadFlushWalletDB(const std::string& strFile)
985 {
986  // Make this thread recognisable as the wallet flushing thread
987  util::ThreadRename("prcycoin-wallet");
988 
989  static bool fOneThread;
990  if (fOneThread)
991  return;
992  fOneThread = true;
993  if (!GetBoolArg("-flushwallet", true))
994  return;
995 
996  unsigned int nLastSeen = CWalletDB::GetUpdateCounter();
997  unsigned int nLastFlushed = CWalletDB::GetUpdateCounter();
998  int64_t nLastWalletUpdate = GetTime();
999  while (true) {
1000  MilliSleep(500);
1001 
1002  if (nLastSeen != CWalletDB::GetUpdateCounter()) {
1003  nLastSeen = CWalletDB::GetUpdateCounter();
1004  nLastWalletUpdate = GetTime();
1005  }
1006 
1007  if (nLastFlushed != CWalletDB::GetUpdateCounter() && GetTime() - nLastWalletUpdate >= 2) {
1008  TRY_LOCK(bitdb.cs_db, lockDb);
1009  if (lockDb) {
1010  // Don't do this if any databases are in use
1011  int nRefCount = 0;
1012  std::map<std::string, int>::iterator mi = bitdb.mapFileUseCount.begin();
1013  while (mi != bitdb.mapFileUseCount.end()) {
1014  nRefCount += (*mi).second;
1015  mi++;
1016  }
1017 
1018  if (nRefCount == 0) {
1019  boost::this_thread::interruption_point();
1020  std::map<std::string, int>::iterator mi = bitdb.mapFileUseCount.find(strFile);
1021  if (mi != bitdb.mapFileUseCount.end()) {
1022  LogPrint(BCLog::DB, "Flushing wallet.dat\n");
1023  nLastFlushed = CWalletDB::GetUpdateCounter();
1024  int64_t nStart = GetTimeMillis();
1025 
1026  // Flush wallet.dat so it's self contained
1027  bitdb.CloseDb(strFile);
1028  bitdb.CheckpointLSN(strFile);
1029 
1030  bitdb.mapFileUseCount.erase(mi++);
1031  LogPrint(BCLog::DB, "Flushed wallet.dat %dms\n", GetTimeMillis() - nStart);
1032  }
1033  }
1034  }
1035  }
1036  }
1037 }
1038 
1039 void NotifyBacked(const CWallet& wallet, bool fSuccess, std::string strMessage)
1040 {
1041  LogPrintf("%s\n", strMessage);
1042  wallet.NotifyWalletBacked(fSuccess, strMessage);
1043 }
1044 
1045 bool BackupWallet(const CWallet& wallet, const fs::path& strDest, bool fEnableCustom)
1046 {
1047  fs::path pathCustom;
1048  fs::path pathWithFile;
1049  if (!wallet.fFileBacked) {
1050  return false;
1051  } else if(fEnableCustom) {
1052  pathWithFile = GetArg("-backuppath", "");
1053  if(!pathWithFile.empty()) {
1054  if(!pathWithFile.has_extension()) {
1055  pathCustom = pathWithFile;
1056  pathWithFile /= wallet.GetUniqueWalletBackupName();
1057  } else {
1058  pathCustom = pathWithFile.parent_path();
1059  }
1060  try {
1061  fs::create_directories(pathCustom);
1062  } catch(const fs::filesystem_error& e) {
1063  NotifyBacked(wallet, false, strprintf("%s\n", e.what()));
1064  pathCustom = "";
1065  }
1066  }
1067  }
1068 
1069  while (true) {
1070  {
1071  LOCK(bitdb.cs_db);
1072  if (!bitdb.mapFileUseCount.count(wallet.strWalletFile) || bitdb.mapFileUseCount[wallet.strWalletFile] == 0) {
1073  // Flush log data to the dat file
1074  bitdb.CloseDb(wallet.strWalletFile);
1076  bitdb.mapFileUseCount.erase(wallet.strWalletFile);
1077 
1078  // Copy wallet.dat
1079  fs::path pathDest(strDest);
1080  fs::path pathSrc = GetDataDir() / wallet.strWalletFile;
1081  if (is_directory(pathDest)) {
1082  if(!exists(pathDest)) create_directory(pathDest);
1083  pathDest /= wallet.strWalletFile;
1084  }
1085  bool defaultPath = AttemptBackupWallet(wallet, pathSrc.string(), pathDest.string());
1086 
1087  if(defaultPath && !pathCustom.empty()) {
1088  int nThreshold = GetArg("-custombackupthreshold", DEFAULT_CUSTOMBACKUPTHRESHOLD);
1089  if (nThreshold > 0) {
1090 
1091  typedef std::multimap<std::time_t, fs::path> folder_set_t;
1092  folder_set_t folderSet;
1093  fs::directory_iterator end_iter;
1094 
1095  pathCustom.make_preferred();
1096  // Build map of backup files for current(!) wallet sorted by last write time
1097 
1098  fs::path currentFile;
1099  for (fs::directory_iterator dir_iter(pathCustom); dir_iter != end_iter; ++dir_iter) {
1100  // Only check regular files
1101  if (fs::is_regular_file(dir_iter->status())) {
1102  currentFile = dir_iter->path().filename();
1103  // Only add the backups for the current wallet, e.g. wallet.dat.*
1104  if (dir_iter->path().stem().string() == wallet.strWalletFile) {
1105  folderSet.insert(folder_set_t::value_type(fs::last_write_time(dir_iter->path()), *dir_iter));
1106  }
1107  }
1108  }
1109 
1110  int counter = 0; //TODO: add seconds to avoid naming conflicts
1111  for (auto entry : folderSet) {
1112  counter++;
1113  if(entry.second == pathWithFile) {
1114  pathWithFile += "(1)";
1115  }
1116  }
1117 
1118  if (counter >= nThreshold) {
1119  std::time_t oldestBackup = 0;
1120  for(auto entry : folderSet) {
1121  if(oldestBackup == 0 || entry.first < oldestBackup) {
1122  oldestBackup = entry.first;
1123  }
1124  }
1125 
1126  try {
1127  auto entry = folderSet.find(oldestBackup);
1128  if (entry != folderSet.end()) {
1129  fs::remove(entry->second);
1130  LogPrintf("Old backup deleted: %s\n", (*entry).second);
1131  }
1132  } catch (fs::filesystem_error& error) {
1133  std::string strMessage = strprintf("Failed to delete backup %s\n", error.what());
1134  NotifyBacked(wallet, false, strMessage);
1135  }
1136  }
1137  }
1138  AttemptBackupWallet(wallet, pathSrc.string(), pathWithFile.string());
1139  }
1140 
1141  return defaultPath;
1142  }
1143  }
1144  MilliSleep(100);
1145  }
1146  return false;
1147 }
1148 
1149 bool AttemptBackupWallet(const CWallet& wallet, const fs::path& pathSrc, const fs::path& pathDest)
1150 {
1151  bool retStatus;
1152  std::string strMessage;
1153  try {
1154  if (fs::equivalent(pathSrc, pathDest)) {
1155  LogPrintf("cannot backup to wallet source file %s\n", pathDest.string());
1156  return false;
1157  }
1158 #if BOOST_VERSION >= 105800 /* BOOST_LIB_VERSION 1_58 */
1159  fs::copy_file(pathSrc, pathDest, fs::copy_option::overwrite_if_exists);
1160 #else
1161  std::ifstream src(pathSrc, std::ios::binary | std::ios::in);
1162  std::ofstream dst(pathDest, std::ios::binary | std::ios::out | std::ios::trunc);
1163  dst << src.rdbuf();
1164  dst.flush();
1165  src.close();
1166  dst.close();
1167 #endif
1168  strMessage = strprintf("copied wallet.dat to %s\n", pathDest.string());
1169  LogPrintf("%s : %s\n", __func__, strMessage);
1170  retStatus = true;
1171  } catch (const fs::filesystem_error& e) {
1172  retStatus = false;
1173  strMessage = strprintf("%s\n", e.what());
1174  LogPrintf("%s : %s\n", __func__, strMessage);
1175  }
1176  NotifyBacked(wallet, retStatus, strMessage);
1177  return retStatus;
1178 }
1179 
1180 bool CWalletDB::Compact(CDBEnv& dbenv, const std::string& strFile)
1181 {
1182  bool fSuccess = dbenv.Compact(strFile);
1183  return fSuccess;
1184 }
1185 
1186 //
1187 // Try to (very carefully!) recover wallet.dat if there is a problem.
1188 //
1189 bool CWalletDB::Recover(CDBEnv& dbenv, std::string filename, bool fOnlyKeys)
1190 {
1191  // Recovery procedure:
1192  // move wallet.dat to wallet.timestamp.bak
1193  // Call Salvage with fAggressive=true to
1194  // get as much data as possible.
1195  // Rewrite salvaged data to wallet.dat
1196  // Set -rescan so any missing transactions will be
1197  // found.
1198  int64_t now = GetTime();
1199  std::string newFilename = strprintf("wallet.%d.bak", now);
1200 
1201  int result = dbenv.dbenv->dbrename(NULL, filename.c_str(), NULL,
1202  newFilename.c_str(), DB_AUTO_COMMIT);
1203  if (result == 0)
1204  LogPrintf("Renamed %s to %s\n", filename, newFilename);
1205  else {
1206  LogPrintf("Failed to rename %s to %s\n", filename, newFilename);
1207  return false;
1208  }
1209 
1210  std::vector<CDBEnv::KeyValPair> salvagedData;
1211  bool allOK = dbenv.Salvage(newFilename, true, salvagedData);
1212  if (salvagedData.empty()) {
1213  LogPrintf("Salvage(aggressive) found no records in %s.\n", newFilename);
1214  return false;
1215  }
1216  LogPrintf("Salvage(aggressive) found %u records\n", salvagedData.size());
1217 
1218  bool fSuccess = allOK;
1219  boost::scoped_ptr<Db> pdbCopy(new Db(dbenv.dbenv, 0));
1220  int ret = pdbCopy->open(NULL, // Txn pointer
1221  filename.c_str(), // Filename
1222  "main", // Logical db name
1223  DB_BTREE, // Database type
1224  DB_CREATE, // Flags
1225  0);
1226  if (ret > 0) {
1227  LogPrintf("Cannot create database file %s\n", filename);
1228  return false;
1229  }
1230  CWallet dummyWallet;
1231  CWalletScanState wss;
1232 
1233  DbTxn* ptxn = dbenv.TxnBegin();
1234  for (CDBEnv::KeyValPair& row : salvagedData) {
1235  if (fOnlyKeys) {
1236  CDataStream ssKey(row.first, SER_DISK, CLIENT_VERSION);
1237  CDataStream ssValue(row.second, SER_DISK, CLIENT_VERSION);
1238  std::string strType, strErr;
1239  bool fReadOK = ReadKeyValue(&dummyWallet, ssKey, ssValue,
1240  wss, strType, strErr);
1241  if (!IsKeyType(strType))
1242  continue;
1243  if (!fReadOK) {
1244  LogPrintf("WARNING: CWalletDB::Recover skipping %s: %s\n", strType, strErr);
1245  continue;
1246  }
1247  }
1248  Dbt datKey(&row.first[0], row.first.size());
1249  Dbt datValue(&row.second[0], row.second.size());
1250  int ret2 = pdbCopy->put(ptxn, &datKey, &datValue, DB_NOOVERWRITE);
1251  if (ret2 > 0)
1252  fSuccess = false;
1253  }
1254  ptxn->commit(0);
1255  pdbCopy->close(0);
1256 
1257  return fSuccess;
1258 }
1259 
1260 bool CWalletDB::Recover(CDBEnv& dbenv, std::string filename)
1261 {
1262  return CWalletDB::Recover(dbenv, filename, false);
1263 }
1264 
1265 bool CWalletDB::WriteDestData(const std::string& address, const std::string& key, const std::string& value)
1266 {
1267  nWalletDBUpdateCounter++;
1268  return Write(std::make_pair(std::string("destdata"), std::make_pair(address, key)), value);
1269 }
1270 
1271 bool CWalletDB::WriteTxPrivateKey(const std::string& outpointKey, const std::string& k)
1272 {
1273  return Write(std::make_pair(std::string("txpriv"), outpointKey), k);
1274 }
1275 
1276 bool CWalletDB::ReadTxPrivateKey(const std::string& outpointKey, std::string& k)
1277 {
1278  return Read(std::make_pair(std::string("txpriv"), outpointKey), k);
1279 }
1280 
1281 bool CWalletDB::WriteKeyImage(const std::string& outpointKey, const CKeyImage& k)
1282 {
1283  return Write(std::make_pair(std::string("outpointkeyimage"), outpointKey), k);
1284 }
1285 bool CWalletDB::ReadKeyImage(const std::string& outpointKey, CKeyImage& k)
1286 {
1287  return Read(std::make_pair(std::string("outpointkeyimage"), outpointKey), k);
1288 }
1289 
1290 
1291 bool CWalletDB::EraseDestData(const std::string& address, const std::string& key)
1292 {
1293  nWalletDBUpdateCounter++;
1294  return Erase(std::make_pair(std::string("destdata"), std::make_pair(address, key)));
1295 }
1296 
1298 {
1299  nWalletDBUpdateCounter++;
1300  return Write(std::string("hdchain"), chain);
1301 }
1302 
1304 {
1305  nWalletDBUpdateCounter++;
1306 
1307  if (!Write(std::string("chdchain"), chain))
1308  return false;
1309 
1310  Erase(std::string("hdchain"));
1311 
1312  return true;
1313 }
1314 
1315 
1316 bool CWalletDB::WriteHDPubKey(const CHDPubKey& hdPubKey, const CKeyMetadata& keyMeta)
1317 {
1318  nWalletDBUpdateCounter++;
1319 
1320  if (!Write(std::make_pair(std::string("keymeta"), hdPubKey.extPubKey.pubkey), keyMeta, false))
1321  return false;
1322 
1323  return Write(std::make_pair(std::string("hdpubkey"), hdPubKey.extPubKey.pubkey), hdPubKey, false);
1324 }
1325 
1327 {
1328  nWalletDBUpdateCounter++;
1329 }
1330 
1332 {
1333  return nWalletDBUpdateCounter;
1334 }
DB_TOO_NEW
@ DB_TOO_NEW
Definition: walletdb.h:40
CWalletDB::WriteBestBlock
bool WriteBestBlock(const CBlockLocator &locator)
Definition: walletdb.cpp:172
CWalletDB::ReadReserveAmount
bool ReadReserveAmount(double &amount)
Definition: walletdb.cpp:167
CWalletDB::ListAccountCreditDebit
void ListAccountCreditDebit(const std::string &strAccount, std::list< CAccountingEntry > &acentries)
Definition: walletdb.cpp:425
CWalletDB::EraseMultiSig
bool EraseMultiSig(const CScript &script)
Definition: walletdb.cpp:155
CAccountingEntry
Internal transfers.
Definition: wallet.h:982
CWallet::nMasterKeyMaxID
unsigned int nMasterKeyMaxID
Definition: wallet.h:312
CWalletDB::WriteOrderPosNext
bool WriteOrderPosNext(int64_t nOrderPosNext)
Definition: walletdb.cpp:185
CWalletScanState::CWalletScanState
CWalletScanState()
Definition: walletdb.cpp:540
CHDPubKey::extPubKey
CExtPubKey extPubKey
Definition: hdchain.h:99
CWalletDB::WriteKeyImage
bool WriteKeyImage(const std::string &outpointKey, const CKeyImage &k)
Definition: walletdb.cpp:1281
CAccount::SetNull
void SetNull()
Definition: wallet.h:178
DB_LOAD_FAIL
@ DB_LOAD_FAIL
Definition: walletdb.h:41
utiltime.h
CDBEnv::cs_db
RecursiveMutex cs_db
Definition: db.h:40
CWalletDB::FindWalletTx
DBErrors FindWalletTx(CWallet *pwallet, std::vector< uint256 > &vTxHash, std::vector< CWalletTx > &vWtx)
Definition: walletdb.cpp:907
GetTime
int64_t GetTime()
For unit testing.
Definition: utiltime.cpp:19
CWallet::mapWallet
std::map< uint256, CWalletTx > mapWallet
Definition: wallet.h:344
CWalletKey
Private key that includes an expiration date in case it never gets used.
Definition: wallet.h:948
CWallet::fFileBacked
bool fFileBacked
Definition: wallet.h:303
CWalletDB::WriteAutoConsolidateSettingTime
bool WriteAutoConsolidateSettingTime(uint32_t settingTime)
Definition: walletdb.cpp:368
SoftSetBoolArg
bool SoftSetBoolArg(const std::string &strArg, bool fValue)
Set a boolean argument if it doesn't already have a value.
Definition: util.cpp:270
CWalletDB::Write2FAPeriod
bool Write2FAPeriod(int period)
Definition: walletdb.cpp:338
CKeyPool
A key pool entry.
Definition: wallet.h:126
CWalletDB::WriteCryptedHDChain
bool WriteCryptedHDChain(const CHDChain &chain)
Definition: walletdb.cpp:1303
CWalletDB::WritePurpose
bool WritePurpose(const std::string &strAddress, const std::string &purpose)
Definition: walletdb.cpp:64
CWalletDB::ReadStakingStatus
bool ReadStakingStatus()
Definition: walletdb.cpp:296
CWallet::nStakeSplitThreshold
uint64_t nStakeSplitThreshold
Definition: wallet.h:317
CWalletDB::ZapWalletTx
DBErrors ZapWalletTx(CWallet *pwallet, std::vector< CWalletTx > &vWtx)
Definition: walletdb.cpp:967
CWalletDB::ErasePurpose
bool ErasePurpose(const std::string &strAddress)
Definition: walletdb.cpp:70
sync.h
CWalletDB::WriteAccountingEntry_Backend
bool WriteAccountingEntry_Backend(const CAccountingEntry &acentry)
This writes directly to the database, and will not update the CWallet's cached accounting entries!...
Definition: walletdb.cpp:408
CWalletDB::EraseTx
bool EraseTx(uint256 hash)
Definition: walletdb.cpp:82
CWalletDB::WriteMSDisabledAddresses
bool WriteMSDisabledAddresses(std::vector< std::string > vDisabledAddresses)
Definition: walletdb.cpp:234
CBitcoinAddress
base58-encoded PRCY addresses.
Definition: base58.h:109
CDBEnv::Salvage
bool Salvage(std::string strFile, bool fAggressive, std::vector< KeyValPair > &vResult)
Definition: db.cpp:214
NotifyBacked
void NotifyBacked(const CWallet &wallet, bool fSuccess, std::string strMessage)
Definition: walletdb.cpp:1039
CWalletDB::ReadAccount
bool ReadAccount(const std::string &strAccount, CAccount &account)
Definition: walletdb.cpp:362
CWalletScanState::fAnyUnordered
bool fAnyUnordered
Definition: walletdb.cpp:536
CWalletDB::WriteMultiSig
bool WriteMultiSig(const CScript &script)
Definition: walletdb.cpp:149
CPrivKey
std::vector< unsigned char, secure_allocator< unsigned char > > CPrivKey
secp256k1: const unsigned int PRIVATE_KEY_SIZE = 279; const unsigned int PUBLIC_KEY_SIZE = 65; const ...
Definition: key.h:20
CWalletScanState
Definition: walletdb.cpp:529
wallet.h
CWalletDB::Read2FASecret
std::string Read2FASecret()
Definition: walletdb.cpp:330
CWalletDB::WriteCScript
bool WriteCScript(const uint160 &hash, const CScript &redeemScript)
Definition: walletdb.cpp:131
CWallet::nAutoCombineThreshold
CAmount nAutoCombineThreshold
Definition: wallet.h:332
DB_LOAD_OK
@ DB_LOAD_OK
Definition: walletdb.h:37
CWalletKey::vchPrivKey
CPrivKey vchPrivKey
Definition: wallet.h:951
CWallet::LoadCryptedKey
bool LoadCryptedKey(const CPubKey &vchPubKey, const std::vector< unsigned char > &vchCryptedSecret)
Adds an encrypted key to the store, without saving it to disk (used by LoadWallet)
Definition: wallet.cpp:440
CWallet::LoadKey
bool LoadKey(const CKey &key, const CPubKey &pubkey)
Adds a key to the store, without saving it to disk (used by LoadWallet)
Definition: wallet.h:433
CWalletDB::Write2FALastTime
bool Write2FALastTime(uint64_t lastTime)
Definition: walletdb.cpp:350
CWalletDB::EraseMultiSend
bool EraseMultiSend(std::vector< std::pair< std::string, int > > vMultiSend)
Definition: walletdb.cpp:212
CMasterKey
Private key encryption is done based on a CMasterKey, which holds a salt and random encryption key.
Definition: crypter.h:34
TRY_LOCK
#define TRY_LOCK(cs, name)
Definition: sync.h:186
CKeyID
A reference to a CKey: the Hash160 of its serialized public key.
Definition: pubkey.h:29
CDBEnv
Definition: db.h:28
CWalletDB::ReadScannedBlockHeight
bool ReadScannedBlockHeight(int &height)
Definition: walletdb.cpp:308
CStealthAccount
Definition: wallet.h:195
CDBEnv::CloseDb
void CloseDb(const std::string &strFile)
Definition: db.cpp:364
CWallet::TxPair
std::pair< CWalletTx *, CAccountingEntry * > TxPair
Definition: wallet.h:347
CWallet::nOrderPosNext
int64_t nOrderPosNext
Definition: wallet.h:351
CWalletScanState::fIsEncrypted
bool fIsEncrypted
Definition: walletdb.cpp:535
DB_NEED_REWRITE
@ DB_NEED_REWRITE
Definition: walletdb.h:42
CWalletScanState::nFileVersion
int nFileVersion
Definition: walletdb.cpp:537
CWalletDB::WriteCryptedKey
bool WriteCryptedKey(const CPubKey &vchPubKey, const std::vector< unsigned char > &vchCryptedSecret, const CKeyMetadata &keyMeta)
Definition: walletdb.cpp:105
CWalletDB::ReadKeyImage
bool ReadKeyImage(const std::string &outpointKey, CKeyImage &k)
Definition: walletdb.cpp:1285
CAccountingEntry::strAccount
std::string strAccount
Definition: wallet.h:985
CWalletDB::ReadAutoConsolidateSettingTime
uint32_t ReadAutoConsolidateSettingTime()
Definition: walletdb.cpp:373
CDBEnv::KeyValPair
std::pair< std::vector< unsigned char >, std::vector< unsigned char > > KeyValPair
Definition: db.h:70
CHDPubKey
Definition: hdchain.h:92
CDB::WriteVersion
bool WriteVersion(int nVersion)
Definition: db.h:320
CWallet::vDisabledAddresses
std::vector< std::string > vDisabledAddresses
Definition: wallet.h:328
CWallet::NotifyWalletBacked
boost::signals2::signal< void(const bool &fSuccess, const std::string &filename)> NotifyWalletBacked
notify wallet file backed up
Definition: wallet.h:616
CPubKey::begin
const unsigned char * begin() const
Definition: pubkey.h:95
ReadKeyValue
bool ReadKeyValue(CWallet *pwallet, CDataStream &ssKey, CDataStream &ssValue, CWalletScanState &wss, std::string &strType, std::string &strErr)
Definition: walletdb.cpp:549
ThreadFlushWalletDB
void ThreadFlushWalletDB(const std::string &strFile)
Definition: walletdb.cpp:984
CWalletDB::EraseWatchOnly
bool EraseWatchOnly(const CScript &script)
Definition: walletdb.cpp:143
CWalletTx::nTimeReceived
unsigned int nTimeReceived
Definition: wallet.h:801
CDBEnv::CheckpointLSN
void CheckpointLSN(const std::string &strFile)
Definition: db.cpp:264
CWalletScanState::nKeyMeta
unsigned int nKeyMeta
Definition: walletdb.cpp:534
DB_NONCRITICAL_ERROR
@ DB_NONCRITICAL_ERROR
Definition: walletdb.h:39
CWalletDB::WritePool
bool WritePool(int64_t nPool, const CKeyPool &keypool)
Definition: walletdb.cpp:275
CWalletDB::WriteAccountingEntry
bool WriteAccountingEntry(const uint64_t nAccEntryNum, const CAccountingEntry &acentry)
Definition: walletdb.cpp:403
CWalletTx::nOrderPos
int64_t nOrderPos
Definition: wallet.h:805
CDB::Read
bool Read(const K &key, T &value)
Definition: db.h:117
CWalletDB::Read2FAPeriod
int Read2FAPeriod()
Definition: walletdb.cpp:342
CWallet::vchDefaultKey
CPubKey vchDefaultKey
Definition: wallet.h:358
CWalletDB::LoadWallet
DBErrors LoadWallet(CWallet *pwallet)
Definition: walletdb.cpp:811
CWallet::vMultiSend
std::vector< std::pair< std::string, int > > vMultiSend
Definition: wallet.h:322
CWallet::nLastMultiSendHeight
int nLastMultiSendHeight
Definition: wallet.h:327
CWallet::GetUniqueWalletBackupName
std::string GetUniqueWalletBackupName() const
Definition: wallet.cpp:6081
CWalletDB::Write2FA
bool Write2FA(bool status)
Definition: walletdb.cpp:313
CPubKey::end
const unsigned char * end() const
Definition: pubkey.h:96
util::ThreadRename
void ThreadRename(std::string &&)
Rename a thread both in terms of an internal (in-memory) name as well as its system thread name.
Definition: threadnames.cpp:57
CWalletDB::WriteMasterKey
bool WriteMasterKey(unsigned int nID, const CMasterKey &kMasterKey)
Definition: walletdb.cpp:125
CWallet::wtxOrdered
TxItems wtxOrdered
Definition: wallet.h:349
CWalletScanState::vWalletUpgrade
std::vector< uint256 > vWalletUpgrade
Definition: walletdb.cpp:538
CWallet::AddToWallet
bool AddToWallet(const CWalletTx &wtxIn, bool fFromLoadWallet, CWalletDB *pwalletdb)
Definition: wallet.cpp:1171
CWallet::LoadMinVersion
bool LoadMinVersion(int nVersion)
Definition: wallet.cpp:6159
CDB::Erase
bool Erase(const K &key)
Definition: db.h:181
GetBoolArg
bool GetBoolArg(const std::string &strArg, bool fDefault)
Return boolean argument or default value.
Definition: util.cpp:255
CWalletDB::Read2FALastTime
uint64_t Read2FALastTime()
Definition: walletdb.cpp:354
CWallet::LoadHDPubKey
bool LoadHDPubKey(const CHDPubKey &hdPubKey)
loads a HDPubKey into the wallets memory
Definition: wallet.cpp:6940
LogPrintf
#define LogPrintf(...)
Definition: logging.h:147
CAmount
int64_t CAmount
Amount in PRCY (Can be negative)
Definition: amount.h:17
CWalletDB::ReadPool
bool ReadPool(int64_t nPool, CKeyPool &keypool)
Definition: walletdb.cpp:270
CDBEnv::dbenv
DbEnv * dbenv
Definition: db.h:41
CWalletDB::WriteAutoCombineSettings
bool WriteAutoCombineSettings(bool fEnable, CAmount nCombineThreshold)
Definition: walletdb.cpp:255
CStealthAccount::spendAccount
CAccount spendAccount
Definition: wallet.h:198
CDB::ReadAtCursor
int ReadAtCursor(Dbc *pcursor, CDataStream &ssKey, CDataStream &ssValue, unsigned int fFlags=DB_NEXT)
Definition: db.h:233
SER_DISK
@ SER_DISK
Definition: serialize.h:160
CWalletDB::ErasePool
bool ErasePool(int64_t nPool)
Definition: walletdb.cpp:281
CWallet::mapMasterKeys
MasterKeyMap mapMasterKeys
Definition: wallet.h:311
CPubKey::size
unsigned int size() const
Simple read-only vector-like interface to the pubkey data.
Definition: pubkey.h:94
CAccount
Account information.
Definition: wallet.h:167
uint256
256-bit unsigned big integer.
Definition: uint256.h:38
CWalletDB::IncrementUpdateCounter
static void IncrementUpdateCounter()
Definition: walletdb.cpp:1326
CWalletDB::WriteKey
bool WriteKey(const CPubKey &vchPubKey, const CPrivKey &vchPrivKey, const CKeyMetadata &keyMeta)
Definition: walletdb.cpp:88
BCLog::DB
@ DB
Definition: logging.h:46
CWalletDB::Read2FA
bool Read2FA()
Definition: walletdb.cpp:317
CWalletDB::WriteWatchOnly
bool WriteWatchOnly(const CScript &script)
Definition: walletdb.cpp:137
LogPrint
#define LogPrint(category,...)
Definition: logging.h:162
CScript
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:363
base_uint::IsNull
bool IsNull() const
Definition: arith_uint256.h:312
CWalletDB::WriteDefaultKey
bool WriteDefaultKey(const CPubKey &vchPubKey)
Definition: walletdb.cpp:264
CWalletDB::ReadBestBlock
bool ReadBestBlock(CBlockLocator &locator)
Definition: walletdb.cpp:179
CWalletDB::GetAccountCreditDebit
CAmount GetAccountCreditDebit(const std::string &strAccount)
Definition: walletdb.cpp:413
CWallet::LoadWatchOnly
bool LoadWatchOnly(const CScript &dest)
Adds a watch-only address to the store, without saving it to disk (used by LoadWallet)
Definition: wallet.cpp:494
CWallet::laccentries
std::list< CAccountingEntry > laccentries
Definition: wallet.h:345
CWallet::SetHDChain
bool SetHDChain(const CHDChain &chain, bool memonly)
Definition: wallet.cpp:260
GetTimeMillis
int64_t GetTimeMillis()
Definition: utiltime.cpp:31
prevector
Implements a drop-in replacement for std::vector<T> which stores up to N elements directly (without h...
Definition: prevector.h:36
CWalletScanState::nCKeys
unsigned int nCKeys
Definition: walletdb.cpp:533
strprintf
#define strprintf
Definition: tinyformat.h:1056
CWallet::fCombineDust
bool fCombineDust
Definition: wallet.h:331
CWalletDB::WriteAccount
bool WriteAccount(const std::string &strAccount, const CAccount &account)
Definition: walletdb.cpp:383
DBErrors
DBErrors
Error statuses for the wallet database.
Definition: walletdb.h:36
uint160
160-bit unsigned big integer.
Definition: uint256.h:27
CPubKey
An encapsulated public key.
Definition: pubkey.h:37
CKey::Load
bool Load(CPrivKey &privkey, CPubKey &vchPubKey, bool fSkipCheck)
Load private key and check that public key matches.
Definition: key.cpp:146
CDBEnv::mapFileUseCount
std::map< std::string, int > mapFileUseCount
Definition: db.h:42
CWalletDB::ReorderTransactions
DBErrors ReorderTransactions(CWallet *pwallet)
Definition: walletdb.cpp:466
CWallet::SetCryptedHDChain
bool SetCryptedHDChain(const CHDChain &chain, bool memonly)
Definition: wallet.cpp:273
CDB::GetCursor
Dbc * GetCursor()
Definition: db.h:222
CKey
An encapsulated private key.
Definition: key.h:39
CAccountingEntry::nOrderPos
int64_t nOrderPos
Definition: wallet.h:991
CHDChain
Definition: hdchain.h:11
CWallet::setKeyPool
std::set< int64_t > setKeyPool
Definition: wallet.h:307
CBlockLocator::vHave
std::vector< uint256 > vHave
Definition: block.h:251
CStealthAccount::viewAccount
CAccount viewAccount
Definition: wallet.h:199
CDBEnv::TxnBegin
DbTxn * TxnBegin(int flags=DB_TXN_WRITE_NOSYNC)
Definition: db.h:81
LOCK
#define LOCK(cs)
Definition: sync.h:182
CWalletDB::WriteMSettings
bool WriteMSettings(bool fMultiSendStake, bool fMultiSendMasternode, int nLastMultiSendHeight)
Definition: walletdb.cpp:225
key
CKey key
Definition: bip38tooldialog.cpp:173
CWalletDB::WriteTx
bool WriteTx(uint256 hash, const CWalletTx &wtx)
Definition: walletdb.cpp:76
CWallet
A CWallet is an extension of a keystore, which also maintains a set of transactions and balances,...
Definition: wallet.h:243
CWalletTx
A transaction with a bunch of additional info that only the owner cares about.
Definition: wallet.h:792
CWalletScanState::nKeys
unsigned int nKeys
Definition: walletdb.cpp:532
CWalletDB::Write2FASecret
bool Write2FASecret(std::string secret)
Definition: walletdb.cpp:326
CWalletDB::Compact
static bool Compact(CDBEnv &dbenv, const std::string &strFile)
Definition: walletdb.cpp:1180
CDBEnv::Compact
bool Compact(const std::string &strFile)
Salvage data from a file that Verify says is bad.
Definition: db.cpp:165
GetDataDir
const fs::path & GetDataDir(bool fNetSpecific)
Definition: util.cpp:349
CWalletDB::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:1265
CWallet::mapKeyMetadata
std::map< CKeyID, CKeyMetadata > mapKeyMetadata
Definition: wallet.h:308
MilliSleep
void MilliSleep(int64_t n)
Definition: utiltime.cpp:45
CWalletDB::WriteStakeSplitThreshold
bool WriteStakeSplitThreshold(uint64_t nStakeSplitThreshold)
Definition: walletdb.cpp:192
CWalletDB::ReadTxPrivateKey
bool ReadTxPrivateKey(const std::string &outpointKey, std::string &k)
Definition: walletdb.cpp:1276
CWallet::cs_wallet
RecursiveMutex cs_wallet
Definition: wallet.h:301
serialize.h
CDataStream
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:34
CWalletDB::Recover
static bool Recover(CDBEnv &dbenv, std::string filename, bool fOnlyKeys)
Definition: walletdb.cpp:1189
CWallet::LoadKeyMetadata
bool LoadKeyMetadata(const CPubKey &pubkey, const CKeyMetadata &metadata)
Load metadata (used by LoadWallet)
Definition: wallet.cpp:430
base58.h
CWalletDB::EraseMSDisabledAddresses
bool EraseMSDisabledAddresses(std::vector< std::string > vDisabledAddresses)
Definition: walletdb.cpp:245
CTransaction::GetHash
const uint256 & GetHash() const
Definition: transaction.h:342
BackupWallet
bool BackupWallet(const CWallet &wallet, const fs::path &strDest, bool fEnableCustom)
Definition: walletdb.cpp:1045
walletdb.h
CWalletDB::GetUpdateCounter
static unsigned int GetUpdateCounter()
Definition: walletdb.cpp:1331
AttemptBackupWallet
bool AttemptBackupWallet(const CWallet &wallet, const fs::path &pathSrc, const fs::path &pathDest)
Definition: walletdb.cpp:1149
CWalletDB::EraseDestData
bool EraseDestData(const std::string &address, const std::string &key)
Erase destination data tuple from wallet database.
Definition: walletdb.cpp:1291
CExtPubKey::pubkey
CPubKey pubkey
Definition: pubkey.h:210
CAccountingEntry::nEntryNo
uint64_t nEntryNo
position in ordered transaction list
Definition: wallet.h:992
CWalletDB::WriteReserveAmount
bool WriteReserveAmount(const double &amount)
Definition: walletdb.cpp:161
Hash
std::string Hash(std::string input)
Compute the 256-bit hash of a std::string.
Definition: hash.h:122
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:249
CBitcoinAddress::IsValid
bool IsValid() const
Definition: base58.cpp:254
CWallet::fMultiSendStake
bool fMultiSendStake
Definition: wallet.h:323
CWalletDB::WriteHDPubKey
bool WriteHDPubKey(const CHDPubKey &hdPubKey, const CKeyMetadata &keyMeta)
Definition: walletdb.cpp:1316
CBitcoinAddress::Get
CTxDestination Get() const
Definition: base58.cpp:267
CWalletDB::ReadStealthAccount
bool ReadStealthAccount(const std::string &strAccount, CStealthAccount &account)
Definition: walletdb.cpp:388
GetArg
std::string GetArg(const std::string &strArg, const std::string &strDefault)
Return string argument or default value.
Definition: util.cpp:241
CWallet::strWalletFile
std::string strWalletFile
Definition: wallet.h:305
CWalletDB::WriteStealthAccount
bool WriteStealthAccount(const std::string &strAccount, const CStealthAccount &account)
Definition: walletdb.cpp:396
bitdb
CDBEnv bitdb
Definition: db.cpp:29
CWalletDB::ReadStealthAccountList
bool ReadStealthAccountList(std::string &accountList)
Definition: walletdb.cpp:46
DB_CORRUPT
@ DB_CORRUPT
Definition: walletdb.h:38
CWalletDB::WriteScannedBlockHeight
bool WriteScannedBlockHeight(int height)
Definition: walletdb.cpp:304
CWallet::nTimeFirstKey
int64_t nTimeFirstKey
Definition: wallet.h:363
zxcvbn::time_t
double time_t
Definition: time_estimates.hpp:10
CWallet::LoadDestData
bool LoadDestData(const CTxDestination &dest, const std::string &key, const std::string &value)
Adds a destination data tuple to the store, without saving it to disk.
Definition: wallet.cpp:5246
CKeyMetadata
Definition: walletdb.h:45
CWallet::LoadCScript
bool LoadCScript(const CScript &redeemScript)
Definition: wallet.cpp:454
CWallet::mapAddressBook
std::map< CTxDestination, CAddressBookData > mapAddressBook
Definition: wallet.h:354
CWalletDB::AppendStealthAccountList
bool AppendStealthAccountList(const std::string &accountName)
Definition: walletdb.cpp:33
error
bool error(const char *fmt, const Args &... args)
Definition: util.h:61
CWalletDB::WriteStakingStatus
bool WriteStakingStatus(bool status)
Definition: walletdb.cpp:292
CWalletDB::WriteMinVersion
bool WriteMinVersion(int nVersion)
Definition: walletdb.cpp:287
CWalletDB::WriteTxPrivateKey
bool WriteTxPrivateKey(const std::string &outpointKey, const std::string &k)
Definition: walletdb.cpp:1271
CWalletDB::WriteName
bool WriteName(const std::string &strAddress, const std::string &strName)
Definition: walletdb.cpp:50
CWallet::fMultiSendMasternodeReward
bool fMultiSendMasternodeReward
Definition: wallet.h:324
CDB::Write
bool Write(const K &key, const T &value, bool fOverwrite=true)
Definition: db.h:152
CWalletDB::WriteMultiSend
bool WriteMultiSend(std::vector< std::pair< std::string, int > > vMultiSend)
Definition: walletdb.cpp:199
CDB::strFile
std::string strFile
Definition: db.h:99
CWalletDB::WriteHDChain
bool WriteHDChain(const CHDChain &chain)
Definition: walletdb.cpp:1297
CWalletDB::EraseName
bool EraseName(const std::string &strAddress)
Definition: walletdb.cpp:56