1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2014 The Bitcoin Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
6 #include "wallet/walletdb.h"
10 #include "serialize.h"
14 #include "wallet/wallet.h"
16 #include <boost/filesystem.hpp>
17 #include <boost/foreach.hpp>
18 #include <boost/scoped_ptr.hpp>
19 #include <boost/thread.hpp>
23 static uint64_t nAccountingEntryNumber = 0;
29 bool CWalletDB::WriteName(const string& strAddress, const string& strName)
32 return Write(make_pair(string("name"), strAddress), strName);
35 bool CWalletDB::EraseName(const string& strAddress)
37 // This should only be used for sending addresses, never for receiving addresses,
38 // receiving addresses must always have an address book entry if they're not change return.
40 return Erase(make_pair(string("name"), strAddress));
43 bool CWalletDB::WritePurpose(const string& strAddress, const string& strPurpose)
46 return Write(make_pair(string("purpose"), strAddress), strPurpose);
49 bool CWalletDB::ErasePurpose(const string& strPurpose)
52 return Erase(make_pair(string("purpose"), strPurpose));
55 bool CWalletDB::WriteTx(uint256 hash, const CWalletTx& wtx)
58 return Write(std::make_pair(std::string("tx"), hash), wtx);
61 bool CWalletDB::EraseTx(uint256 hash)
64 return Erase(std::make_pair(std::string("tx"), hash));
67 bool CWalletDB::WriteKey(const CPubKey& vchPubKey, const CPrivKey& vchPrivKey, const CKeyMetadata& keyMeta)
71 if (!Write(std::make_pair(std::string("keymeta"), vchPubKey),
75 // hash pubkey/privkey to accelerate wallet load
76 std::vector<unsigned char> vchKey;
77 vchKey.reserve(vchPubKey.size() + vchPrivKey.size());
78 vchKey.insert(vchKey.end(), vchPubKey.begin(), vchPubKey.end());
79 vchKey.insert(vchKey.end(), vchPrivKey.begin(), vchPrivKey.end());
81 return Write(std::make_pair(std::string("key"), vchPubKey), std::make_pair(vchPrivKey, Hash(vchKey.begin(), vchKey.end())), false);
84 bool CWalletDB::WriteCryptedKey(const CPubKey& vchPubKey,
85 const std::vector<unsigned char>& vchCryptedSecret,
86 const CKeyMetadata &keyMeta)
88 const bool fEraseUnencryptedKey = true;
91 if (!Write(std::make_pair(std::string("keymeta"), vchPubKey),
95 if (!Write(std::make_pair(std::string("ckey"), vchPubKey), vchCryptedSecret, false))
97 if (fEraseUnencryptedKey)
99 Erase(std::make_pair(std::string("key"), vchPubKey));
100 Erase(std::make_pair(std::string("wkey"), vchPubKey));
105 bool CWalletDB::WriteMasterKey(unsigned int nID, const CMasterKey& kMasterKey)
108 return Write(std::make_pair(std::string("mkey"), nID), kMasterKey, true);
111 bool CWalletDB::WriteCScript(const uint160& hash, const CScript& redeemScript)
114 return Write(std::make_pair(std::string("cscript"), hash), redeemScript, false);
117 bool CWalletDB::WriteWatchOnly(const CScript &dest)
120 return Write(std::make_pair(std::string("watchs"), dest), '1');
123 bool CWalletDB::EraseWatchOnly(const CScript &dest)
126 return Erase(std::make_pair(std::string("watchs"), dest));
129 bool CWalletDB::WriteBestBlock(const CBlockLocator& locator)
132 return Write(std::string("bestblock"), locator);
135 bool CWalletDB::ReadBestBlock(CBlockLocator& locator)
137 return Read(std::string("bestblock"), locator);
140 bool CWalletDB::WriteOrderPosNext(int64_t nOrderPosNext)
143 return Write(std::string("orderposnext"), nOrderPosNext);
146 bool CWalletDB::WriteDefaultKey(const CPubKey& vchPubKey)
149 return Write(std::string("defaultkey"), vchPubKey);
152 bool CWalletDB::ReadPool(int64_t nPool, CKeyPool& keypool)
154 return Read(std::make_pair(std::string("pool"), nPool), keypool);
157 bool CWalletDB::WritePool(int64_t nPool, const CKeyPool& keypool)
160 return Write(std::make_pair(std::string("pool"), nPool), keypool);
163 bool CWalletDB::ErasePool(int64_t nPool)
166 return Erase(std::make_pair(std::string("pool"), nPool));
169 bool CWalletDB::WriteMinVersion(int nVersion)
171 return Write(std::string("minversion"), nVersion);
174 bool CWalletDB::ReadAccount(const string& strAccount, CAccount& account)
177 return Read(make_pair(string("acc"), strAccount), account);
180 bool CWalletDB::WriteAccount(const string& strAccount, const CAccount& account)
182 return Write(make_pair(string("acc"), strAccount), account);
185 bool CWalletDB::WriteAccountingEntry(const uint64_t nAccEntryNum, const CAccountingEntry& acentry)
187 return Write(std::make_pair(std::string("acentry"), std::make_pair(acentry.strAccount, nAccEntryNum)), acentry);
190 bool CWalletDB::WriteAccountingEntry(const CAccountingEntry& acentry)
192 return WriteAccountingEntry(++nAccountingEntryNumber, acentry);
195 CAmount CWalletDB::GetAccountCreditDebit(const string& strAccount)
197 list<CAccountingEntry> entries;
198 ListAccountCreditDebit(strAccount, entries);
200 CAmount nCreditDebit = 0;
201 BOOST_FOREACH (const CAccountingEntry& entry, entries)
202 nCreditDebit += entry.nCreditDebit;
207 void CWalletDB::ListAccountCreditDebit(const string& strAccount, list<CAccountingEntry>& entries)
209 bool fAllAccounts = (strAccount == "*");
211 Dbc* pcursor = GetCursor();
213 throw runtime_error("CWalletDB::ListAccountCreditDebit(): cannot create DB cursor");
214 unsigned int fFlags = DB_SET_RANGE;
218 CDataStream ssKey(SER_DISK, CLIENT_VERSION);
219 if (fFlags == DB_SET_RANGE)
220 ssKey << std::make_pair(std::string("acentry"), std::make_pair((fAllAccounts ? string("") : strAccount), uint64_t(0)));
221 CDataStream ssValue(SER_DISK, CLIENT_VERSION);
222 int ret = ReadAtCursor(pcursor, ssKey, ssValue, fFlags);
224 if (ret == DB_NOTFOUND)
229 throw runtime_error("CWalletDB::ListAccountCreditDebit(): error scanning DB");
235 if (strType != "acentry")
237 CAccountingEntry acentry;
238 ssKey >> acentry.strAccount;
239 if (!fAllAccounts && acentry.strAccount != strAccount)
243 ssKey >> acentry.nEntryNo;
244 entries.push_back(acentry);
250 DBErrors CWalletDB::ReorderTransactions(CWallet* pwallet)
252 LOCK(pwallet->cs_wallet);
253 // Old wallets didn't have any defined order for transactions
254 // Probably a bad idea to change the output of this
256 // First: get all CWalletTx and CAccountingEntry into a sorted-by-time multimap.
257 typedef pair<CWalletTx*, CAccountingEntry*> TxPair;
258 typedef multimap<int64_t, TxPair > TxItems;
261 for (map<uint256, CWalletTx>::iterator it = pwallet->mapWallet.begin(); it != pwallet->mapWallet.end(); ++it)
263 CWalletTx* wtx = &((*it).second);
264 txByTime.insert(make_pair(wtx->nTimeReceived, TxPair(wtx, (CAccountingEntry*)0)));
266 list<CAccountingEntry> acentries;
267 ListAccountCreditDebit("", acentries);
268 BOOST_FOREACH(CAccountingEntry& entry, acentries)
270 txByTime.insert(make_pair(entry.nTime, TxPair((CWalletTx*)0, &entry)));
273 int64_t& nOrderPosNext = pwallet->nOrderPosNext;
275 std::vector<int64_t> nOrderPosOffsets;
276 for (TxItems::iterator it = txByTime.begin(); it != txByTime.end(); ++it)
278 CWalletTx *const pwtx = (*it).second.first;
279 CAccountingEntry *const pacentry = (*it).second.second;
280 int64_t& nOrderPos = (pwtx != 0) ? pwtx->nOrderPos : pacentry->nOrderPos;
284 nOrderPos = nOrderPosNext++;
285 nOrderPosOffsets.push_back(nOrderPos);
289 if (!WriteTx(pwtx->GetHash(), *pwtx))
293 if (!WriteAccountingEntry(pacentry->nEntryNo, *pacentry))
298 int64_t nOrderPosOff = 0;
299 BOOST_FOREACH(const int64_t& nOffsetStart, nOrderPosOffsets)
301 if (nOrderPos >= nOffsetStart)
304 nOrderPos += nOrderPosOff;
305 nOrderPosNext = std::max(nOrderPosNext, nOrderPos + 1);
310 // Since we're changing the order, write it back
313 if (!WriteTx(pwtx->GetHash(), *pwtx))
317 if (!WriteAccountingEntry(pacentry->nEntryNo, *pacentry))
321 WriteOrderPosNext(nOrderPosNext);
326 class CWalletScanState {
330 unsigned int nKeyMeta;
334 vector<uint256> vWalletUpgrade;
337 nKeys = nCKeys = nKeyMeta = 0;
338 fIsEncrypted = false;
339 fAnyUnordered = false;
345 ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue,
346 CWalletScanState &wss, string& strType, string& strErr)
350 // Taking advantage of the fact that pair serialization
351 // is just the two items serialized one after the other
353 if (strType == "name")
357 ssValue >> pwallet->mapAddressBook[CBitcoinAddress(strAddress).Get()].name;
359 else if (strType == "purpose")
363 ssValue >> pwallet->mapAddressBook[CBitcoinAddress(strAddress).Get()].purpose;
365 else if (strType == "tx")
371 CValidationState state;
372 if (!(CheckTransaction(wtx, state) && (wtx.GetHash() == hash) && state.IsValid()))
375 // Undo serialize changes in 31600
376 if (31404 <= wtx.fTimeReceivedIsTxTime && wtx.fTimeReceivedIsTxTime <= 31703)
378 if (!ssValue.empty())
382 ssValue >> fTmp >> fUnused >> wtx.strFromAccount;
383 strErr = strprintf("LoadWallet() upgrading tx ver=%d %d '%s' %s",
384 wtx.fTimeReceivedIsTxTime, fTmp, wtx.strFromAccount, hash.ToString());
385 wtx.fTimeReceivedIsTxTime = fTmp;
389 strErr = strprintf("LoadWallet() repairing tx ver=%d %s", wtx.fTimeReceivedIsTxTime, hash.ToString());
390 wtx.fTimeReceivedIsTxTime = 0;
392 wss.vWalletUpgrade.push_back(hash);
395 if (wtx.nOrderPos == -1)
396 wss.fAnyUnordered = true;
398 pwallet->AddToWallet(wtx, true, NULL);
400 else if (strType == "acentry")
406 if (nNumber > nAccountingEntryNumber)
407 nAccountingEntryNumber = nNumber;
409 if (!wss.fAnyUnordered)
411 CAccountingEntry acentry;
413 if (acentry.nOrderPos == -1)
414 wss.fAnyUnordered = true;
417 else if (strType == "watchs")
424 pwallet->LoadWatchOnly(script);
426 // Watch-only addresses have no birthday information for now,
427 // so set the wallet birthday to the beginning of time.
428 pwallet->nTimeFirstKey = 1;
430 else if (strType == "key" || strType == "wkey")
434 if (!vchPubKey.IsValid())
436 strErr = "Error reading wallet database: CPubKey corrupt";
443 if (strType == "key")
450 pkey = wkey.vchPrivKey;
453 // Old wallets store keys as "key" [pubkey] => [privkey]
454 // ... which was slow for wallets with lots of keys, because the public key is re-derived from the private key
455 // using EC operations as a checksum.
456 // Newer wallets store keys as "key"[pubkey] => [privkey][hash(pubkey,privkey)], which is much faster while
457 // remaining backwards-compatible.
464 bool fSkipCheck = false;
468 // hash pubkey/privkey to accelerate wallet load
469 std::vector<unsigned char> vchKey;
470 vchKey.reserve(vchPubKey.size() + pkey.size());
471 vchKey.insert(vchKey.end(), vchPubKey.begin(), vchPubKey.end());
472 vchKey.insert(vchKey.end(), pkey.begin(), pkey.end());
474 if (Hash(vchKey.begin(), vchKey.end()) != hash)
476 strErr = "Error reading wallet database: CPubKey/CPrivKey corrupt";
483 if (!key.Load(pkey, vchPubKey, fSkipCheck))
485 strErr = "Error reading wallet database: CPrivKey corrupt";
488 if (!pwallet->LoadKey(key, vchPubKey))
490 strErr = "Error reading wallet database: LoadKey failed";
494 else if (strType == "mkey")
498 CMasterKey kMasterKey;
499 ssValue >> kMasterKey;
500 if(pwallet->mapMasterKeys.count(nID) != 0)
502 strErr = strprintf("Error reading wallet database: duplicate CMasterKey id %u", nID);
505 pwallet->mapMasterKeys[nID] = kMasterKey;
506 if (pwallet->nMasterKeyMaxID < nID)
507 pwallet->nMasterKeyMaxID = nID;
509 else if (strType == "ckey")
511 vector<unsigned char> vchPubKey;
513 vector<unsigned char> vchPrivKey;
514 ssValue >> vchPrivKey;
517 if (!pwallet->LoadCryptedKey(vchPubKey, vchPrivKey))
519 strErr = "Error reading wallet database: LoadCryptedKey failed";
522 wss.fIsEncrypted = true;
524 else if (strType == "keymeta")
528 CKeyMetadata keyMeta;
532 pwallet->LoadKeyMetadata(vchPubKey, keyMeta);
534 // find earliest key creation time, as wallet birthday
535 if (!pwallet->nTimeFirstKey ||
536 (keyMeta.nCreateTime < pwallet->nTimeFirstKey))
537 pwallet->nTimeFirstKey = keyMeta.nCreateTime;
539 else if (strType == "defaultkey")
541 ssValue >> pwallet->vchDefaultKey;
543 else if (strType == "pool")
549 pwallet->setKeyPool.insert(nIndex);
551 // If no metadata exists yet, create a default with the pool key's
552 // creation time. Note that this may be overwritten by actually
553 // stored metadata for that key later, which is fine.
554 CKeyID keyid = keypool.vchPubKey.GetID();
555 if (pwallet->mapKeyMetadata.count(keyid) == 0)
556 pwallet->mapKeyMetadata[keyid] = CKeyMetadata(keypool.nTime);
558 else if (strType == "version")
560 ssValue >> wss.nFileVersion;
561 if (wss.nFileVersion == 10300)
562 wss.nFileVersion = 300;
564 else if (strType == "cscript")
570 if (!pwallet->LoadCScript(script))
572 strErr = "Error reading wallet database: LoadCScript failed";
576 else if (strType == "orderposnext")
578 ssValue >> pwallet->nOrderPosNext;
580 else if (strType == "destdata")
582 std::string strAddress, strKey, strValue;
586 if (!pwallet->LoadDestData(CBitcoinAddress(strAddress).Get(), strKey, strValue))
588 strErr = "Error reading wallet database: LoadDestData failed";
599 static bool IsKeyType(string strType)
601 return (strType== "key" || strType == "wkey" ||
602 strType == "mkey" || strType == "ckey");
605 DBErrors CWalletDB::LoadWallet(CWallet* pwallet)
607 pwallet->vchDefaultKey = CPubKey();
608 CWalletScanState wss;
609 bool fNoncriticalErrors = false;
610 DBErrors result = DB_LOAD_OK;
613 LOCK(pwallet->cs_wallet);
615 if (Read((string)"minversion", nMinVersion))
617 if (nMinVersion > CLIENT_VERSION)
619 pwallet->LoadMinVersion(nMinVersion);
623 Dbc* pcursor = GetCursor();
626 LogPrintf("Error getting wallet database cursor\n");
633 CDataStream ssKey(SER_DISK, CLIENT_VERSION);
634 CDataStream ssValue(SER_DISK, CLIENT_VERSION);
635 int ret = ReadAtCursor(pcursor, ssKey, ssValue);
636 if (ret == DB_NOTFOUND)
640 LogPrintf("Error reading next record from wallet database\n");
644 // Try to be tolerant of single corrupt records:
645 string strType, strErr;
646 if (!ReadKeyValue(pwallet, ssKey, ssValue, wss, strType, strErr))
648 // losing keys is considered a catastrophic error, anything else
649 // we assume the user can live with:
650 if (IsKeyType(strType))
654 // Leave other errors alone, if we try to fix them we might make things worse.
655 fNoncriticalErrors = true; // ... but do warn the user there is something wrong.
657 // Rescan if there is a bad transaction record:
658 SoftSetBoolArg("-rescan", true);
662 LogPrintf("%s\n", strErr);
666 catch (const boost::thread_interrupted&) {
673 if (fNoncriticalErrors && result == DB_LOAD_OK)
674 result = DB_NONCRITICAL_ERROR;
676 // Any wallet corruption at all: skip any rewriting or
677 // upgrading, we don't want to make it worse.
678 if (result != DB_LOAD_OK)
681 LogPrintf("nFileVersion = %d\n", wss.nFileVersion);
683 LogPrintf("Keys: %u plaintext, %u encrypted, %u w/ metadata, %u total\n",
684 wss.nKeys, wss.nCKeys, wss.nKeyMeta, wss.nKeys + wss.nCKeys);
686 // nTimeFirstKey is only reliable if all keys have metadata
687 if ((wss.nKeys + wss.nCKeys) != wss.nKeyMeta)
688 pwallet->nTimeFirstKey = 1; // 0 would be considered 'no value'
690 BOOST_FOREACH(uint256 hash, wss.vWalletUpgrade)
691 WriteTx(hash, pwallet->mapWallet[hash]);
693 // Rewrite encrypted wallets of versions 0.4.0 and 0.5.0rc:
694 if (wss.fIsEncrypted && (wss.nFileVersion == 40000 || wss.nFileVersion == 50000))
695 return DB_NEED_REWRITE;
697 if (wss.nFileVersion < CLIENT_VERSION) // Update
698 WriteVersion(CLIENT_VERSION);
700 if (wss.fAnyUnordered)
701 result = ReorderTransactions(pwallet);
706 DBErrors CWalletDB::FindWalletTx(CWallet* pwallet, vector<uint256>& vTxHash, vector<CWalletTx>& vWtx)
708 pwallet->vchDefaultKey = CPubKey();
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 (const 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 boost::filesystem::path pathSrc = GetDataDir() / wallet.strWalletFile;
868 boost::filesystem::path pathDest(strDest);
869 if (boost::filesystem::is_directory(pathDest))
870 pathDest /= wallet.strWalletFile;
873 #if BOOST_VERSION >= 104000
874 boost::filesystem::copy_file(pathSrc, pathDest, boost::filesystem::copy_option::overwrite_if_exists);
876 boost::filesystem::copy_file(pathSrc, pathDest);
878 LogPrintf("copied wallet.dat to %s\n", pathDest.string());
880 } catch (const boost::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, const 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 boost::scoped_ptr<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);
971 bool CWalletDB::Recover(CDBEnv& dbenv, const std::string& filename)
973 return CWalletDB::Recover(dbenv, filename, false);
976 bool CWalletDB::WriteDestData(const std::string &address, const std::string &key, const std::string &value)
979 return Write(std::make_pair(std::string("destdata"), std::make_pair(address, key)), value);
982 bool CWalletDB::EraseDestData(const std::string &address, const std::string &key)
985 return Erase(std::make_pair(std::string("destdata"), std::make_pair(address, key)));