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::WriteBestBlock(const CBlockLocator& locator)
118 return Write(std::string("bestblock"), locator);
121 bool CWalletDB::ReadBestBlock(CBlockLocator& locator)
123 return Read(std::string("bestblock"), locator);
126 bool CWalletDB::WriteOrderPosNext(int64_t nOrderPosNext)
129 return Write(std::string("orderposnext"), nOrderPosNext);
132 bool CWalletDB::WriteDefaultKey(const CPubKey& vchPubKey)
135 return Write(std::string("defaultkey"), vchPubKey);
138 bool CWalletDB::ReadPool(int64_t nPool, CKeyPool& keypool)
140 return Read(std::make_pair(std::string("pool"), nPool), keypool);
143 bool CWalletDB::WritePool(int64_t nPool, const CKeyPool& keypool)
146 return Write(std::make_pair(std::string("pool"), nPool), keypool);
149 bool CWalletDB::ErasePool(int64_t nPool)
152 return Erase(std::make_pair(std::string("pool"), nPool));
155 bool CWalletDB::WriteMinVersion(int nVersion)
157 return Write(std::string("minversion"), nVersion);
160 bool CWalletDB::ReadAccount(const string& strAccount, CAccount& account)
163 return Read(make_pair(string("acc"), strAccount), account);
166 bool CWalletDB::WriteAccount(const string& strAccount, const CAccount& account)
168 return Write(make_pair(string("acc"), strAccount), account);
171 bool CWalletDB::WriteAccountingEntry(const uint64_t nAccEntryNum, const CAccountingEntry& acentry)
173 return Write(boost::make_tuple(string("acentry"), acentry.strAccount, nAccEntryNum), acentry);
176 bool CWalletDB::WriteAccountingEntry(const CAccountingEntry& acentry)
178 return WriteAccountingEntry(++nAccountingEntryNumber, acentry);
181 int64_t CWalletDB::GetAccountCreditDebit(const string& strAccount)
183 list<CAccountingEntry> entries;
184 ListAccountCreditDebit(strAccount, entries);
186 int64_t nCreditDebit = 0;
187 BOOST_FOREACH (const CAccountingEntry& entry, entries)
188 nCreditDebit += entry.nCreditDebit;
193 void CWalletDB::ListAccountCreditDebit(const string& strAccount, list<CAccountingEntry>& entries)
195 bool fAllAccounts = (strAccount == "*");
197 Dbc* pcursor = GetCursor();
199 throw runtime_error("CWalletDB::ListAccountCreditDebit() : cannot create DB cursor");
200 unsigned int fFlags = DB_SET_RANGE;
204 CDataStream ssKey(SER_DISK, CLIENT_VERSION);
205 if (fFlags == DB_SET_RANGE)
206 ssKey << boost::make_tuple(string("acentry"), (fAllAccounts? string("") : strAccount), uint64_t(0));
207 CDataStream ssValue(SER_DISK, CLIENT_VERSION);
208 int ret = ReadAtCursor(pcursor, ssKey, ssValue, fFlags);
210 if (ret == DB_NOTFOUND)
215 throw runtime_error("CWalletDB::ListAccountCreditDebit() : error scanning DB");
221 if (strType != "acentry")
223 CAccountingEntry acentry;
224 ssKey >> acentry.strAccount;
225 if (!fAllAccounts && acentry.strAccount != strAccount)
229 ssKey >> acentry.nEntryNo;
230 entries.push_back(acentry);
238 CWalletDB::ReorderTransactions(CWallet* pwallet)
240 LOCK(pwallet->cs_wallet);
241 // Old wallets didn't have any defined order for transactions
242 // Probably a bad idea to change the output of this
244 // First: get all CWalletTx and CAccountingEntry into a sorted-by-time multimap.
245 typedef pair<CWalletTx*, CAccountingEntry*> TxPair;
246 typedef multimap<int64_t, TxPair > TxItems;
249 for (map<uint256, CWalletTx>::iterator it = pwallet->mapWallet.begin(); it != pwallet->mapWallet.end(); ++it)
251 CWalletTx* wtx = &((*it).second);
252 txByTime.insert(make_pair(wtx->nTimeReceived, TxPair(wtx, (CAccountingEntry*)0)));
254 list<CAccountingEntry> acentries;
255 ListAccountCreditDebit("", acentries);
256 BOOST_FOREACH(CAccountingEntry& entry, acentries)
258 txByTime.insert(make_pair(entry.nTime, TxPair((CWalletTx*)0, &entry)));
261 int64_t& nOrderPosNext = pwallet->nOrderPosNext;
263 std::vector<int64_t> nOrderPosOffsets;
264 for (TxItems::iterator it = txByTime.begin(); it != txByTime.end(); ++it)
266 CWalletTx *const pwtx = (*it).second.first;
267 CAccountingEntry *const pacentry = (*it).second.second;
268 int64_t& nOrderPos = (pwtx != 0) ? pwtx->nOrderPos : pacentry->nOrderPos;
272 nOrderPos = nOrderPosNext++;
273 nOrderPosOffsets.push_back(nOrderPos);
276 // Have to write accounting regardless, since we don't keep it in memory
277 if (!WriteAccountingEntry(pacentry->nEntryNo, *pacentry))
282 int64_t nOrderPosOff = 0;
283 BOOST_FOREACH(const int64_t& nOffsetStart, nOrderPosOffsets)
285 if (nOrderPos >= nOffsetStart)
288 nOrderPos += nOrderPosOff;
289 nOrderPosNext = std::max(nOrderPosNext, nOrderPos + 1);
294 // Since we're changing the order, write it back
297 if (!WriteTx(pwtx->GetHash(), *pwtx))
301 if (!WriteAccountingEntry(pacentry->nEntryNo, *pacentry))
309 class CWalletScanState {
313 unsigned int nKeyMeta;
317 vector<uint256> vWalletUpgrade;
320 nKeys = nCKeys = nKeyMeta = 0;
321 fIsEncrypted = false;
322 fAnyUnordered = false;
328 ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue,
329 CWalletScanState &wss, string& strType, string& strErr)
333 // Taking advantage of the fact that pair serialization
334 // is just the two items serialized one after the other
336 if (strType == "name")
340 ssValue >> pwallet->mapAddressBook[CBitcoinAddress(strAddress).Get()].name;
342 else if (strType == "purpose")
346 ssValue >> pwallet->mapAddressBook[CBitcoinAddress(strAddress).Get()].purpose;
348 else if (strType == "tx")
354 CValidationState state;
355 if (CheckTransaction(wtx, state) && (wtx.GetHash() == hash) && state.IsValid())
356 wtx.BindWallet(pwallet);
360 // Undo serialize changes in 31600
361 if (31404 <= wtx.fTimeReceivedIsTxTime && wtx.fTimeReceivedIsTxTime <= 31703)
363 if (!ssValue.empty())
367 ssValue >> fTmp >> fUnused >> wtx.strFromAccount;
368 strErr = strprintf("LoadWallet() upgrading tx ver=%d %d '%s' %s",
369 wtx.fTimeReceivedIsTxTime, fTmp, wtx.strFromAccount, hash.ToString());
370 wtx.fTimeReceivedIsTxTime = fTmp;
374 strErr = strprintf("LoadWallet() repairing tx ver=%d %s", wtx.fTimeReceivedIsTxTime, hash.ToString());
375 wtx.fTimeReceivedIsTxTime = 0;
377 wss.vWalletUpgrade.push_back(hash);
380 if (wtx.nOrderPos == -1)
381 wss.fAnyUnordered = true;
383 pwallet->AddToWallet(wtx, true);
385 //LogPrintf("LoadWallet %s\n", wtx.GetHash().ToString());
386 //LogPrintf(" %12"PRId64" %s %s %s\n",
387 // wtx.vout[0].nValue,
388 // DateTimeStrFormat("%Y-%m-%d %H:%M:%S", wtx.GetBlockTime()),
389 // wtx.hashBlock.ToString(),
390 // wtx.mapValue["message"]);
392 else if (strType == "acentry")
398 if (nNumber > nAccountingEntryNumber)
399 nAccountingEntryNumber = nNumber;
401 if (!wss.fAnyUnordered)
403 CAccountingEntry acentry;
405 if (acentry.nOrderPos == -1)
406 wss.fAnyUnordered = true;
409 else if (strType == "key" || strType == "wkey")
413 if (!vchPubKey.IsValid())
415 strErr = "Error reading wallet database: CPubKey corrupt";
422 if (strType == "key")
429 pkey = wkey.vchPrivKey;
432 // Old wallets store keys as "key" [pubkey] => [privkey]
433 // ... which was slow for wallets with lots of keys, because the public key is re-derived from the private key
434 // using EC operations as a checksum.
435 // Newer wallets store keys as "key"[pubkey] => [privkey][hash(pubkey,privkey)], which is much faster while
436 // remaining backwards-compatible.
443 bool fSkipCheck = false;
447 // hash pubkey/privkey to accelerate wallet load
448 std::vector<unsigned char> vchKey;
449 vchKey.reserve(vchPubKey.size() + pkey.size());
450 vchKey.insert(vchKey.end(), vchPubKey.begin(), vchPubKey.end());
451 vchKey.insert(vchKey.end(), pkey.begin(), pkey.end());
453 if (Hash(vchKey.begin(), vchKey.end()) != hash)
455 strErr = "Error reading wallet database: CPubKey/CPrivKey corrupt";
462 if (!key.Load(pkey, vchPubKey, fSkipCheck))
464 strErr = "Error reading wallet database: CPrivKey corrupt";
467 if (!pwallet->LoadKey(key, vchPubKey))
469 strErr = "Error reading wallet database: LoadKey failed";
473 else if (strType == "mkey")
477 CMasterKey kMasterKey;
478 ssValue >> kMasterKey;
479 if(pwallet->mapMasterKeys.count(nID) != 0)
481 strErr = strprintf("Error reading wallet database: duplicate CMasterKey id %u", nID);
484 pwallet->mapMasterKeys[nID] = kMasterKey;
485 if (pwallet->nMasterKeyMaxID < nID)
486 pwallet->nMasterKeyMaxID = nID;
488 else if (strType == "ckey")
490 vector<unsigned char> vchPubKey;
492 vector<unsigned char> vchPrivKey;
493 ssValue >> vchPrivKey;
496 if (!pwallet->LoadCryptedKey(vchPubKey, vchPrivKey))
498 strErr = "Error reading wallet database: LoadCryptedKey failed";
501 wss.fIsEncrypted = true;
503 else if (strType == "keymeta")
507 CKeyMetadata keyMeta;
511 pwallet->LoadKeyMetadata(vchPubKey, keyMeta);
513 // find earliest key creation time, as wallet birthday
514 if (!pwallet->nTimeFirstKey ||
515 (keyMeta.nCreateTime < pwallet->nTimeFirstKey))
516 pwallet->nTimeFirstKey = keyMeta.nCreateTime;
518 else if (strType == "defaultkey")
520 ssValue >> pwallet->vchDefaultKey;
522 else if (strType == "pool")
528 pwallet->setKeyPool.insert(nIndex);
530 // If no metadata exists yet, create a default with the pool key's
531 // creation time. Note that this may be overwritten by actually
532 // stored metadata for that key later, which is fine.
533 CKeyID keyid = keypool.vchPubKey.GetID();
534 if (pwallet->mapKeyMetadata.count(keyid) == 0)
535 pwallet->mapKeyMetadata[keyid] = CKeyMetadata(keypool.nTime);
537 else if (strType == "version")
539 ssValue >> wss.nFileVersion;
540 if (wss.nFileVersion == 10300)
541 wss.nFileVersion = 300;
543 else if (strType == "cscript")
549 if (!pwallet->LoadCScript(script))
551 strErr = "Error reading wallet database: LoadCScript failed";
555 else if (strType == "orderposnext")
557 ssValue >> pwallet->nOrderPosNext;
559 else if (strType == "destdata")
561 std::string strAddress, strKey, strValue;
565 if (!pwallet->LoadDestData(CBitcoinAddress(strAddress).Get(), strKey, strValue))
567 strErr = "Error reading wallet database: LoadDestData failed";
578 static bool IsKeyType(string strType)
580 return (strType== "key" || strType == "wkey" ||
581 strType == "mkey" || strType == "ckey");
584 DBErrors CWalletDB::LoadWallet(CWallet* pwallet)
586 pwallet->vchDefaultKey = CPubKey();
587 CWalletScanState wss;
588 bool fNoncriticalErrors = false;
589 DBErrors result = DB_LOAD_OK;
592 LOCK(pwallet->cs_wallet);
594 if (Read((string)"minversion", nMinVersion))
596 if (nMinVersion > CLIENT_VERSION)
598 pwallet->LoadMinVersion(nMinVersion);
602 Dbc* pcursor = GetCursor();
605 LogPrintf("Error getting wallet database cursor\n");
612 CDataStream ssKey(SER_DISK, CLIENT_VERSION);
613 CDataStream ssValue(SER_DISK, CLIENT_VERSION);
614 int ret = ReadAtCursor(pcursor, ssKey, ssValue);
615 if (ret == DB_NOTFOUND)
619 LogPrintf("Error reading next record from wallet database\n");
623 // Try to be tolerant of single corrupt records:
624 string strType, strErr;
625 if (!ReadKeyValue(pwallet, ssKey, ssValue, wss, strType, strErr))
627 // losing keys is considered a catastrophic error, anything else
628 // we assume the user can live with:
629 if (IsKeyType(strType))
633 // Leave other errors alone, if we try to fix them we might make things worse.
634 fNoncriticalErrors = true; // ... but do warn the user there is something wrong.
636 // Rescan if there is a bad transaction record:
637 SoftSetBoolArg("-rescan", true);
641 LogPrintf("%s\n", strErr);
645 catch (boost::thread_interrupted) {
652 if (fNoncriticalErrors && result == DB_LOAD_OK)
653 result = DB_NONCRITICAL_ERROR;
655 // Any wallet corruption at all: skip any rewriting or
656 // upgrading, we don't want to make it worse.
657 if (result != DB_LOAD_OK)
660 LogPrintf("nFileVersion = %d\n", wss.nFileVersion);
662 LogPrintf("Keys: %u plaintext, %u encrypted, %u w/ metadata, %u total\n",
663 wss.nKeys, wss.nCKeys, wss.nKeyMeta, wss.nKeys + wss.nCKeys);
665 // nTimeFirstKey is only reliable if all keys have metadata
666 if ((wss.nKeys + wss.nCKeys) != wss.nKeyMeta)
667 pwallet->nTimeFirstKey = 1; // 0 would be considered 'no value'
669 BOOST_FOREACH(uint256 hash, wss.vWalletUpgrade)
670 WriteTx(hash, pwallet->mapWallet[hash]);
672 // Rewrite encrypted wallets of versions 0.4.0 and 0.5.0rc:
673 if (wss.fIsEncrypted && (wss.nFileVersion == 40000 || wss.nFileVersion == 50000))
674 return DB_NEED_REWRITE;
676 if (wss.nFileVersion < CLIENT_VERSION) // Update
677 WriteVersion(CLIENT_VERSION);
679 if (wss.fAnyUnordered)
680 result = ReorderTransactions(pwallet);
685 DBErrors CWalletDB::FindWalletTx(CWallet* pwallet, vector<uint256>& vTxHash)
687 pwallet->vchDefaultKey = CPubKey();
688 CWalletScanState wss;
689 bool fNoncriticalErrors = false;
690 DBErrors result = DB_LOAD_OK;
693 LOCK(pwallet->cs_wallet);
695 if (Read((string)"minversion", nMinVersion))
697 if (nMinVersion > CLIENT_VERSION)
699 pwallet->LoadMinVersion(nMinVersion);
703 Dbc* pcursor = GetCursor();
706 LogPrintf("Error getting wallet database cursor\n");
713 CDataStream ssKey(SER_DISK, CLIENT_VERSION);
714 CDataStream ssValue(SER_DISK, CLIENT_VERSION);
715 int ret = ReadAtCursor(pcursor, ssKey, ssValue);
716 if (ret == DB_NOTFOUND)
720 LogPrintf("Error reading next record from wallet database\n");
726 if (strType == "tx") {
730 vTxHash.push_back(hash);
735 catch (boost::thread_interrupted) {
742 if (fNoncriticalErrors && result == DB_LOAD_OK)
743 result = DB_NONCRITICAL_ERROR;
748 DBErrors CWalletDB::ZapWalletTx(CWallet* pwallet)
750 // build list of wallet TXs
751 vector<uint256> vTxHash;
752 DBErrors err = FindWalletTx(pwallet, vTxHash);
753 if (err != DB_LOAD_OK)
756 // erase each wallet TX
757 BOOST_FOREACH (uint256& hash, vTxHash) {
765 void ThreadFlushWalletDB(const string& strFile)
767 // Make this thread recognisable as the wallet flushing thread
768 RenameThread("bitcoin-wallet");
770 static bool fOneThread;
774 if (!GetBoolArg("-flushwallet", true))
777 unsigned int nLastSeen = nWalletDBUpdated;
778 unsigned int nLastFlushed = nWalletDBUpdated;
779 int64_t nLastWalletUpdate = GetTime();
784 if (nLastSeen != nWalletDBUpdated)
786 nLastSeen = nWalletDBUpdated;
787 nLastWalletUpdate = GetTime();
790 if (nLastFlushed != nWalletDBUpdated && GetTime() - nLastWalletUpdate >= 2)
792 TRY_LOCK(bitdb.cs_db,lockDb);
795 // Don't do this if any databases are in use
797 map<string, int>::iterator mi = bitdb.mapFileUseCount.begin();
798 while (mi != bitdb.mapFileUseCount.end())
800 nRefCount += (*mi).second;
806 boost::this_thread::interruption_point();
807 map<string, int>::iterator mi = bitdb.mapFileUseCount.find(strFile);
808 if (mi != bitdb.mapFileUseCount.end())
810 LogPrint("db", "Flushing wallet.dat\n");
811 nLastFlushed = nWalletDBUpdated;
812 int64_t nStart = GetTimeMillis();
814 // Flush wallet.dat so it's self contained
815 bitdb.CloseDb(strFile);
816 bitdb.CheckpointLSN(strFile);
818 bitdb.mapFileUseCount.erase(mi++);
819 LogPrint("db", "Flushed wallet.dat %"PRId64"ms\n", GetTimeMillis() - nStart);
827 bool BackupWallet(const CWallet& wallet, const string& strDest)
829 if (!wallet.fFileBacked)
835 if (!bitdb.mapFileUseCount.count(wallet.strWalletFile) || bitdb.mapFileUseCount[wallet.strWalletFile] == 0)
837 // Flush log data to the dat file
838 bitdb.CloseDb(wallet.strWalletFile);
839 bitdb.CheckpointLSN(wallet.strWalletFile);
840 bitdb.mapFileUseCount.erase(wallet.strWalletFile);
843 filesystem::path pathSrc = GetDataDir() / wallet.strWalletFile;
844 filesystem::path pathDest(strDest);
845 if (filesystem::is_directory(pathDest))
846 pathDest /= wallet.strWalletFile;
849 #if BOOST_VERSION >= 104000
850 filesystem::copy_file(pathSrc, pathDest, filesystem::copy_option::overwrite_if_exists);
852 filesystem::copy_file(pathSrc, pathDest);
854 LogPrintf("copied wallet.dat to %s\n", pathDest.string());
856 } catch(const filesystem::filesystem_error &e) {
857 LogPrintf("error copying wallet.dat to %s - %s\n", pathDest.string(), e.what());
868 // Try to (very carefully!) recover wallet.dat if there is a problem.
870 bool CWalletDB::Recover(CDBEnv& dbenv, std::string filename, bool fOnlyKeys)
872 // Recovery procedure:
873 // move wallet.dat to wallet.timestamp.bak
874 // Call Salvage with fAggressive=true to
875 // get as much data as possible.
876 // Rewrite salvaged data to wallet.dat
877 // Set -rescan so any missing transactions will be
879 int64_t now = GetTime();
880 std::string newFilename = strprintf("wallet.%"PRId64".bak", now);
882 int result = dbenv.dbenv.dbrename(NULL, filename.c_str(), NULL,
883 newFilename.c_str(), DB_AUTO_COMMIT);
885 LogPrintf("Renamed %s to %s\n", filename, newFilename);
888 LogPrintf("Failed to rename %s to %s\n", filename, newFilename);
892 std::vector<CDBEnv::KeyValPair> salvagedData;
893 bool allOK = dbenv.Salvage(newFilename, true, salvagedData);
894 if (salvagedData.empty())
896 LogPrintf("Salvage(aggressive) found no records in %s.\n", newFilename);
899 LogPrintf("Salvage(aggressive) found %"PRIszu" records\n", salvagedData.size());
901 bool fSuccess = allOK;
902 Db* pdbCopy = new Db(&dbenv.dbenv, 0);
903 int ret = pdbCopy->open(NULL, // Txn pointer
904 filename.c_str(), // Filename
905 "main", // Logical db name
906 DB_BTREE, // Database type
911 LogPrintf("Cannot create database file %s\n", filename);
915 CWalletScanState wss;
917 DbTxn* ptxn = dbenv.TxnBegin();
918 BOOST_FOREACH(CDBEnv::KeyValPair& row, salvagedData)
922 CDataStream ssKey(row.first, SER_DISK, CLIENT_VERSION);
923 CDataStream ssValue(row.second, SER_DISK, CLIENT_VERSION);
924 string strType, strErr;
925 bool fReadOK = ReadKeyValue(&dummyWallet, ssKey, ssValue,
926 wss, strType, strErr);
927 if (!IsKeyType(strType))
931 LogPrintf("WARNING: CWalletDB::Recover skipping %s: %s\n", strType, strErr);
935 Dbt datKey(&row.first[0], row.first.size());
936 Dbt datValue(&row.second[0], row.second.size());
937 int ret2 = pdbCopy->put(ptxn, &datKey, &datValue, DB_NOOVERWRITE);
948 bool CWalletDB::Recover(CDBEnv& dbenv, std::string filename)
950 return CWalletDB::Recover(dbenv, filename, false);
953 bool CWalletDB::WriteDestData(const std::string &address, const std::string &key, const std::string &value)
956 return Write(boost::make_tuple(std::string("destdata"), address, key), value);
959 bool CWalletDB::EraseDestData(const std::string &address, const std::string &key)
962 return Erase(boost::make_tuple(string("destdata"), address, key));