Feathercoin  0.5.0
P2P Digital Currency
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
walletdb.cpp
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2012 The Bitcoin developers
3 // Distributed under the MIT/X11 software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #include "walletdb.h"
7 #include "wallet.h"
8 #include <boost/version.hpp>
9 #include <boost/filesystem.hpp>
10 
11 using namespace std;
12 using namespace boost;
13 
14 
15 static uint64 nAccountingEntryNumber = 0;
16 
17 //
18 // CWalletDB
19 //
20 
21 bool CWalletDB::WriteName(const string& strAddress, const string& strName)
22 {
24  return Write(make_pair(string("name"), strAddress), strName);
25 }
26 
27 bool CWalletDB::EraseName(const string& strAddress)
28 {
29  // This should only be used for sending addresses, never for receiving addresses,
30  // receiving addresses must always have an address book entry if they're not change return.
32  return Erase(make_pair(string("name"), strAddress));
33 }
34 
35 bool CWalletDB::ReadAccount(const string& strAccount, CAccount& account)
36 {
37  account.SetNull();
38  return Read(make_pair(string("acc"), strAccount), account);
39 }
40 
41 bool CWalletDB::WriteAccount(const string& strAccount, const CAccount& account)
42 {
43  return Write(make_pair(string("acc"), strAccount), account);
44 }
45 
46 bool CWalletDB::WriteAccountingEntry(const uint64 nAccEntryNum, const CAccountingEntry& acentry)
47 {
48  return Write(boost::make_tuple(string("acentry"), acentry.strAccount, nAccEntryNum), acentry);
49 }
50 
52 {
53  return WriteAccountingEntry(++nAccountingEntryNumber, acentry);
54 }
55 
56 int64 CWalletDB::GetAccountCreditDebit(const string& strAccount)
57 {
58  list<CAccountingEntry> entries;
59  ListAccountCreditDebit(strAccount, entries);
60 
61  int64 nCreditDebit = 0;
62  BOOST_FOREACH (const CAccountingEntry& entry, entries)
63  nCreditDebit += entry.nCreditDebit;
64 
65  return nCreditDebit;
66 }
67 
68 void CWalletDB::ListAccountCreditDebit(const string& strAccount, list<CAccountingEntry>& entries)
69 {
70  bool fAllAccounts = (strAccount == "*");
71 
72  Dbc* pcursor = GetCursor();
73  if (!pcursor)
74  throw runtime_error("CWalletDB::ListAccountCreditDebit() : cannot create DB cursor");
75  unsigned int fFlags = DB_SET_RANGE;
76  loop
77  {
78  // Read next record
79  CDataStream ssKey(SER_DISK, CLIENT_VERSION);
80  if (fFlags == DB_SET_RANGE)
81  ssKey << boost::make_tuple(string("acentry"), (fAllAccounts? string("") : strAccount), uint64(0));
82  CDataStream ssValue(SER_DISK, CLIENT_VERSION);
83  int ret = ReadAtCursor(pcursor, ssKey, ssValue, fFlags);
84  fFlags = DB_NEXT;
85  if (ret == DB_NOTFOUND)
86  break;
87  else if (ret != 0)
88  {
89  pcursor->close();
90  throw runtime_error("CWalletDB::ListAccountCreditDebit() : error scanning DB");
91  }
92 
93  // Unserialize
94  string strType;
95  ssKey >> strType;
96  if (strType != "acentry")
97  break;
98  CAccountingEntry acentry;
99  ssKey >> acentry.strAccount;
100  if (!fAllAccounts && acentry.strAccount != strAccount)
101  break;
102 
103  ssValue >> acentry;
104  ssKey >> acentry.nEntryNo;
105  entries.push_back(acentry);
106  }
107 
108  pcursor->close();
109 }
110 
111 
112 DBErrors
114 {
115  LOCK(pwallet->cs_wallet);
116  // Old wallets didn't have any defined order for transactions
117  // Probably a bad idea to change the output of this
118 
119  // First: get all CWalletTx and CAccountingEntry into a sorted-by-time multimap.
120  typedef pair<CWalletTx*, CAccountingEntry*> TxPair;
121  typedef multimap<int64, TxPair > TxItems;
122  TxItems txByTime;
123 
124  for (map<uint256, CWalletTx>::iterator it = pwallet->mapWallet.begin(); it != pwallet->mapWallet.end(); ++it)
125  {
126  CWalletTx* wtx = &((*it).second);
127  txByTime.insert(make_pair(wtx->nTimeReceived, TxPair(wtx, (CAccountingEntry*)0)));
128  }
129  list<CAccountingEntry> acentries;
130  ListAccountCreditDebit("", acentries);
131  BOOST_FOREACH(CAccountingEntry& entry, acentries)
132  {
133  txByTime.insert(make_pair(entry.nTime, TxPair((CWalletTx*)0, &entry)));
134  }
135 
136  int64& nOrderPosNext = pwallet->nOrderPosNext;
137  nOrderPosNext = 0;
138  std::vector<int64> nOrderPosOffsets;
139  for (TxItems::iterator it = txByTime.begin(); it != txByTime.end(); ++it)
140  {
141  CWalletTx *const pwtx = (*it).second.first;
142  CAccountingEntry *const pacentry = (*it).second.second;
143  int64& nOrderPos = (pwtx != 0) ? pwtx->nOrderPos : pacentry->nOrderPos;
144 
145  if (nOrderPos == -1)
146  {
147  nOrderPos = nOrderPosNext++;
148  nOrderPosOffsets.push_back(nOrderPos);
149 
150  if (pacentry)
151  // Have to write accounting regardless, since we don't keep it in memory
152  if (!WriteAccountingEntry(pacentry->nEntryNo, *pacentry))
153  return DB_LOAD_FAIL;
154  }
155  else
156  {
157  int64 nOrderPosOff = 0;
158  BOOST_FOREACH(const int64& nOffsetStart, nOrderPosOffsets)
159  {
160  if (nOrderPos >= nOffsetStart)
161  ++nOrderPosOff;
162  }
163  nOrderPos += nOrderPosOff;
164  nOrderPosNext = std::max(nOrderPosNext, nOrderPos + 1);
165 
166  if (!nOrderPosOff)
167  continue;
168 
169  // Since we're changing the order, write it back
170  if (pwtx)
171  {
172  if (!WriteTx(pwtx->GetHash(), *pwtx))
173  return DB_LOAD_FAIL;
174  }
175  else
176  if (!WriteAccountingEntry(pacentry->nEntryNo, *pacentry))
177  return DB_LOAD_FAIL;
178  }
179  }
180 
181  return DB_LOAD_OK;
182 }
183 
184 
185 bool
186 ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue,
187  int& nFileVersion, vector<uint256>& vWalletUpgrade,
188  bool& fIsEncrypted, bool& fAnyUnordered, string& strType, string& strErr)
189 {
190  try {
191  // Unserialize
192  // Taking advantage of the fact that pair serialization
193  // is just the two items serialized one after the other
194  ssKey >> strType;
195  if (strType == "name")
196  {
197  string strAddress;
198  ssKey >> strAddress;
199  ssValue >> pwallet->mapAddressBook[CBitcoinAddress(strAddress).Get()];
200  }
201  else if (strType == "tx")
202  {
203  uint256 hash;
204  ssKey >> hash;
205  CWalletTx& wtx = pwallet->mapWallet[hash];
206  ssValue >> wtx;
208  if (wtx.CheckTransaction(state) && (wtx.GetHash() == hash) && state.IsValid())
209  wtx.BindWallet(pwallet);
210  else
211  {
212  pwallet->mapWallet.erase(hash);
213  return false;
214  }
215 
216  // Undo serialize changes in 31600
217  if (31404 <= wtx.fTimeReceivedIsTxTime && wtx.fTimeReceivedIsTxTime <= 31703)
218  {
219  if (!ssValue.empty())
220  {
221  char fTmp;
222  char fUnused;
223  ssValue >> fTmp >> fUnused >> wtx.strFromAccount;
224  strErr = strprintf("LoadWallet() upgrading tx ver=%d %d '%s' %s",
225  wtx.fTimeReceivedIsTxTime, fTmp, wtx.strFromAccount.c_str(), hash.ToString().c_str());
226  wtx.fTimeReceivedIsTxTime = fTmp;
227  }
228  else
229  {
230  strErr = strprintf("LoadWallet() repairing tx ver=%d %s", wtx.fTimeReceivedIsTxTime, hash.ToString().c_str());
231  wtx.fTimeReceivedIsTxTime = 0;
232  }
233  vWalletUpgrade.push_back(hash);
234  }
235 
236  if (wtx.nOrderPos == -1)
237  fAnyUnordered = true;
238 
240  //printf("LoadWallet %s\n", wtx.GetHash().ToString().c_str());
241  //printf(" %12"PRI64d" %s %s %s\n",
242  // wtx.vout[0].nValue,
243  // DateTimeStrFormat("%Y-%m-%d %H:%M:%S", wtx.GetBlockTime()).c_str(),
244  // wtx.hashBlock.ToString().c_str(),
245  // wtx.mapValue["message"].c_str());
246  }
247  else if (strType == "acentry")
248  {
249  string strAccount;
250  ssKey >> strAccount;
251  uint64 nNumber;
252  ssKey >> nNumber;
253  if (nNumber > nAccountingEntryNumber)
254  nAccountingEntryNumber = nNumber;
255 
256  if (!fAnyUnordered)
257  {
258  CAccountingEntry acentry;
259  ssValue >> acentry;
260  if (acentry.nOrderPos == -1)
261  fAnyUnordered = true;
262  }
263  }
264  else if (strType == "key" || strType == "wkey")
265  {
266  CPubKey vchPubKey;
267  ssKey >> vchPubKey;
268  if (!vchPubKey.IsValid())
269  {
270  strErr = "Error reading wallet database: CPubKey corrupt";
271  return false;
272  }
273  CKey key;
274  CPrivKey pkey;
275  if (strType == "key")
276  ssValue >> pkey;
277  else {
278  CWalletKey wkey;
279  ssValue >> wkey;
280  pkey = wkey.vchPrivKey;
281  }
282  if (!key.SetPrivKey(pkey, vchPubKey.IsCompressed()))
283  {
284  strErr = "Error reading wallet database: CPrivKey corrupt";
285  return false;
286  }
287  if (key.GetPubKey() != vchPubKey)
288  {
289  strErr = "Error reading wallet database: CPrivKey pubkey inconsistency";
290  return false;
291  }
292  if (!pwallet->LoadKey(key, vchPubKey))
293  {
294  strErr = "Error reading wallet database: LoadKey failed";
295  return false;
296  }
297  }
298  else if (strType == "mkey")
299  {
300  unsigned int nID;
301  ssKey >> nID;
302  CMasterKey kMasterKey;
303  ssValue >> kMasterKey;
304  if(pwallet->mapMasterKeys.count(nID) != 0)
305  {
306  strErr = strprintf("Error reading wallet database: duplicate CMasterKey id %u", nID);
307  return false;
308  }
309  pwallet->mapMasterKeys[nID] = kMasterKey;
310  if (pwallet->nMasterKeyMaxID < nID)
311  pwallet->nMasterKeyMaxID = nID;
312  }
313  else if (strType == "ckey")
314  {
315  vector<unsigned char> vchPubKey;
316  ssKey >> vchPubKey;
317  vector<unsigned char> vchPrivKey;
318  ssValue >> vchPrivKey;
319  if (!pwallet->LoadCryptedKey(vchPubKey, vchPrivKey))
320  {
321  strErr = "Error reading wallet database: LoadCryptedKey failed";
322  return false;
323  }
324  fIsEncrypted = true;
325  }
326  else if (strType == "defaultkey")
327  {
328  ssValue >> pwallet->vchDefaultKey;
329  }
330  else if (strType == "pool")
331  {
332  int64 nIndex;
333  ssKey >> nIndex;
334  pwallet->setKeyPool.insert(nIndex);
335  }
336  else if (strType == "version")
337  {
338  ssValue >> nFileVersion;
339  if (nFileVersion == 10300)
340  nFileVersion = 300;
341  }
342  else if (strType == "cscript")
343  {
344  uint160 hash;
345  ssKey >> hash;
346  CScript script;
347  ssValue >> script;
348  if (!pwallet->LoadCScript(script))
349  {
350  strErr = "Error reading wallet database: LoadCScript failed";
351  return false;
352  }
353  }
354  else if (strType == "orderposnext")
355  {
356  ssValue >> pwallet->nOrderPosNext;
357  }
358  } catch (...)
359  {
360  return false;
361  }
362  return true;
363 }
364 
365 static bool IsKeyType(string strType)
366 {
367  return (strType== "key" || strType == "wkey" ||
368  strType == "mkey" || strType == "ckey");
369 }
370 
372 {
373  pwallet->vchDefaultKey = CPubKey();
374  int nFileVersion = 0;
375  vector<uint256> vWalletUpgrade;
376  bool fIsEncrypted = false;
377  bool fAnyUnordered = false;
378  bool fNoncriticalErrors = false;
379  DBErrors result = DB_LOAD_OK;
380 
381  try {
382  LOCK(pwallet->cs_wallet);
383  int nMinVersion = 0;
384  if (Read((string)"minversion", nMinVersion))
385  {
386  if (nMinVersion > CLIENT_VERSION)
387  return DB_TOO_NEW;
388  pwallet->LoadMinVersion(nMinVersion);
389  }
390 
391  // Get cursor
392  Dbc* pcursor = GetCursor();
393  if (!pcursor)
394  {
395  printf("Error getting wallet database cursor\n");
396  return DB_CORRUPT;
397  }
398 
399  loop
400  {
401  // Read next record
402  CDataStream ssKey(SER_DISK, CLIENT_VERSION);
403  CDataStream ssValue(SER_DISK, CLIENT_VERSION);
404  int ret = ReadAtCursor(pcursor, ssKey, ssValue);
405  if (ret == DB_NOTFOUND)
406  break;
407  else if (ret != 0)
408  {
409  printf("Error reading next record from wallet database\n");
410  return DB_CORRUPT;
411  }
412 
413  // Try to be tolerant of single corrupt records:
414  string strType, strErr;
415  if (!ReadKeyValue(pwallet, ssKey, ssValue, nFileVersion,
416  vWalletUpgrade, fIsEncrypted, fAnyUnordered, strType, strErr))
417  {
418  // losing keys is considered a catastrophic error, anything else
419  // we assume the user can live with:
420  if (IsKeyType(strType))
421  result = DB_CORRUPT;
422  else
423  {
424  // Leave other errors alone, if we try to fix them we might make things worse.
425  fNoncriticalErrors = true; // ... but do warn the user there is something wrong.
426  if (strType == "tx")
427  // Rescan if there is a bad transaction record:
428  SoftSetBoolArg("-rescan", true);
429  }
430  }
431  if (!strErr.empty())
432  printf("%s\n", strErr.c_str());
433  }
434  pcursor->close();
435  }
436  catch (boost::thread_interrupted) {
437  throw;
438  }
439  catch (...) {
440  result = DB_CORRUPT;
441  }
442 
443  if (fNoncriticalErrors && result == DB_LOAD_OK)
444  result = DB_NONCRITICAL_ERROR;
445 
446  // Any wallet corruption at all: skip any rewriting or
447  // upgrading, we don't want to make it worse.
448  if (result != DB_LOAD_OK)
449  return result;
450 
451  printf("nFileVersion = %d\n", nFileVersion);
452 
453  BOOST_FOREACH(uint256 hash, vWalletUpgrade)
454  WriteTx(hash, pwallet->mapWallet[hash]);
455 
456  // Rewrite encrypted wallets of versions 0.4.0 and 0.5.0rc:
457  if (fIsEncrypted && (nFileVersion == 40000 || nFileVersion == 50000))
458  return DB_NEED_REWRITE;
459 
460  if (nFileVersion < CLIENT_VERSION) // Update
461  WriteVersion(CLIENT_VERSION);
462 
463  if (fAnyUnordered)
464  result = ReorderTransactions(pwallet);
465 
466  return result;
467 }
468 
469 void ThreadFlushWalletDB(const string& strFile)
470 {
471  // Make this thread recognisable as the wallet flushing thread
472  RenameThread("bitcoin-wallet");
473 
474  static bool fOneThread;
475  if (fOneThread)
476  return;
477  fOneThread = true;
478  if (!GetBoolArg("-flushwallet", true))
479  return;
480 
481  unsigned int nLastSeen = nWalletDBUpdated;
482  unsigned int nLastFlushed = nWalletDBUpdated;
483  int64 nLastWalletUpdate = GetTime();
484  while (true)
485  {
486  MilliSleep(500);
487 
488  if (nLastSeen != nWalletDBUpdated)
489  {
490  nLastSeen = nWalletDBUpdated;
491  nLastWalletUpdate = GetTime();
492  }
493 
494  if (nLastFlushed != nWalletDBUpdated && GetTime() - nLastWalletUpdate >= 2)
495  {
496  TRY_LOCK(bitdb.cs_db,lockDb);
497  if (lockDb)
498  {
499  // Don't do this if any databases are in use
500  int nRefCount = 0;
501  map<string, int>::iterator mi = bitdb.mapFileUseCount.begin();
502  while (mi != bitdb.mapFileUseCount.end())
503  {
504  nRefCount += (*mi).second;
505  mi++;
506  }
507 
508  if (nRefCount == 0)
509  {
510  boost::this_thread::interruption_point();
511  map<string, int>::iterator mi = bitdb.mapFileUseCount.find(strFile);
512  if (mi != bitdb.mapFileUseCount.end())
513  {
514  printf("Flushing wallet.dat\n");
515  nLastFlushed = nWalletDBUpdated;
516  int64 nStart = GetTimeMillis();
517 
518  // Flush wallet.dat so it's self contained
519  bitdb.CloseDb(strFile);
520  bitdb.CheckpointLSN(strFile);
521 
522  bitdb.mapFileUseCount.erase(mi++);
523  printf("Flushed wallet.dat %"PRI64d"ms\n", GetTimeMillis() - nStart);
524  }
525  }
526  }
527  }
528  }
529 }
530 
531 bool BackupWallet(const CWallet& wallet, const string& strDest)
532 {
533  if (!wallet.fFileBacked)
534  return false;
535  while (true)
536  {
537  {
538  LOCK(bitdb.cs_db);
539  if (!bitdb.mapFileUseCount.count(wallet.strWalletFile) || bitdb.mapFileUseCount[wallet.strWalletFile] == 0)
540  {
541  // Flush log data to the dat file
542  bitdb.CloseDb(wallet.strWalletFile);
544  bitdb.mapFileUseCount.erase(wallet.strWalletFile);
545 
546  // Copy wallet.dat
547  filesystem::path pathSrc = GetDataDir() / wallet.strWalletFile;
548  filesystem::path pathDest(strDest);
549  if (filesystem::is_directory(pathDest))
550  pathDest /= wallet.strWalletFile;
551 
552  try {
553 #if BOOST_VERSION >= 104000
554  filesystem::copy_file(pathSrc, pathDest, filesystem::copy_option::overwrite_if_exists);
555 #else
556  filesystem::copy_file(pathSrc, pathDest);
557 #endif
558  printf("copied wallet.dat to %s\n", pathDest.string().c_str());
559  return true;
560  } catch(const filesystem::filesystem_error &e) {
561  printf("error copying wallet.dat to %s - %s\n", pathDest.string().c_str(), e.what());
562  return false;
563  }
564  }
565  }
566  MilliSleep(100);
567  }
568  return false;
569 }
570 
571 //
572 // Try to (very carefully!) recover wallet.dat if there is a problem.
573 //
574 bool CWalletDB::Recover(CDBEnv& dbenv, std::string filename, bool fOnlyKeys)
575 {
576  // Recovery procedure:
577  // move wallet.dat to wallet.timestamp.bak
578  // Call Salvage with fAggressive=true to
579  // get as much data as possible.
580  // Rewrite salvaged data to wallet.dat
581  // Set -rescan so any missing transactions will be
582  // found.
583  int64 now = GetTime();
584  std::string newFilename = strprintf("wallet.%"PRI64d".bak", now);
585 
586  int result = dbenv.dbenv.dbrename(NULL, filename.c_str(), NULL,
587  newFilename.c_str(), DB_AUTO_COMMIT);
588  if (result == 0)
589  printf("Renamed %s to %s\n", filename.c_str(), newFilename.c_str());
590  else
591  {
592  printf("Failed to rename %s to %s\n", filename.c_str(), newFilename.c_str());
593  return false;
594  }
595 
596  std::vector<CDBEnv::KeyValPair> salvagedData;
597  bool allOK = dbenv.Salvage(newFilename, true, salvagedData);
598  if (salvagedData.empty())
599  {
600  printf("Salvage(aggressive) found no records in %s.\n", newFilename.c_str());
601  return false;
602  }
603  printf("Salvage(aggressive) found %"PRIszu" records\n", salvagedData.size());
604 
605  bool fSuccess = allOK;
606  Db* pdbCopy = new Db(&dbenv.dbenv, 0);
607  int ret = pdbCopy->open(NULL, // Txn pointer
608  filename.c_str(), // Filename
609  "main", // Logical db name
610  DB_BTREE, // Database type
611  DB_CREATE, // Flags
612  0);
613  if (ret > 0)
614  {
615  printf("Cannot create database file %s\n", filename.c_str());
616  return false;
617  }
618  CWallet dummyWallet;
619  int nFileVersion = 0;
620  vector<uint256> vWalletUpgrade;
621  bool fIsEncrypted = false;
622  bool fAnyUnordered = false;
623 
624  DbTxn* ptxn = dbenv.TxnBegin();
625  BOOST_FOREACH(CDBEnv::KeyValPair& row, salvagedData)
626  {
627  if (fOnlyKeys)
628  {
629  CDataStream ssKey(row.first, SER_DISK, CLIENT_VERSION);
630  CDataStream ssValue(row.second, SER_DISK, CLIENT_VERSION);
631  string strType, strErr;
632  bool fReadOK = ReadKeyValue(&dummyWallet, ssKey, ssValue,
633  nFileVersion, vWalletUpgrade,
634  fIsEncrypted, fAnyUnordered,
635  strType, strErr);
636  if (!IsKeyType(strType))
637  continue;
638  if (!fReadOK)
639  {
640  printf("WARNING: CWalletDB::Recover skipping %s: %s\n", strType.c_str(), strErr.c_str());
641  continue;
642  }
643  }
644  Dbt datKey(&row.first[0], row.first.size());
645  Dbt datValue(&row.second[0], row.second.size());
646  int ret2 = pdbCopy->put(ptxn, &datKey, &datValue, DB_NOOVERWRITE);
647  if (ret2 > 0)
648  fSuccess = false;
649  }
650  ptxn->commit(0);
651  pdbCopy->close(0);
652  delete pdbCopy;
653 
654  return fSuccess;
655 }
656 
657 bool CWalletDB::Recover(CDBEnv& dbenv, std::string filename)
658 {
659  return CWalletDB::Recover(dbenv, filename, false);
660 }
const boost::filesystem::path & GetDataDir(bool fNetSpecific)
Definition: util.cpp:1060
unsigned int nWalletDBUpdated
Definition: db.cpp:21
bool LoadCryptedKey(const CPubKey &vchPubKey, const std::vector< unsigned char > &vchCryptedSecret)
Definition: wallet.cpp:77
#define PRIszu
Definition: util.h:70
Account information.
Definition: wallet.h:758
#define strprintf(format,...)
Definition: util.h:169
std::map< std::string, int > mapFileUseCount
Definition: db.h:43
#define PRI64d
Definition: util.h:51
int64 GetAccountCreditDebit(const std::string &strAccount)
Definition: walletdb.cpp:56
void CheckpointLSN(std::string strFile)
Definition: db.cpp:209
bool WriteAccount(const std::string &strAccount, const CAccount &account)
Definition: walletdb.cpp:41
DbTxn * TxnBegin(int flags=DB_TXN_WRITE_NOSYNC)
Definition: db.h:77
CPrivKey vchPrivKey
Definition: wallet.h:726
#define TRY_LOCK(cs, name)
Definition: sync.h:110
Definition: util.cpp:28
CCriticalSection cs_wallet
Definition: wallet.h:83
int64 nTime
Definition: wallet.h:791
int64 nOrderPos
Definition: wallet.h:382
bool SoftSetBoolArg(const std::string &strArg, bool fValue)
Set a boolean argument if it doesn't already have a value.
Definition: util.cpp:619
CPubKey vchDefaultKey
Definition: wallet.h:121
Master key for wallet encryption.
Definition: crypter.h:30
uint256 GetHash() const
Definition: main.h:515
void ListAccountCreditDebit(const std::string &strAccount, std::list< CAccountingEntry > &acentries)
Definition: walletdb.cpp:68
void SetNull()
Definition: wallet.h:768
Double ended buffer combining vector and stream-like interfaces.
Definition: serialize.h:799
unsigned long long uint64
Definition: serialize.h:26
bool BackupWallet(const CWallet &wallet, const string &strDest)
Definition: walletdb.cpp:531
DBErrors
Error statuses for the wallet database.
Definition: walletdb.h:16
CTxDestination Get() const
Definition: base58.h:345
void RenameThread(const char *name)
Definition: util.cpp:1467
int64 GetTime()
Definition: util.cpp:1298
CDBEnv bitdb
Definition: db.cpp:29
int64 GetTimeMillis()
Definition: util.h:340
std::vector< unsigned char, secure_allocator< unsigned char > > CPrivKey
Definition: key.h:169
void MilliSleep(int64 n)
Definition: util.h:106
#define loop
Definition: util.h:38
bool GetBoolArg(const std::string &strArg, bool fDefault)
Return boolean argument or default value.
Definition: util.cpp:600
unsigned int nMasterKeyMaxID
Definition: wallet.h:93
bool WriteAccountingEntry(const uint64 nAccEntryNum, const CAccountingEntry &acentry)
Definition: walletdb.cpp:46
#define printf
Definition: rpcdump.cpp:12
CPubKey GetPubKey() const
Definition: key.cpp:312
#define LOCK(cs)
Definition: sync.h:108
bool WriteName(const std::string &strAddress, const std::string &strName)
Definition: walletdb.cpp:21
DBErrors LoadWallet(CWallet *pwallet)
Definition: walletdb.cpp:371
An encapsulated public key.
Definition: key.h:40
MTState * state
Definition: db_test.cc:1708
bool LoadKey(const CKey &key, const CPubKey &pubkey)
Definition: wallet.h:142
CCriticalSection cs_db
Definition: db.h:41
bool LoadCScript(const CScript &redeemScript)
Definition: wallet.h:151
uint64 nEntryNo
Definition: wallet.h:796
bool LoadMinVersion(int nVersion)
Definition: wallet.h:144
A transaction with a bunch of additional info that only the owner cares about.
Definition: wallet.h:367
DBErrors ReorderTransactions(CWallet *)
Definition: walletdb.cpp:113
std::string strWalletFile
Definition: wallet.h:86
bool fFileBacked
Definition: wallet.h:85
Capture information about block/transaction validation.
Definition: main.h:1907
256-bit unsigned integer
Definition: uint256.h:537
void ThreadFlushWalletDB(const string &strFile)
Definition: walletdb.cpp:469
bool SetPrivKey(const CPrivKey &vchPrivKey, bool fCompressed)
Definition: key.cpp:293
std::set< int64 > setKeyPool
Definition: wallet.h:88
bool IsValid()
Definition: main.h:1937
bool Salvage(std::string strFile, bool fAggressive, std::vector< KeyValPair > &vResult)
Definition: db.cpp:154
MasterKeyMap mapMasterKeys
Definition: wallet.h:92
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:244
void CloseDb(const std::string &strFile)
Definition: db.cpp:311
bool ReadKeyValue(CWallet *pwallet, CDataStream &ssKey, CDataStream &ssValue, int &nFileVersion, vector< uint256 > &vWalletUpgrade, bool &fIsEncrypted, bool &fAnyUnordered, string &strType, string &strErr)
Definition: walletdb.cpp:186
static bool Recover(CDBEnv &dbenv, std::string filename, bool fOnlyKeys)
Definition: walletdb.cpp:574
Private key that includes an expiration date in case it never gets used.
Definition: wallet.h:723
Internal transfers.
Definition: wallet.h:786
Definition: db.h:31
int64 nOrderPosNext
Definition: wallet.h:116
A CWallet is an extension of a keystore, which also maintains a set of transactions and balances...
Definition: wallet.h:69
160-bit unsigned integer
Definition: uint256.h:422
std::map< CTxDestination, std::string > mapAddressBook
Definition: wallet.h:119
std::map< uint256, CWalletTx > mapWallet
Definition: wallet.h:115
int64 nOrderPos
Definition: wallet.h:795
DbEnv dbenv
Definition: db.h:42
unsigned int nTimeReceived
Definition: wallet.h:377
An encapsulated private key.
Definition: key.h:172
bool EraseName(const std::string &strAddress)
Definition: walletdb.cpp:27
int64 nCreditDebit
Definition: wallet.h:790
std::pair< std::vector< unsigned char >, std::vector< unsigned char > > KeyValPair
Definition: db.h:66
uint32_t hash
Definition: cache.cc:34
bool ReadAccount(const std::string &strAccount, CAccount &account)
Definition: walletdb.cpp:35
bool empty() const
Definition: serialize.h:889
long long int64
Definition: serialize.h:25
std::string strAccount
Definition: wallet.h:789