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"
11 #include "serialize.h"
15 #include "wallet/wallet.h"
17 #include <boost/filesystem.hpp>
18 #include <boost/foreach.hpp>
19 #include <boost/scoped_ptr.hpp>
20 #include <boost/thread.hpp>
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::EraseWatchOnly(const CScript &dest)
127 return Erase(std::make_pair(std::string("watchs"), dest));
130 bool CWalletDB::WriteBestBlock(const CBlockLocator& locator)
133 return Write(std::string("bestblock"), locator);
136 bool CWalletDB::ReadBestBlock(CBlockLocator& locator)
138 return Read(std::string("bestblock"), locator);
141 bool CWalletDB::WriteOrderPosNext(int64_t nOrderPosNext)
144 return Write(std::string("orderposnext"), nOrderPosNext);
147 bool CWalletDB::WriteDefaultKey(const CPubKey& vchPubKey)
150 return Write(std::string("defaultkey"), vchPubKey);
153 bool CWalletDB::ReadPool(int64_t nPool, CKeyPool& keypool)
155 return Read(std::make_pair(std::string("pool"), nPool), keypool);
158 bool CWalletDB::WritePool(int64_t nPool, const CKeyPool& keypool)
161 return Write(std::make_pair(std::string("pool"), nPool), keypool);
164 bool CWalletDB::ErasePool(int64_t nPool)
167 return Erase(std::make_pair(std::string("pool"), nPool));
170 bool CWalletDB::WriteMinVersion(int nVersion)
172 return Write(std::string("minversion"), nVersion);
175 bool CWalletDB::ReadAccount(const string& strAccount, CAccount& account)
178 return Read(make_pair(string("acc"), strAccount), account);
181 bool CWalletDB::WriteAccount(const string& strAccount, const CAccount& account)
183 return Write(make_pair(string("acc"), strAccount), account);
186 bool CWalletDB::WriteAccountingEntry(const uint64_t nAccEntryNum, const CAccountingEntry& acentry)
188 return Write(std::make_pair(std::string("acentry"), std::make_pair(acentry.strAccount, nAccEntryNum)), acentry);
191 bool CWalletDB::WriteAccountingEntry(const CAccountingEntry& acentry)
193 return WriteAccountingEntry(++nAccountingEntryNumber, acentry);
196 CAmount CWalletDB::GetAccountCreditDebit(const string& strAccount)
198 list<CAccountingEntry> entries;
199 ListAccountCreditDebit(strAccount, entries);
201 CAmount nCreditDebit = 0;
202 BOOST_FOREACH (const CAccountingEntry& entry, entries)
203 nCreditDebit += entry.nCreditDebit;
208 void CWalletDB::ListAccountCreditDebit(const string& strAccount, list<CAccountingEntry>& entries)
210 bool fAllAccounts = (strAccount == "*");
212 Dbc* pcursor = GetCursor();
214 throw runtime_error("CWalletDB::ListAccountCreditDebit(): cannot create DB cursor");
215 unsigned int fFlags = DB_SET_RANGE;
219 CDataStream ssKey(SER_DISK, CLIENT_VERSION);
220 if (fFlags == DB_SET_RANGE)
221 ssKey << std::make_pair(std::string("acentry"), std::make_pair((fAllAccounts ? string("") : strAccount), uint64_t(0)));
222 CDataStream ssValue(SER_DISK, CLIENT_VERSION);
223 int ret = ReadAtCursor(pcursor, ssKey, ssValue, fFlags);
225 if (ret == DB_NOTFOUND)
230 throw runtime_error("CWalletDB::ListAccountCreditDebit(): error scanning DB");
236 if (strType != "acentry")
238 CAccountingEntry acentry;
239 ssKey >> acentry.strAccount;
240 if (!fAllAccounts && acentry.strAccount != strAccount)
244 ssKey >> acentry.nEntryNo;
245 entries.push_back(acentry);
251 DBErrors CWalletDB::ReorderTransactions(CWallet* pwallet)
253 LOCK(pwallet->cs_wallet);
254 // Old wallets didn't have any defined order for transactions
255 // Probably a bad idea to change the output of this
257 // First: get all CWalletTx and CAccountingEntry into a sorted-by-time multimap.
258 typedef pair<CWalletTx*, CAccountingEntry*> TxPair;
259 typedef multimap<int64_t, TxPair > TxItems;
262 for (map<uint256, CWalletTx>::iterator it = pwallet->mapWallet.begin(); it != pwallet->mapWallet.end(); ++it)
264 CWalletTx* wtx = &((*it).second);
265 txByTime.insert(make_pair(wtx->nTimeReceived, TxPair(wtx, (CAccountingEntry*)0)));
267 list<CAccountingEntry> acentries;
268 ListAccountCreditDebit("", acentries);
269 BOOST_FOREACH(CAccountingEntry& entry, acentries)
271 txByTime.insert(make_pair(entry.nTime, TxPair((CWalletTx*)0, &entry)));
274 int64_t& nOrderPosNext = pwallet->nOrderPosNext;
276 std::vector<int64_t> nOrderPosOffsets;
277 for (TxItems::iterator it = txByTime.begin(); it != txByTime.end(); ++it)
279 CWalletTx *const pwtx = (*it).second.first;
280 CAccountingEntry *const pacentry = (*it).second.second;
281 int64_t& nOrderPos = (pwtx != 0) ? pwtx->nOrderPos : pacentry->nOrderPos;
285 nOrderPos = nOrderPosNext++;
286 nOrderPosOffsets.push_back(nOrderPos);
290 if (!WriteTx(pwtx->GetHash(), *pwtx))
294 if (!WriteAccountingEntry(pacentry->nEntryNo, *pacentry))
299 int64_t nOrderPosOff = 0;
300 BOOST_FOREACH(const int64_t& nOffsetStart, nOrderPosOffsets)
302 if (nOrderPos >= nOffsetStart)
305 nOrderPos += nOrderPosOff;
306 nOrderPosNext = std::max(nOrderPosNext, nOrderPos + 1);
311 // Since we're changing the order, write it back
314 if (!WriteTx(pwtx->GetHash(), *pwtx))
318 if (!WriteAccountingEntry(pacentry->nEntryNo, *pacentry))
322 WriteOrderPosNext(nOrderPosNext);
327 class CWalletScanState {
331 unsigned int nKeyMeta;
335 vector<uint256> vWalletUpgrade;
338 nKeys = nCKeys = nKeyMeta = 0;
339 fIsEncrypted = false;
340 fAnyUnordered = false;
346 ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue,
347 CWalletScanState &wss, string& strType, string& strErr)
351 // Taking advantage of the fact that pair serialization
352 // is just the two items serialized one after the other
354 if (strType == "name")
358 ssValue >> pwallet->mapAddressBook[CBitcoinAddress(strAddress).Get()].name;
360 else if (strType == "purpose")
364 ssValue >> pwallet->mapAddressBook[CBitcoinAddress(strAddress).Get()].purpose;
366 else if (strType == "tx")
372 CValidationState state;
373 if (!(CheckTransaction(wtx, state) && (wtx.GetHash() == hash) && state.IsValid()))
376 // Undo serialize changes in 31600
377 if (31404 <= wtx.fTimeReceivedIsTxTime && wtx.fTimeReceivedIsTxTime <= 31703)
379 if (!ssValue.empty())
383 ssValue >> fTmp >> fUnused >> wtx.strFromAccount;
384 strErr = strprintf("LoadWallet() upgrading tx ver=%d %d '%s' %s",
385 wtx.fTimeReceivedIsTxTime, fTmp, wtx.strFromAccount, hash.ToString());
386 wtx.fTimeReceivedIsTxTime = fTmp;
390 strErr = strprintf("LoadWallet() repairing tx ver=%d %s", wtx.fTimeReceivedIsTxTime, hash.ToString());
391 wtx.fTimeReceivedIsTxTime = 0;
393 wss.vWalletUpgrade.push_back(hash);
396 if (wtx.nOrderPos == -1)
397 wss.fAnyUnordered = true;
399 pwallet->AddToWallet(wtx, true, NULL);
401 else if (strType == "acentry")
407 if (nNumber > nAccountingEntryNumber)
408 nAccountingEntryNumber = nNumber;
410 if (!wss.fAnyUnordered)
412 CAccountingEntry acentry;
414 if (acentry.nOrderPos == -1)
415 wss.fAnyUnordered = true;
418 else if (strType == "watchs")
425 pwallet->LoadWatchOnly(script);
427 // Watch-only addresses have no birthday information for now,
428 // so set the wallet birthday to the beginning of time.
429 pwallet->nTimeFirstKey = 1;
431 else if (strType == "key" || strType == "wkey")
435 if (!vchPubKey.IsValid())
437 strErr = "Error reading wallet database: CPubKey corrupt";
444 if (strType == "key")
451 pkey = wkey.vchPrivKey;
454 // Old wallets store keys as "key" [pubkey] => [privkey]
455 // ... which was slow for wallets with lots of keys, because the public key is re-derived from the private key
456 // using EC operations as a checksum.
457 // Newer wallets store keys as "key"[pubkey] => [privkey][hash(pubkey,privkey)], which is much faster while
458 // remaining backwards-compatible.
465 bool fSkipCheck = false;
469 // hash pubkey/privkey to accelerate wallet load
470 std::vector<unsigned char> vchKey;
471 vchKey.reserve(vchPubKey.size() + pkey.size());
472 vchKey.insert(vchKey.end(), vchPubKey.begin(), vchPubKey.end());
473 vchKey.insert(vchKey.end(), pkey.begin(), pkey.end());
475 if (Hash(vchKey.begin(), vchKey.end()) != hash)
477 strErr = "Error reading wallet database: CPubKey/CPrivKey corrupt";
484 if (!key.Load(pkey, vchPubKey, fSkipCheck))
486 strErr = "Error reading wallet database: CPrivKey corrupt";
489 if (!pwallet->LoadKey(key, vchPubKey))
491 strErr = "Error reading wallet database: LoadKey failed";
495 else if (strType == "mkey")
499 CMasterKey kMasterKey;
500 ssValue >> kMasterKey;
501 if(pwallet->mapMasterKeys.count(nID) != 0)
503 strErr = strprintf("Error reading wallet database: duplicate CMasterKey id %u", nID);
506 pwallet->mapMasterKeys[nID] = kMasterKey;
507 if (pwallet->nMasterKeyMaxID < nID)
508 pwallet->nMasterKeyMaxID = nID;
510 else if (strType == "ckey")
512 vector<unsigned char> vchPubKey;
514 vector<unsigned char> vchPrivKey;
515 ssValue >> vchPrivKey;
518 if (!pwallet->LoadCryptedKey(vchPubKey, vchPrivKey))
520 strErr = "Error reading wallet database: LoadCryptedKey failed";
523 wss.fIsEncrypted = true;
525 else if (strType == "keymeta")
529 CKeyMetadata keyMeta;
533 pwallet->LoadKeyMetadata(vchPubKey, keyMeta);
535 // find earliest key creation time, as wallet birthday
536 if (!pwallet->nTimeFirstKey ||
537 (keyMeta.nCreateTime < pwallet->nTimeFirstKey))
538 pwallet->nTimeFirstKey = keyMeta.nCreateTime;
540 else if (strType == "defaultkey")
542 ssValue >> pwallet->vchDefaultKey;
544 else if (strType == "pool")
550 pwallet->setKeyPool.insert(nIndex);
552 // If no metadata exists yet, create a default with the pool key's
553 // creation time. Note that this may be overwritten by actually
554 // stored metadata for that key later, which is fine.
555 CKeyID keyid = keypool.vchPubKey.GetID();
556 if (pwallet->mapKeyMetadata.count(keyid) == 0)
557 pwallet->mapKeyMetadata[keyid] = CKeyMetadata(keypool.nTime);
559 else if (strType == "version")
561 ssValue >> wss.nFileVersion;
562 if (wss.nFileVersion == 10300)
563 wss.nFileVersion = 300;
565 else if (strType == "cscript")
571 if (!pwallet->LoadCScript(script))
573 strErr = "Error reading wallet database: LoadCScript failed";
577 else if (strType == "orderposnext")
579 ssValue >> pwallet->nOrderPosNext;
581 else if (strType == "destdata")
583 std::string strAddress, strKey, strValue;
587 if (!pwallet->LoadDestData(CBitcoinAddress(strAddress).Get(), strKey, strValue))
589 strErr = "Error reading wallet database: LoadDestData failed";
600 static bool IsKeyType(string strType)
602 return (strType== "key" || strType == "wkey" ||
603 strType == "mkey" || strType == "ckey");
606 DBErrors CWalletDB::LoadWallet(CWallet* pwallet)
608 pwallet->vchDefaultKey = CPubKey();
609 CWalletScanState wss;
610 bool fNoncriticalErrors = false;
611 DBErrors result = DB_LOAD_OK;
614 LOCK(pwallet->cs_wallet);
616 if (Read((string)"minversion", nMinVersion))
618 if (nMinVersion > CLIENT_VERSION)
620 pwallet->LoadMinVersion(nMinVersion);
624 Dbc* pcursor = GetCursor();
627 LogPrintf("Error getting wallet database cursor\n");
634 CDataStream ssKey(SER_DISK, CLIENT_VERSION);
635 CDataStream ssValue(SER_DISK, CLIENT_VERSION);
636 int ret = ReadAtCursor(pcursor, ssKey, ssValue);
637 if (ret == DB_NOTFOUND)
641 LogPrintf("Error reading next record from wallet database\n");
645 // Try to be tolerant of single corrupt records:
646 string strType, strErr;
647 if (!ReadKeyValue(pwallet, ssKey, ssValue, wss, strType, strErr))
649 // losing keys is considered a catastrophic error, anything else
650 // we assume the user can live with:
651 if (IsKeyType(strType))
655 // Leave other errors alone, if we try to fix them we might make things worse.
656 fNoncriticalErrors = true; // ... but do warn the user there is something wrong.
658 // Rescan if there is a bad transaction record:
659 SoftSetBoolArg("-rescan", true);
663 LogPrintf("%s\n", strErr);
667 catch (const boost::thread_interrupted&) {
674 if (fNoncriticalErrors && result == DB_LOAD_OK)
675 result = DB_NONCRITICAL_ERROR;
677 // Any wallet corruption at all: skip any rewriting or
678 // upgrading, we don't want to make it worse.
679 if (result != DB_LOAD_OK)
682 LogPrintf("nFileVersion = %d\n", wss.nFileVersion);
684 LogPrintf("Keys: %u plaintext, %u encrypted, %u w/ metadata, %u total\n",
685 wss.nKeys, wss.nCKeys, wss.nKeyMeta, wss.nKeys + wss.nCKeys);
687 // nTimeFirstKey is only reliable if all keys have metadata
688 if ((wss.nKeys + wss.nCKeys) != wss.nKeyMeta)
689 pwallet->nTimeFirstKey = 1; // 0 would be considered 'no value'
691 BOOST_FOREACH(uint256 hash, wss.vWalletUpgrade)
692 WriteTx(hash, pwallet->mapWallet[hash]);
694 // Rewrite encrypted wallets of versions 0.4.0 and 0.5.0rc:
695 if (wss.fIsEncrypted && (wss.nFileVersion == 40000 || wss.nFileVersion == 50000))
696 return DB_NEED_REWRITE;
698 if (wss.nFileVersion < CLIENT_VERSION) // Update
699 WriteVersion(CLIENT_VERSION);
701 if (wss.fAnyUnordered)
702 result = ReorderTransactions(pwallet);
707 DBErrors CWalletDB::FindWalletTx(CWallet* pwallet, vector<uint256>& vTxHash, vector<CWalletTx>& vWtx)
709 pwallet->vchDefaultKey = CPubKey();
710 bool fNoncriticalErrors = false;
711 DBErrors result = DB_LOAD_OK;
714 LOCK(pwallet->cs_wallet);
716 if (Read((string)"minversion", nMinVersion))
718 if (nMinVersion > CLIENT_VERSION)
720 pwallet->LoadMinVersion(nMinVersion);
724 Dbc* pcursor = GetCursor();
727 LogPrintf("Error getting wallet database cursor\n");
734 CDataStream ssKey(SER_DISK, CLIENT_VERSION);
735 CDataStream ssValue(SER_DISK, CLIENT_VERSION);
736 int ret = ReadAtCursor(pcursor, ssKey, ssValue);
737 if (ret == DB_NOTFOUND)
741 LogPrintf("Error reading next record from wallet database\n");
747 if (strType == "tx") {
754 vTxHash.push_back(hash);
760 catch (const boost::thread_interrupted&) {
767 if (fNoncriticalErrors && result == DB_LOAD_OK)
768 result = DB_NONCRITICAL_ERROR;
773 DBErrors CWalletDB::ZapWalletTx(CWallet* pwallet, vector<CWalletTx>& vWtx)
775 // build list of wallet TXs
776 vector<uint256> vTxHash;
777 DBErrors err = FindWalletTx(pwallet, vTxHash, vWtx);
778 if (err != DB_LOAD_OK)
781 // erase each wallet TX
782 BOOST_FOREACH (uint256& hash, vTxHash) {
790 void ThreadFlushWalletDB(const string& strFile)
792 // Make this thread recognisable as the wallet flushing thread
793 RenameThread("bitcoin-wallet");
795 static bool fOneThread;
799 if (!GetBoolArg("-flushwallet", true))
802 unsigned int nLastSeen = nWalletDBUpdated;
803 unsigned int nLastFlushed = nWalletDBUpdated;
804 int64_t nLastWalletUpdate = GetTime();
809 if (nLastSeen != nWalletDBUpdated)
811 nLastSeen = nWalletDBUpdated;
812 nLastWalletUpdate = GetTime();
815 if (nLastFlushed != nWalletDBUpdated && GetTime() - nLastWalletUpdate >= 2)
817 TRY_LOCK(bitdb.cs_db,lockDb);
820 // Don't do this if any databases are in use
822 map<string, int>::iterator mi = bitdb.mapFileUseCount.begin();
823 while (mi != bitdb.mapFileUseCount.end())
825 nRefCount += (*mi).second;
831 boost::this_thread::interruption_point();
832 map<string, int>::iterator mi = bitdb.mapFileUseCount.find(strFile);
833 if (mi != bitdb.mapFileUseCount.end())
835 LogPrint("db", "Flushing wallet.dat\n");
836 nLastFlushed = nWalletDBUpdated;
837 int64_t nStart = GetTimeMillis();
839 // Flush wallet.dat so it's self contained
840 bitdb.CloseDb(strFile);
841 bitdb.CheckpointLSN(strFile);
843 bitdb.mapFileUseCount.erase(mi++);
844 LogPrint("db", "Flushed wallet.dat %dms\n", GetTimeMillis() - nStart);
852 bool BackupWallet(const CWallet& wallet, const string& strDest)
854 if (!wallet.fFileBacked)
860 if (!bitdb.mapFileUseCount.count(wallet.strWalletFile) || bitdb.mapFileUseCount[wallet.strWalletFile] == 0)
862 // Flush log data to the dat file
863 bitdb.CloseDb(wallet.strWalletFile);
864 bitdb.CheckpointLSN(wallet.strWalletFile);
865 bitdb.mapFileUseCount.erase(wallet.strWalletFile);
868 boost::filesystem::path pathSrc = GetDataDir() / wallet.strWalletFile;
869 boost::filesystem::path pathDest(strDest);
870 if (boost::filesystem::is_directory(pathDest))
871 pathDest /= wallet.strWalletFile;
874 #if BOOST_VERSION >= 104000
875 boost::filesystem::copy_file(pathSrc, pathDest, boost::filesystem::copy_option::overwrite_if_exists);
877 boost::filesystem::copy_file(pathSrc, pathDest);
879 LogPrintf("copied wallet.dat to %s\n", pathDest.string());
881 } catch (const boost::filesystem::filesystem_error& e) {
882 LogPrintf("error copying wallet.dat to %s - %s\n", pathDest.string(), e.what());
893 // Try to (very carefully!) recover wallet.dat if there is a problem.
895 bool CWalletDB::Recover(CDBEnv& dbenv, const std::string& filename, bool fOnlyKeys)
897 // Recovery procedure:
898 // move wallet.dat to wallet.timestamp.bak
899 // Call Salvage with fAggressive=true to
900 // get as much data as possible.
901 // Rewrite salvaged data to wallet.dat
902 // Set -rescan so any missing transactions will be
904 int64_t now = GetTime();
905 std::string newFilename = strprintf("wallet.%d.bak", now);
907 int result = dbenv.dbenv->dbrename(NULL, filename.c_str(), NULL,
908 newFilename.c_str(), DB_AUTO_COMMIT);
910 LogPrintf("Renamed %s to %s\n", filename, newFilename);
913 LogPrintf("Failed to rename %s to %s\n", filename, newFilename);
917 std::vector<CDBEnv::KeyValPair> salvagedData;
918 bool fSuccess = dbenv.Salvage(newFilename, true, salvagedData);
919 if (salvagedData.empty())
921 LogPrintf("Salvage(aggressive) found no records in %s.\n", newFilename);
924 LogPrintf("Salvage(aggressive) found %u records\n", salvagedData.size());
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)));