1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2014 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.
10 #include "serialize.h"
16 #include <boost/filesystem.hpp>
17 #include <boost/foreach.hpp>
18 #include <boost/thread.hpp>
21 using namespace boost;
24 static uint64_t nAccountingEntryNumber = 0;
30 bool CWalletDB::WriteName(const string& strAddress, const string& strName)
33 return Write(make_pair(string("name"), strAddress), strName);
36 bool CWalletDB::EraseName(const string& strAddress)
38 // This should only be used for sending addresses, never for receiving addresses,
39 // receiving addresses must always have an address book entry if they're not change return.
41 return Erase(make_pair(string("name"), strAddress));
44 bool CWalletDB::WritePurpose(const string& strAddress, const string& strPurpose)
47 return Write(make_pair(string("purpose"), strAddress), strPurpose);
50 bool CWalletDB::ErasePurpose(const string& strPurpose)
53 return Erase(make_pair(string("purpose"), strPurpose));
56 bool CWalletDB::WriteTx(uint256 hash, const CWalletTx& wtx)
59 return Write(std::make_pair(std::string("tx"), hash), wtx);
62 bool CWalletDB::EraseTx(uint256 hash)
65 return Erase(std::make_pair(std::string("tx"), hash));
68 bool CWalletDB::WriteKey(const CPubKey& vchPubKey, const CPrivKey& vchPrivKey, const CKeyMetadata& keyMeta)
72 if (!Write(std::make_pair(std::string("keymeta"), vchPubKey),
76 // hash pubkey/privkey to accelerate wallet load
77 std::vector<unsigned char> vchKey;
78 vchKey.reserve(vchPubKey.size() + vchPrivKey.size());
79 vchKey.insert(vchKey.end(), vchPubKey.begin(), vchPubKey.end());
80 vchKey.insert(vchKey.end(), vchPrivKey.begin(), vchPrivKey.end());
82 return Write(std::make_pair(std::string("key"), vchPubKey), std::make_pair(vchPrivKey, Hash(vchKey.begin(), vchKey.end())), false);
85 bool CWalletDB::WriteCryptedKey(const CPubKey& vchPubKey,
86 const std::vector<unsigned char>& vchCryptedSecret,
87 const CKeyMetadata &keyMeta)
89 const bool fEraseUnencryptedKey = true;
92 if (!Write(std::make_pair(std::string("keymeta"), vchPubKey),
96 if (!Write(std::make_pair(std::string("ckey"), vchPubKey), vchCryptedSecret, false))
98 if (fEraseUnencryptedKey)
100 Erase(std::make_pair(std::string("key"), vchPubKey));
101 Erase(std::make_pair(std::string("wkey"), vchPubKey));
106 bool CWalletDB::WriteMasterKey(unsigned int nID, const CMasterKey& kMasterKey)
109 return Write(std::make_pair(std::string("mkey"), nID), kMasterKey, true);
112 bool CWalletDB::WriteCScript(const uint160& hash, const CScript& redeemScript)
115 return Write(std::make_pair(std::string("cscript"), hash), redeemScript, false);
118 bool CWalletDB::WriteWatchOnly(const CScript &dest)
121 return Write(std::make_pair(std::string("watchs"), dest), '1');
124 bool CWalletDB::WriteBestBlock(const CBlockLocator& locator)
127 return Write(std::string("bestblock"), locator);
130 bool CWalletDB::ReadBestBlock(CBlockLocator& locator)
132 return Read(std::string("bestblock"), locator);
135 bool CWalletDB::WriteOrderPosNext(int64_t nOrderPosNext)
138 return Write(std::string("orderposnext"), nOrderPosNext);
141 bool CWalletDB::WriteDefaultKey(const CPubKey& vchPubKey)
144 return Write(std::string("defaultkey"), vchPubKey);
147 bool CWalletDB::ReadPool(int64_t nPool, CKeyPool& keypool)
149 return Read(std::make_pair(std::string("pool"), nPool), keypool);
152 bool CWalletDB::WritePool(int64_t nPool, const CKeyPool& keypool)
155 return Write(std::make_pair(std::string("pool"), nPool), keypool);
158 bool CWalletDB::ErasePool(int64_t nPool)
161 return Erase(std::make_pair(std::string("pool"), nPool));
164 bool CWalletDB::WriteMinVersion(int nVersion)
166 return Write(std::string("minversion"), nVersion);
169 bool CWalletDB::ReadAccount(const string& strAccount, CAccount& account)
172 return Read(make_pair(string("acc"), strAccount), account);
175 bool CWalletDB::WriteAccount(const string& strAccount, const CAccount& account)
177 return Write(make_pair(string("acc"), strAccount), account);
180 bool CWalletDB::WriteAccountingEntry(const uint64_t nAccEntryNum, const CAccountingEntry& acentry)
182 return Write(boost::make_tuple(string("acentry"), acentry.strAccount, nAccEntryNum), acentry);
185 bool CWalletDB::WriteAccountingEntry(const CAccountingEntry& acentry)
187 return WriteAccountingEntry(++nAccountingEntryNumber, acentry);
190 int64_t CWalletDB::GetAccountCreditDebit(const string& strAccount)
192 list<CAccountingEntry> entries;
193 ListAccountCreditDebit(strAccount, entries);
195 int64_t nCreditDebit = 0;
196 BOOST_FOREACH (const CAccountingEntry& entry, entries)
197 nCreditDebit += entry.nCreditDebit;
202 void CWalletDB::ListAccountCreditDebit(const string& strAccount, list<CAccountingEntry>& entries)
204 bool fAllAccounts = (strAccount == "*");
206 Dbc* pcursor = GetCursor();
208 throw runtime_error("CWalletDB::ListAccountCreditDebit() : cannot create DB cursor");
209 unsigned int fFlags = DB_SET_RANGE;
213 CDataStream ssKey(SER_DISK, CLIENT_VERSION);
214 if (fFlags == DB_SET_RANGE)
215 ssKey << boost::make_tuple(string("acentry"), (fAllAccounts? string("") : strAccount), uint64_t(0));
216 CDataStream ssValue(SER_DISK, CLIENT_VERSION);
217 int ret = ReadAtCursor(pcursor, ssKey, ssValue, fFlags);
219 if (ret == DB_NOTFOUND)
224 throw runtime_error("CWalletDB::ListAccountCreditDebit() : error scanning DB");
230 if (strType != "acentry")
232 CAccountingEntry acentry;
233 ssKey >> acentry.strAccount;
234 if (!fAllAccounts && acentry.strAccount != strAccount)
238 ssKey >> acentry.nEntryNo;
239 entries.push_back(acentry);
247 CWalletDB::ReorderTransactions(CWallet* pwallet)
249 LOCK(pwallet->cs_wallet);
250 // Old wallets didn't have any defined order for transactions
251 // Probably a bad idea to change the output of this
253 // First: get all CWalletTx and CAccountingEntry into a sorted-by-time multimap.
254 typedef pair<CWalletTx*, CAccountingEntry*> TxPair;
255 typedef multimap<int64_t, TxPair > TxItems;
258 for (map<uint256, CWalletTx>::iterator it = pwallet->mapWallet.begin(); it != pwallet->mapWallet.end(); ++it)
260 CWalletTx* wtx = &((*it).second);
261 txByTime.insert(make_pair(wtx->nTimeReceived, TxPair(wtx, (CAccountingEntry*)0)));
263 list<CAccountingEntry> acentries;
264 ListAccountCreditDebit("", acentries);
265 BOOST_FOREACH(CAccountingEntry& entry, acentries)
267 txByTime.insert(make_pair(entry.nTime, TxPair((CWalletTx*)0, &entry)));
270 int64_t& nOrderPosNext = pwallet->nOrderPosNext;
272 std::vector<int64_t> nOrderPosOffsets;
273 for (TxItems::iterator it = txByTime.begin(); it != txByTime.end(); ++it)
275 CWalletTx *const pwtx = (*it).second.first;
276 CAccountingEntry *const pacentry = (*it).second.second;
277 int64_t& nOrderPos = (pwtx != 0) ? pwtx->nOrderPos : pacentry->nOrderPos;
281 nOrderPos = nOrderPosNext++;
282 nOrderPosOffsets.push_back(nOrderPos);
285 // Have to write accounting regardless, since we don't keep it in memory
286 if (!WriteAccountingEntry(pacentry->nEntryNo, *pacentry))
291 int64_t nOrderPosOff = 0;
292 BOOST_FOREACH(const int64_t& nOffsetStart, nOrderPosOffsets)
294 if (nOrderPos >= nOffsetStart)
297 nOrderPos += nOrderPosOff;
298 nOrderPosNext = std::max(nOrderPosNext, nOrderPos + 1);
303 // Since we're changing the order, write it back
306 if (!WriteTx(pwtx->GetHash(), *pwtx))
310 if (!WriteAccountingEntry(pacentry->nEntryNo, *pacentry))
318 class CWalletScanState {
322 unsigned int nKeyMeta;
326 vector<uint256> vWalletUpgrade;
329 nKeys = nCKeys = nKeyMeta = 0;
330 fIsEncrypted = false;
331 fAnyUnordered = false;
337 ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue,
338 CWalletScanState &wss, string& strType, string& strErr)
342 // Taking advantage of the fact that pair serialization
343 // is just the two items serialized one after the other
345 if (strType == "name")
349 ssValue >> pwallet->mapAddressBook[CBitcoinAddress(strAddress).Get()].name;
351 else if (strType == "purpose")
355 ssValue >> pwallet->mapAddressBook[CBitcoinAddress(strAddress).Get()].purpose;
357 else if (strType == "tx")
363 CValidationState state;
364 if (!(CheckTransaction(wtx, state) && (wtx.GetHash() == hash) && state.IsValid()))
367 // Undo serialize changes in 31600
368 if (31404 <= wtx.fTimeReceivedIsTxTime && wtx.fTimeReceivedIsTxTime <= 31703)
370 if (!ssValue.empty())
374 ssValue >> fTmp >> fUnused >> wtx.strFromAccount;
375 strErr = strprintf("LoadWallet() upgrading tx ver=%d %d '%s' %s",
376 wtx.fTimeReceivedIsTxTime, fTmp, wtx.strFromAccount, hash.ToString());
377 wtx.fTimeReceivedIsTxTime = fTmp;
381 strErr = strprintf("LoadWallet() repairing tx ver=%d %s", wtx.fTimeReceivedIsTxTime, hash.ToString());
382 wtx.fTimeReceivedIsTxTime = 0;
384 wss.vWalletUpgrade.push_back(hash);
387 if (wtx.nOrderPos == -1)
388 wss.fAnyUnordered = true;
390 pwallet->AddToWallet(wtx, true);
392 //LogPrintf("LoadWallet %s\n", wtx.GetHash().ToString());
393 //LogPrintf(" %12d %s %s %s\n",
394 // wtx.vout[0].nValue,
395 // DateTimeStrFormat("%Y-%m-%d %H:%M:%S", wtx.GetBlockTime()),
396 // wtx.hashBlock.ToString(),
397 // wtx.mapValue["message"]);
399 else if (strType == "acentry")
405 if (nNumber > nAccountingEntryNumber)
406 nAccountingEntryNumber = nNumber;
408 if (!wss.fAnyUnordered)
410 CAccountingEntry acentry;
412 if (acentry.nOrderPos == -1)
413 wss.fAnyUnordered = true;
416 else if (strType == "watchs")
423 pwallet->LoadWatchOnly(script);
425 // Watch-only addresses have no birthday information for now,
426 // so set the wallet birthday to the beginning of time.
427 pwallet->nTimeFirstKey = 1;
429 else if (strType == "key" || strType == "wkey")
433 if (!vchPubKey.IsValid())
435 strErr = "Error reading wallet database: CPubKey corrupt";
442 if (strType == "key")
449 pkey = wkey.vchPrivKey;
452 // Old wallets store keys as "key" [pubkey] => [privkey]
453 // ... which was slow for wallets with lots of keys, because the public key is re-derived from the private key
454 // using EC operations as a checksum.
455 // Newer wallets store keys as "key"[pubkey] => [privkey][hash(pubkey,privkey)], which is much faster while
456 // remaining backwards-compatible.
463 bool fSkipCheck = false;
467 // hash pubkey/privkey to accelerate wallet load
468 std::vector<unsigned char> vchKey;
469 vchKey.reserve(vchPubKey.size() + pkey.size());
470 vchKey.insert(vchKey.end(), vchPubKey.begin(), vchPubKey.end());
471 vchKey.insert(vchKey.end(), pkey.begin(), pkey.end());
473 if (Hash(vchKey.begin(), vchKey.end()) != hash)
475 strErr = "Error reading wallet database: CPubKey/CPrivKey corrupt";
482 if (!key.Load(pkey, vchPubKey, fSkipCheck))
484 strErr = "Error reading wallet database: CPrivKey corrupt";
487 if (!pwallet->LoadKey(key, vchPubKey))
489 strErr = "Error reading wallet database: LoadKey failed";
493 else if (strType == "mkey")
497 CMasterKey kMasterKey;
498 ssValue >> kMasterKey;
499 if(pwallet->mapMasterKeys.count(nID) != 0)
501 strErr = strprintf("Error reading wallet database: duplicate CMasterKey id %u", nID);
504 pwallet->mapMasterKeys[nID] = kMasterKey;
505 if (pwallet->nMasterKeyMaxID < nID)
506 pwallet->nMasterKeyMaxID = nID;
508 else if (strType == "ckey")
510 vector<unsigned char> vchPubKey;
512 vector<unsigned char> vchPrivKey;
513 ssValue >> vchPrivKey;
516 if (!pwallet->LoadCryptedKey(vchPubKey, vchPrivKey))
518 strErr = "Error reading wallet database: LoadCryptedKey failed";
521 wss.fIsEncrypted = true;
523 else if (strType == "keymeta")
527 CKeyMetadata keyMeta;
531 pwallet->LoadKeyMetadata(vchPubKey, keyMeta);
533 // find earliest key creation time, as wallet birthday
534 if (!pwallet->nTimeFirstKey ||
535 (keyMeta.nCreateTime < pwallet->nTimeFirstKey))
536 pwallet->nTimeFirstKey = keyMeta.nCreateTime;
538 else if (strType == "defaultkey")
540 ssValue >> pwallet->vchDefaultKey;
542 else if (strType == "pool")
548 pwallet->setKeyPool.insert(nIndex);
550 // If no metadata exists yet, create a default with the pool key's
551 // creation time. Note that this may be overwritten by actually
552 // stored metadata for that key later, which is fine.
553 CKeyID keyid = keypool.vchPubKey.GetID();
554 if (pwallet->mapKeyMetadata.count(keyid) == 0)
555 pwallet->mapKeyMetadata[keyid] = CKeyMetadata(keypool.nTime);
557 else if (strType == "version")
559 ssValue >> wss.nFileVersion;
560 if (wss.nFileVersion == 10300)
561 wss.nFileVersion = 300;
563 else if (strType == "cscript")
569 if (!pwallet->LoadCScript(script))
571 strErr = "Error reading wallet database: LoadCScript failed";
575 else if (strType == "orderposnext")
577 ssValue >> pwallet->nOrderPosNext;
579 else if (strType == "destdata")
581 std::string strAddress, strKey, strValue;
585 if (!pwallet->LoadDestData(CBitcoinAddress(strAddress).Get(), strKey, strValue))
587 strErr = "Error reading wallet database: LoadDestData failed";
598 static bool IsKeyType(string strType)
600 return (strType== "key" || strType == "wkey" ||
601 strType == "mkey" || strType == "ckey");
604 DBErrors CWalletDB::LoadWallet(CWallet* pwallet)
606 pwallet->vchDefaultKey = CPubKey();
607 CWalletScanState wss;
608 bool fNoncriticalErrors = false;
609 DBErrors result = DB_LOAD_OK;
612 LOCK(pwallet->cs_wallet);
614 if (Read((string)"minversion", nMinVersion))
616 if (nMinVersion > CLIENT_VERSION)
618 pwallet->LoadMinVersion(nMinVersion);
622 Dbc* pcursor = GetCursor();
625 LogPrintf("Error getting wallet database cursor\n");
632 CDataStream ssKey(SER_DISK, CLIENT_VERSION);
633 CDataStream ssValue(SER_DISK, CLIENT_VERSION);
634 int ret = ReadAtCursor(pcursor, ssKey, ssValue);
635 if (ret == DB_NOTFOUND)
639 LogPrintf("Error reading next record from wallet database\n");
643 // Try to be tolerant of single corrupt records:
644 string strType, strErr;
645 if (!ReadKeyValue(pwallet, ssKey, ssValue, wss, strType, strErr))
647 // losing keys is considered a catastrophic error, anything else
648 // we assume the user can live with:
649 if (IsKeyType(strType))
653 // Leave other errors alone, if we try to fix them we might make things worse.
654 fNoncriticalErrors = true; // ... but do warn the user there is something wrong.
656 // Rescan if there is a bad transaction record:
657 SoftSetBoolArg("-rescan", true);
661 LogPrintf("%s\n", strErr);
665 catch (boost::thread_interrupted) {
672 if (fNoncriticalErrors && result == DB_LOAD_OK)
673 result = DB_NONCRITICAL_ERROR;
675 // Any wallet corruption at all: skip any rewriting or
676 // upgrading, we don't want to make it worse.
677 if (result != DB_LOAD_OK)
680 LogPrintf("nFileVersion = %d\n", wss.nFileVersion);
682 LogPrintf("Keys: %u plaintext, %u encrypted, %u w/ metadata, %u total\n",
683 wss.nKeys, wss.nCKeys, wss.nKeyMeta, wss.nKeys + wss.nCKeys);
685 // nTimeFirstKey is only reliable if all keys have metadata
686 if ((wss.nKeys + wss.nCKeys) != wss.nKeyMeta)
687 pwallet->nTimeFirstKey = 1; // 0 would be considered 'no value'
689 BOOST_FOREACH(uint256 hash, wss.vWalletUpgrade)
690 WriteTx(hash, pwallet->mapWallet[hash]);
692 // Rewrite encrypted wallets of versions 0.4.0 and 0.5.0rc:
693 if (wss.fIsEncrypted && (wss.nFileVersion == 40000 || wss.nFileVersion == 50000))
694 return DB_NEED_REWRITE;
696 if (wss.nFileVersion < CLIENT_VERSION) // Update
697 WriteVersion(CLIENT_VERSION);
699 if (wss.fAnyUnordered)
700 result = ReorderTransactions(pwallet);
705 DBErrors CWalletDB::FindWalletTx(CWallet* pwallet, vector<uint256>& vTxHash, vector<CWalletTx>& vWtx)
707 pwallet->vchDefaultKey = CPubKey();
708 CWalletScanState wss;
709 bool fNoncriticalErrors = false;
710 DBErrors result = DB_LOAD_OK;
713 LOCK(pwallet->cs_wallet);
715 if (Read((string)"minversion", nMinVersion))
717 if (nMinVersion > CLIENT_VERSION)
719 pwallet->LoadMinVersion(nMinVersion);
723 Dbc* pcursor = GetCursor();
726 LogPrintf("Error getting wallet database cursor\n");
733 CDataStream ssKey(SER_DISK, CLIENT_VERSION);
734 CDataStream ssValue(SER_DISK, CLIENT_VERSION);
735 int ret = ReadAtCursor(pcursor, ssKey, ssValue);
736 if (ret == DB_NOTFOUND)
740 LogPrintf("Error reading next record from wallet database\n");
746 if (strType == "tx") {
753 vTxHash.push_back(hash);
759 catch (boost::thread_interrupted) {
766 if (fNoncriticalErrors && result == DB_LOAD_OK)
767 result = DB_NONCRITICAL_ERROR;
772 DBErrors CWalletDB::ZapWalletTx(CWallet* pwallet, vector<CWalletTx>& vWtx)
774 // build list of wallet TXs
775 vector<uint256> vTxHash;
776 DBErrors err = FindWalletTx(pwallet, vTxHash, vWtx);
777 if (err != DB_LOAD_OK)
780 // erase each wallet TX
781 BOOST_FOREACH (uint256& hash, vTxHash) {
789 void ThreadFlushWalletDB(const string& strFile)
791 // Make this thread recognisable as the wallet flushing thread
792 RenameThread("bitcoin-wallet");
794 static bool fOneThread;
798 if (!GetBoolArg("-flushwallet", true))
801 unsigned int nLastSeen = nWalletDBUpdated;
802 unsigned int nLastFlushed = nWalletDBUpdated;
803 int64_t nLastWalletUpdate = GetTime();
808 if (nLastSeen != nWalletDBUpdated)
810 nLastSeen = nWalletDBUpdated;
811 nLastWalletUpdate = GetTime();
814 if (nLastFlushed != nWalletDBUpdated && GetTime() - nLastWalletUpdate >= 2)
816 TRY_LOCK(bitdb.cs_db,lockDb);
819 // Don't do this if any databases are in use
821 map<string, int>::iterator mi = bitdb.mapFileUseCount.begin();
822 while (mi != bitdb.mapFileUseCount.end())
824 nRefCount += (*mi).second;
830 boost::this_thread::interruption_point();
831 map<string, int>::iterator mi = bitdb.mapFileUseCount.find(strFile);
832 if (mi != bitdb.mapFileUseCount.end())
834 LogPrint("db", "Flushing wallet.dat\n");
835 nLastFlushed = nWalletDBUpdated;
836 int64_t nStart = GetTimeMillis();
838 // Flush wallet.dat so it's self contained
839 bitdb.CloseDb(strFile);
840 bitdb.CheckpointLSN(strFile);
842 bitdb.mapFileUseCount.erase(mi++);
843 LogPrint("db", "Flushed wallet.dat %dms\n", GetTimeMillis() - nStart);
851 bool BackupWallet(const CWallet& wallet, const string& strDest)
853 if (!wallet.fFileBacked)
859 if (!bitdb.mapFileUseCount.count(wallet.strWalletFile) || bitdb.mapFileUseCount[wallet.strWalletFile] == 0)
861 // Flush log data to the dat file
862 bitdb.CloseDb(wallet.strWalletFile);
863 bitdb.CheckpointLSN(wallet.strWalletFile);
864 bitdb.mapFileUseCount.erase(wallet.strWalletFile);
867 filesystem::path pathSrc = GetDataDir() / wallet.strWalletFile;
868 filesystem::path pathDest(strDest);
869 if (filesystem::is_directory(pathDest))
870 pathDest /= wallet.strWalletFile;
873 #if BOOST_VERSION >= 104000
874 filesystem::copy_file(pathSrc, pathDest, filesystem::copy_option::overwrite_if_exists);
876 filesystem::copy_file(pathSrc, pathDest);
878 LogPrintf("copied wallet.dat to %s\n", pathDest.string());
880 } catch(const filesystem::filesystem_error &e) {
881 LogPrintf("error copying wallet.dat to %s - %s\n", pathDest.string(), e.what());
892 // Try to (very carefully!) recover wallet.dat if there is a problem.
894 bool CWalletDB::Recover(CDBEnv& dbenv, std::string filename, bool fOnlyKeys)
896 // Recovery procedure:
897 // move wallet.dat to wallet.timestamp.bak
898 // Call Salvage with fAggressive=true to
899 // get as much data as possible.
900 // Rewrite salvaged data to wallet.dat
901 // Set -rescan so any missing transactions will be
903 int64_t now = GetTime();
904 std::string newFilename = strprintf("wallet.%d.bak", now);
906 int result = dbenv.dbenv.dbrename(NULL, filename.c_str(), NULL,
907 newFilename.c_str(), DB_AUTO_COMMIT);
909 LogPrintf("Renamed %s to %s\n", filename, newFilename);
912 LogPrintf("Failed to rename %s to %s\n", filename, newFilename);
916 std::vector<CDBEnv::KeyValPair> salvagedData;
917 bool allOK = dbenv.Salvage(newFilename, true, salvagedData);
918 if (salvagedData.empty())
920 LogPrintf("Salvage(aggressive) found no records in %s.\n", newFilename);
923 LogPrintf("Salvage(aggressive) found %u records\n", salvagedData.size());
925 bool fSuccess = allOK;
926 Db* pdbCopy = new Db(&dbenv.dbenv, 0);
927 int ret = pdbCopy->open(NULL, // Txn pointer
928 filename.c_str(), // Filename
929 "main", // Logical db name
930 DB_BTREE, // Database type
935 LogPrintf("Cannot create database file %s\n", filename);
939 CWalletScanState wss;
941 DbTxn* ptxn = dbenv.TxnBegin();
942 BOOST_FOREACH(CDBEnv::KeyValPair& row, salvagedData)
946 CDataStream ssKey(row.first, SER_DISK, CLIENT_VERSION);
947 CDataStream ssValue(row.second, SER_DISK, CLIENT_VERSION);
948 string strType, strErr;
949 bool fReadOK = ReadKeyValue(&dummyWallet, ssKey, ssValue,
950 wss, strType, strErr);
951 if (!IsKeyType(strType))
955 LogPrintf("WARNING: CWalletDB::Recover skipping %s: %s\n", strType, strErr);
959 Dbt datKey(&row.first[0], row.first.size());
960 Dbt datValue(&row.second[0], row.second.size());
961 int ret2 = pdbCopy->put(ptxn, &datKey, &datValue, DB_NOOVERWRITE);
972 bool CWalletDB::Recover(CDBEnv& dbenv, std::string filename)
974 return CWalletDB::Recover(dbenv, filename, false);
977 bool CWalletDB::WriteDestData(const std::string &address, const std::string &key, const std::string &value)
980 return Write(boost::make_tuple(std::string("destdata"), address, key), value);
983 bool CWalletDB::EraseDestData(const std::string &address, const std::string &key)
986 return Erase(boost::make_tuple(string("destdata"), address, key));