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"
14 #include <boost/filesystem.hpp>
15 #include <boost/foreach.hpp>
18 using namespace boost;
21 static uint64_t nAccountingEntryNumber = 0;
27 bool CWalletDB::WriteName(const string& strAddress, const string& strName)
30 return Write(make_pair(string("name"), strAddress), strName);
33 bool CWalletDB::EraseName(const string& strAddress)
35 // This should only be used for sending addresses, never for receiving addresses,
36 // receiving addresses must always have an address book entry if they're not change return.
38 return Erase(make_pair(string("name"), strAddress));
41 bool CWalletDB::WritePurpose(const string& strAddress, const string& strPurpose)
44 return Write(make_pair(string("purpose"), strAddress), strPurpose);
47 bool CWalletDB::ErasePurpose(const string& strPurpose)
50 return Erase(make_pair(string("purpose"), strPurpose));
53 bool CWalletDB::WriteTx(uint256 hash, const CWalletTx& wtx)
56 return Write(std::make_pair(std::string("tx"), hash), wtx);
59 bool CWalletDB::EraseTx(uint256 hash)
62 return Erase(std::make_pair(std::string("tx"), hash));
65 bool CWalletDB::WriteKey(const CPubKey& vchPubKey, const CPrivKey& vchPrivKey, const CKeyMetadata& keyMeta)
69 if (!Write(std::make_pair(std::string("keymeta"), vchPubKey),
73 // hash pubkey/privkey to accelerate wallet load
74 std::vector<unsigned char> vchKey;
75 vchKey.reserve(vchPubKey.size() + vchPrivKey.size());
76 vchKey.insert(vchKey.end(), vchPubKey.begin(), vchPubKey.end());
77 vchKey.insert(vchKey.end(), vchPrivKey.begin(), vchPrivKey.end());
79 return Write(std::make_pair(std::string("key"), vchPubKey), std::make_pair(vchPrivKey, Hash(vchKey.begin(), vchKey.end())), false);
82 bool CWalletDB::WriteCryptedKey(const CPubKey& vchPubKey,
83 const std::vector<unsigned char>& vchCryptedSecret,
84 const CKeyMetadata &keyMeta)
86 const bool fEraseUnencryptedKey = true;
89 if (!Write(std::make_pair(std::string("keymeta"), vchPubKey),
93 if (!Write(std::make_pair(std::string("ckey"), vchPubKey), vchCryptedSecret, false))
95 if (fEraseUnencryptedKey)
97 Erase(std::make_pair(std::string("key"), vchPubKey));
98 Erase(std::make_pair(std::string("wkey"), vchPubKey));
103 bool CWalletDB::WriteMasterKey(unsigned int nID, const CMasterKey& kMasterKey)
106 return Write(std::make_pair(std::string("mkey"), nID), kMasterKey, true);
109 bool CWalletDB::WriteCScript(const uint160& hash, const CScript& redeemScript)
112 return Write(std::make_pair(std::string("cscript"), hash), redeemScript, false);
115 bool CWalletDB::WriteWatchOnly(const CScript &dest)
118 return Write(std::make_pair(std::string("watchs"), dest), '1');
121 bool CWalletDB::WriteBestBlock(const CBlockLocator& locator)
124 return Write(std::string("bestblock"), locator);
127 bool CWalletDB::ReadBestBlock(CBlockLocator& locator)
129 return Read(std::string("bestblock"), locator);
132 bool CWalletDB::WriteOrderPosNext(int64_t nOrderPosNext)
135 return Write(std::string("orderposnext"), nOrderPosNext);
138 bool CWalletDB::WriteDefaultKey(const CPubKey& vchPubKey)
141 return Write(std::string("defaultkey"), vchPubKey);
144 bool CWalletDB::ReadPool(int64_t nPool, CKeyPool& keypool)
146 return Read(std::make_pair(std::string("pool"), nPool), keypool);
149 bool CWalletDB::WritePool(int64_t nPool, const CKeyPool& keypool)
152 return Write(std::make_pair(std::string("pool"), nPool), keypool);
155 bool CWalletDB::ErasePool(int64_t nPool)
158 return Erase(std::make_pair(std::string("pool"), nPool));
161 bool CWalletDB::WriteMinVersion(int nVersion)
163 return Write(std::string("minversion"), nVersion);
166 bool CWalletDB::ReadAccount(const string& strAccount, CAccount& account)
169 return Read(make_pair(string("acc"), strAccount), account);
172 bool CWalletDB::WriteAccount(const string& strAccount, const CAccount& account)
174 return Write(make_pair(string("acc"), strAccount), account);
177 bool CWalletDB::WriteAccountingEntry(const uint64_t nAccEntryNum, const CAccountingEntry& acentry)
179 return Write(boost::make_tuple(string("acentry"), acentry.strAccount, nAccEntryNum), acentry);
182 bool CWalletDB::WriteAccountingEntry(const CAccountingEntry& acentry)
184 return WriteAccountingEntry(++nAccountingEntryNumber, acentry);
187 int64_t CWalletDB::GetAccountCreditDebit(const string& strAccount)
189 list<CAccountingEntry> entries;
190 ListAccountCreditDebit(strAccount, entries);
192 int64_t nCreditDebit = 0;
193 BOOST_FOREACH (const CAccountingEntry& entry, entries)
194 nCreditDebit += entry.nCreditDebit;
199 void CWalletDB::ListAccountCreditDebit(const string& strAccount, list<CAccountingEntry>& entries)
201 bool fAllAccounts = (strAccount == "*");
203 Dbc* pcursor = GetCursor();
205 throw runtime_error("CWalletDB::ListAccountCreditDebit() : cannot create DB cursor");
206 unsigned int fFlags = DB_SET_RANGE;
210 CDataStream ssKey(SER_DISK, CLIENT_VERSION);
211 if (fFlags == DB_SET_RANGE)
212 ssKey << boost::make_tuple(string("acentry"), (fAllAccounts? string("") : strAccount), uint64_t(0));
213 CDataStream ssValue(SER_DISK, CLIENT_VERSION);
214 int ret = ReadAtCursor(pcursor, ssKey, ssValue, fFlags);
216 if (ret == DB_NOTFOUND)
221 throw runtime_error("CWalletDB::ListAccountCreditDebit() : error scanning DB");
227 if (strType != "acentry")
229 CAccountingEntry acentry;
230 ssKey >> acentry.strAccount;
231 if (!fAllAccounts && acentry.strAccount != strAccount)
235 ssKey >> acentry.nEntryNo;
236 entries.push_back(acentry);
244 CWalletDB::ReorderTransactions(CWallet* pwallet)
246 LOCK(pwallet->cs_wallet);
247 // Old wallets didn't have any defined order for transactions
248 // Probably a bad idea to change the output of this
250 // First: get all CWalletTx and CAccountingEntry into a sorted-by-time multimap.
251 typedef pair<CWalletTx*, CAccountingEntry*> TxPair;
252 typedef multimap<int64_t, TxPair > TxItems;
255 for (map<uint256, CWalletTx>::iterator it = pwallet->mapWallet.begin(); it != pwallet->mapWallet.end(); ++it)
257 CWalletTx* wtx = &((*it).second);
258 txByTime.insert(make_pair(wtx->nTimeReceived, TxPair(wtx, (CAccountingEntry*)0)));
260 list<CAccountingEntry> acentries;
261 ListAccountCreditDebit("", acentries);
262 BOOST_FOREACH(CAccountingEntry& entry, acentries)
264 txByTime.insert(make_pair(entry.nTime, TxPair((CWalletTx*)0, &entry)));
267 int64_t& nOrderPosNext = pwallet->nOrderPosNext;
269 std::vector<int64_t> nOrderPosOffsets;
270 for (TxItems::iterator it = txByTime.begin(); it != txByTime.end(); ++it)
272 CWalletTx *const pwtx = (*it).second.first;
273 CAccountingEntry *const pacentry = (*it).second.second;
274 int64_t& nOrderPos = (pwtx != 0) ? pwtx->nOrderPos : pacentry->nOrderPos;
278 nOrderPos = nOrderPosNext++;
279 nOrderPosOffsets.push_back(nOrderPos);
282 // Have to write accounting regardless, since we don't keep it in memory
283 if (!WriteAccountingEntry(pacentry->nEntryNo, *pacentry))
288 int64_t nOrderPosOff = 0;
289 BOOST_FOREACH(const int64_t& nOffsetStart, nOrderPosOffsets)
291 if (nOrderPos >= nOffsetStart)
294 nOrderPos += nOrderPosOff;
295 nOrderPosNext = std::max(nOrderPosNext, nOrderPos + 1);
300 // Since we're changing the order, write it back
303 if (!WriteTx(pwtx->GetHash(), *pwtx))
307 if (!WriteAccountingEntry(pacentry->nEntryNo, *pacentry))
315 class CWalletScanState {
319 unsigned int nKeyMeta;
323 vector<uint256> vWalletUpgrade;
326 nKeys = nCKeys = nKeyMeta = 0;
327 fIsEncrypted = false;
328 fAnyUnordered = false;
334 ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue,
335 CWalletScanState &wss, string& strType, string& strErr)
339 // Taking advantage of the fact that pair serialization
340 // is just the two items serialized one after the other
342 if (strType == "name")
346 ssValue >> pwallet->mapAddressBook[CBitcoinAddress(strAddress).Get()].name;
348 else if (strType == "purpose")
352 ssValue >> pwallet->mapAddressBook[CBitcoinAddress(strAddress).Get()].purpose;
354 else if (strType == "tx")
360 CValidationState state;
361 if (!(CheckTransaction(wtx, state) && (wtx.GetHash() == hash) && state.IsValid()))
364 // Undo serialize changes in 31600
365 if (31404 <= wtx.fTimeReceivedIsTxTime && wtx.fTimeReceivedIsTxTime <= 31703)
367 if (!ssValue.empty())
371 ssValue >> fTmp >> fUnused >> wtx.strFromAccount;
372 strErr = strprintf("LoadWallet() upgrading tx ver=%d %d '%s' %s",
373 wtx.fTimeReceivedIsTxTime, fTmp, wtx.strFromAccount, hash.ToString());
374 wtx.fTimeReceivedIsTxTime = fTmp;
378 strErr = strprintf("LoadWallet() repairing tx ver=%d %s", wtx.fTimeReceivedIsTxTime, hash.ToString());
379 wtx.fTimeReceivedIsTxTime = 0;
381 wss.vWalletUpgrade.push_back(hash);
384 if (wtx.nOrderPos == -1)
385 wss.fAnyUnordered = true;
387 pwallet->AddToWallet(wtx, true);
389 //LogPrintf("LoadWallet %s\n", wtx.GetHash().ToString());
390 //LogPrintf(" %12d %s %s %s\n",
391 // wtx.vout[0].nValue,
392 // DateTimeStrFormat("%Y-%m-%d %H:%M:%S", wtx.GetBlockTime()),
393 // wtx.hashBlock.ToString(),
394 // wtx.mapValue["message"]);
396 else if (strType == "acentry")
402 if (nNumber > nAccountingEntryNumber)
403 nAccountingEntryNumber = nNumber;
405 if (!wss.fAnyUnordered)
407 CAccountingEntry acentry;
409 if (acentry.nOrderPos == -1)
410 wss.fAnyUnordered = true;
413 else if (strType == "watchs")
420 pwallet->LoadWatchOnly(script);
422 // Watch-only addresses have no birthday information for now,
423 // so set the wallet birthday to the beginning of time.
424 pwallet->nTimeFirstKey = 1;
426 else if (strType == "key" || strType == "wkey")
430 if (!vchPubKey.IsValid())
432 strErr = "Error reading wallet database: CPubKey corrupt";
439 if (strType == "key")
446 pkey = wkey.vchPrivKey;
449 // Old wallets store keys as "key" [pubkey] => [privkey]
450 // ... which was slow for wallets with lots of keys, because the public key is re-derived from the private key
451 // using EC operations as a checksum.
452 // Newer wallets store keys as "key"[pubkey] => [privkey][hash(pubkey,privkey)], which is much faster while
453 // remaining backwards-compatible.
460 bool fSkipCheck = false;
464 // hash pubkey/privkey to accelerate wallet load
465 std::vector<unsigned char> vchKey;
466 vchKey.reserve(vchPubKey.size() + pkey.size());
467 vchKey.insert(vchKey.end(), vchPubKey.begin(), vchPubKey.end());
468 vchKey.insert(vchKey.end(), pkey.begin(), pkey.end());
470 if (Hash(vchKey.begin(), vchKey.end()) != hash)
472 strErr = "Error reading wallet database: CPubKey/CPrivKey corrupt";
479 if (!key.Load(pkey, vchPubKey, fSkipCheck))
481 strErr = "Error reading wallet database: CPrivKey corrupt";
484 if (!pwallet->LoadKey(key, vchPubKey))
486 strErr = "Error reading wallet database: LoadKey failed";
490 else if (strType == "mkey")
494 CMasterKey kMasterKey;
495 ssValue >> kMasterKey;
496 if(pwallet->mapMasterKeys.count(nID) != 0)
498 strErr = strprintf("Error reading wallet database: duplicate CMasterKey id %u", nID);
501 pwallet->mapMasterKeys[nID] = kMasterKey;
502 if (pwallet->nMasterKeyMaxID < nID)
503 pwallet->nMasterKeyMaxID = nID;
505 else if (strType == "ckey")
507 vector<unsigned char> vchPubKey;
509 vector<unsigned char> vchPrivKey;
510 ssValue >> vchPrivKey;
513 if (!pwallet->LoadCryptedKey(vchPubKey, vchPrivKey))
515 strErr = "Error reading wallet database: LoadCryptedKey failed";
518 wss.fIsEncrypted = true;
520 else if (strType == "keymeta")
524 CKeyMetadata keyMeta;
528 pwallet->LoadKeyMetadata(vchPubKey, keyMeta);
530 // find earliest key creation time, as wallet birthday
531 if (!pwallet->nTimeFirstKey ||
532 (keyMeta.nCreateTime < pwallet->nTimeFirstKey))
533 pwallet->nTimeFirstKey = keyMeta.nCreateTime;
535 else if (strType == "defaultkey")
537 ssValue >> pwallet->vchDefaultKey;
539 else if (strType == "pool")
545 pwallet->setKeyPool.insert(nIndex);
547 // If no metadata exists yet, create a default with the pool key's
548 // creation time. Note that this may be overwritten by actually
549 // stored metadata for that key later, which is fine.
550 CKeyID keyid = keypool.vchPubKey.GetID();
551 if (pwallet->mapKeyMetadata.count(keyid) == 0)
552 pwallet->mapKeyMetadata[keyid] = CKeyMetadata(keypool.nTime);
554 else if (strType == "version")
556 ssValue >> wss.nFileVersion;
557 if (wss.nFileVersion == 10300)
558 wss.nFileVersion = 300;
560 else if (strType == "cscript")
566 if (!pwallet->LoadCScript(script))
568 strErr = "Error reading wallet database: LoadCScript failed";
572 else if (strType == "orderposnext")
574 ssValue >> pwallet->nOrderPosNext;
576 else if (strType == "destdata")
578 std::string strAddress, strKey, strValue;
582 if (!pwallet->LoadDestData(CBitcoinAddress(strAddress).Get(), strKey, strValue))
584 strErr = "Error reading wallet database: LoadDestData failed";
595 static bool IsKeyType(string strType)
597 return (strType== "key" || strType == "wkey" ||
598 strType == "mkey" || strType == "ckey");
601 DBErrors CWalletDB::LoadWallet(CWallet* pwallet)
603 pwallet->vchDefaultKey = CPubKey();
604 CWalletScanState wss;
605 bool fNoncriticalErrors = false;
606 DBErrors result = DB_LOAD_OK;
609 LOCK(pwallet->cs_wallet);
611 if (Read((string)"minversion", nMinVersion))
613 if (nMinVersion > CLIENT_VERSION)
615 pwallet->LoadMinVersion(nMinVersion);
619 Dbc* pcursor = GetCursor();
622 LogPrintf("Error getting wallet database cursor\n");
629 CDataStream ssKey(SER_DISK, CLIENT_VERSION);
630 CDataStream ssValue(SER_DISK, CLIENT_VERSION);
631 int ret = ReadAtCursor(pcursor, ssKey, ssValue);
632 if (ret == DB_NOTFOUND)
636 LogPrintf("Error reading next record from wallet database\n");
640 // Try to be tolerant of single corrupt records:
641 string strType, strErr;
642 if (!ReadKeyValue(pwallet, ssKey, ssValue, wss, strType, strErr))
644 // losing keys is considered a catastrophic error, anything else
645 // we assume the user can live with:
646 if (IsKeyType(strType))
650 // Leave other errors alone, if we try to fix them we might make things worse.
651 fNoncriticalErrors = true; // ... but do warn the user there is something wrong.
653 // Rescan if there is a bad transaction record:
654 SoftSetBoolArg("-rescan", true);
658 LogPrintf("%s\n", strErr);
662 catch (boost::thread_interrupted) {
669 if (fNoncriticalErrors && result == DB_LOAD_OK)
670 result = DB_NONCRITICAL_ERROR;
672 // Any wallet corruption at all: skip any rewriting or
673 // upgrading, we don't want to make it worse.
674 if (result != DB_LOAD_OK)
677 LogPrintf("nFileVersion = %d\n", wss.nFileVersion);
679 LogPrintf("Keys: %u plaintext, %u encrypted, %u w/ metadata, %u total\n",
680 wss.nKeys, wss.nCKeys, wss.nKeyMeta, wss.nKeys + wss.nCKeys);
682 // nTimeFirstKey is only reliable if all keys have metadata
683 if ((wss.nKeys + wss.nCKeys) != wss.nKeyMeta)
684 pwallet->nTimeFirstKey = 1; // 0 would be considered 'no value'
686 BOOST_FOREACH(uint256 hash, wss.vWalletUpgrade)
687 WriteTx(hash, pwallet->mapWallet[hash]);
689 // Rewrite encrypted wallets of versions 0.4.0 and 0.5.0rc:
690 if (wss.fIsEncrypted && (wss.nFileVersion == 40000 || wss.nFileVersion == 50000))
691 return DB_NEED_REWRITE;
693 if (wss.nFileVersion < CLIENT_VERSION) // Update
694 WriteVersion(CLIENT_VERSION);
696 if (wss.fAnyUnordered)
697 result = ReorderTransactions(pwallet);
702 DBErrors CWalletDB::FindWalletTx(CWallet* pwallet, vector<uint256>& vTxHash, vector<CWalletTx>& vWtx)
704 pwallet->vchDefaultKey = CPubKey();
705 CWalletScanState wss;
706 bool fNoncriticalErrors = false;
707 DBErrors result = DB_LOAD_OK;
710 LOCK(pwallet->cs_wallet);
712 if (Read((string)"minversion", nMinVersion))
714 if (nMinVersion > CLIENT_VERSION)
716 pwallet->LoadMinVersion(nMinVersion);
720 Dbc* pcursor = GetCursor();
723 LogPrintf("Error getting wallet database cursor\n");
730 CDataStream ssKey(SER_DISK, CLIENT_VERSION);
731 CDataStream ssValue(SER_DISK, CLIENT_VERSION);
732 int ret = ReadAtCursor(pcursor, ssKey, ssValue);
733 if (ret == DB_NOTFOUND)
737 LogPrintf("Error reading next record from wallet database\n");
743 if (strType == "tx") {
750 vTxHash.push_back(hash);
756 catch (boost::thread_interrupted) {
763 if (fNoncriticalErrors && result == DB_LOAD_OK)
764 result = DB_NONCRITICAL_ERROR;
769 DBErrors CWalletDB::ZapWalletTx(CWallet* pwallet, vector<CWalletTx>& vWtx)
771 // build list of wallet TXs
772 vector<uint256> vTxHash;
773 DBErrors err = FindWalletTx(pwallet, vTxHash, vWtx);
774 if (err != DB_LOAD_OK)
777 // erase each wallet TX
778 BOOST_FOREACH (uint256& hash, vTxHash) {
786 void ThreadFlushWalletDB(const string& strFile)
788 // Make this thread recognisable as the wallet flushing thread
789 RenameThread("bitcoin-wallet");
791 static bool fOneThread;
795 if (!GetBoolArg("-flushwallet", true))
798 unsigned int nLastSeen = nWalletDBUpdated;
799 unsigned int nLastFlushed = nWalletDBUpdated;
800 int64_t nLastWalletUpdate = GetTime();
805 if (nLastSeen != nWalletDBUpdated)
807 nLastSeen = nWalletDBUpdated;
808 nLastWalletUpdate = GetTime();
811 if (nLastFlushed != nWalletDBUpdated && GetTime() - nLastWalletUpdate >= 2)
813 TRY_LOCK(bitdb.cs_db,lockDb);
816 // Don't do this if any databases are in use
818 map<string, int>::iterator mi = bitdb.mapFileUseCount.begin();
819 while (mi != bitdb.mapFileUseCount.end())
821 nRefCount += (*mi).second;
827 boost::this_thread::interruption_point();
828 map<string, int>::iterator mi = bitdb.mapFileUseCount.find(strFile);
829 if (mi != bitdb.mapFileUseCount.end())
831 LogPrint("db", "Flushing wallet.dat\n");
832 nLastFlushed = nWalletDBUpdated;
833 int64_t nStart = GetTimeMillis();
835 // Flush wallet.dat so it's self contained
836 bitdb.CloseDb(strFile);
837 bitdb.CheckpointLSN(strFile);
839 bitdb.mapFileUseCount.erase(mi++);
840 LogPrint("db", "Flushed wallet.dat %dms\n", GetTimeMillis() - nStart);
848 bool BackupWallet(const CWallet& wallet, const string& strDest)
850 if (!wallet.fFileBacked)
856 if (!bitdb.mapFileUseCount.count(wallet.strWalletFile) || bitdb.mapFileUseCount[wallet.strWalletFile] == 0)
858 // Flush log data to the dat file
859 bitdb.CloseDb(wallet.strWalletFile);
860 bitdb.CheckpointLSN(wallet.strWalletFile);
861 bitdb.mapFileUseCount.erase(wallet.strWalletFile);
864 filesystem::path pathSrc = GetDataDir() / wallet.strWalletFile;
865 filesystem::path pathDest(strDest);
866 if (filesystem::is_directory(pathDest))
867 pathDest /= wallet.strWalletFile;
870 #if BOOST_VERSION >= 104000
871 filesystem::copy_file(pathSrc, pathDest, filesystem::copy_option::overwrite_if_exists);
873 filesystem::copy_file(pathSrc, pathDest);
875 LogPrintf("copied wallet.dat to %s\n", pathDest.string());
877 } catch(const filesystem::filesystem_error &e) {
878 LogPrintf("error copying wallet.dat to %s - %s\n", pathDest.string(), e.what());
889 // Try to (very carefully!) recover wallet.dat if there is a problem.
891 bool CWalletDB::Recover(CDBEnv& dbenv, std::string filename, bool fOnlyKeys)
893 // Recovery procedure:
894 // move wallet.dat to wallet.timestamp.bak
895 // Call Salvage with fAggressive=true to
896 // get as much data as possible.
897 // Rewrite salvaged data to wallet.dat
898 // Set -rescan so any missing transactions will be
900 int64_t now = GetTime();
901 std::string newFilename = strprintf("wallet.%d.bak", now);
903 int result = dbenv.dbenv.dbrename(NULL, filename.c_str(), NULL,
904 newFilename.c_str(), DB_AUTO_COMMIT);
906 LogPrintf("Renamed %s to %s\n", filename, newFilename);
909 LogPrintf("Failed to rename %s to %s\n", filename, newFilename);
913 std::vector<CDBEnv::KeyValPair> salvagedData;
914 bool allOK = dbenv.Salvage(newFilename, true, salvagedData);
915 if (salvagedData.empty())
917 LogPrintf("Salvage(aggressive) found no records in %s.\n", newFilename);
920 LogPrintf("Salvage(aggressive) found %u records\n", salvagedData.size());
922 bool fSuccess = allOK;
923 Db* pdbCopy = new Db(&dbenv.dbenv, 0);
924 int ret = pdbCopy->open(NULL, // Txn pointer
925 filename.c_str(), // Filename
926 "main", // Logical db name
927 DB_BTREE, // Database type
932 LogPrintf("Cannot create database file %s\n", filename);
936 CWalletScanState wss;
938 DbTxn* ptxn = dbenv.TxnBegin();
939 BOOST_FOREACH(CDBEnv::KeyValPair& row, salvagedData)
943 CDataStream ssKey(row.first, SER_DISK, CLIENT_VERSION);
944 CDataStream ssValue(row.second, SER_DISK, CLIENT_VERSION);
945 string strType, strErr;
946 bool fReadOK = ReadKeyValue(&dummyWallet, ssKey, ssValue,
947 wss, strType, strErr);
948 if (!IsKeyType(strType))
952 LogPrintf("WARNING: CWalletDB::Recover skipping %s: %s\n", strType, strErr);
956 Dbt datKey(&row.first[0], row.first.size());
957 Dbt datValue(&row.second[0], row.second.size());
958 int ret2 = pdbCopy->put(ptxn, &datKey, &datValue, DB_NOOVERWRITE);
969 bool CWalletDB::Recover(CDBEnv& dbenv, std::string filename)
971 return CWalletDB::Recover(dbenv, filename, false);
974 bool CWalletDB::WriteDestData(const std::string &address, const std::string &key, const std::string &value)
977 return Write(boost::make_tuple(std::string("destdata"), address, key), value);
980 bool CWalletDB::EraseDestData(const std::string &address, const std::string &key)
983 return Erase(boost::make_tuple(string("destdata"), address, key));