1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2011 The Bitcoin developers
3 // Distributed under the MIT/X11 software license, see the accompanying
4 // file license.txt or http://www.opensource.org/licenses/mit-license.php.
9 #include <boost/filesystem.hpp>
10 #include <boost/filesystem/fstream.hpp>
13 using namespace boost;
16 unsigned int nWalletDBUpdated;
17 uint64 nAccountingEntryNumber = 0;
25 static CCriticalSection cs_db;
26 static bool fDbEnvInit = false;
28 static map<string, int> mapFileUseCount;
29 static map<string, Db*> mapDb;
49 CDB::CDB(const char* pszFile, const char* pszMode) : pdb(NULL)
55 fReadOnly = (!strchr(pszMode, '+') && !strchr(pszMode, 'w'));
56 bool fCreate = strchr(pszMode, 'c');
57 unsigned int nFlags = DB_THREAD;
67 string strDataDir = GetDataDir();
68 string strLogDir = strDataDir + "/database";
69 filesystem::create_directory(strLogDir.c_str());
70 string strErrorFile = strDataDir + "/db.log";
71 printf("dbenv.open strLogDir=%s strErrorFile=%s\n", strLogDir.c_str(), strErrorFile.c_str());
73 dbenv.set_lg_dir(strLogDir.c_str());
74 dbenv.set_lg_max(10000000);
75 dbenv.set_lk_max_locks(10000);
76 dbenv.set_lk_max_objects(10000);
77 dbenv.set_errfile(fopen(strErrorFile.c_str(), "a")); /// debug
78 dbenv.set_flags(DB_AUTO_COMMIT, 1);
79 ret = dbenv.open(strDataDir.c_str(),
89 throw runtime_error(strprintf("CDB() : error %d opening database environment", ret));
94 ++mapFileUseCount[strFile];
98 pdb = new Db(&dbenv, 0);
100 ret = pdb->open(NULL, // Txn pointer
102 "main", // Logical db name
103 DB_BTREE, // Database type
111 CRITICAL_BLOCK(cs_db)
112 --mapFileUseCount[strFile];
114 throw runtime_error(strprintf("CDB() : can't open database file %s, error %d", pszFile, ret));
117 if (fCreate && !Exists(string("version")))
119 bool fTmp = fReadOnly;
121 WriteVersion(VERSION);
125 mapDb[strFile] = pdb;
135 vTxn.front()->abort();
139 // Flush database activity from memory pool to disk log
140 unsigned int nMinutes = 0;
143 if (strFile == "addr.dat")
145 if (strFile == "blkindex.dat" && IsInitialBlockDownload() && nBestHeight % 500 != 0)
147 dbenv.txn_checkpoint(0, nMinutes, 0);
149 CRITICAL_BLOCK(cs_db)
150 --mapFileUseCount[strFile];
153 void static CloseDb(const string& strFile)
155 CRITICAL_BLOCK(cs_db)
157 if (mapDb[strFile] != NULL)
159 // Close the database handle
160 Db* pdb = mapDb[strFile];
163 mapDb[strFile] = NULL;
168 bool Resilver(const string& strFile)
172 CRITICAL_BLOCK(cs_db)
174 if (!mapFileUseCount.count(strFile) || mapFileUseCount[strFile] == 0)
176 // Flush log data to the dat file
178 dbenv.txn_checkpoint(0, 0, 0);
179 dbenv.lsn_reset(strFile.c_str(), 0);
180 mapFileUseCount.erase(strFile);
182 bool fSuccess = true;
183 printf("Resilvering %s...\n", strFile.c_str());
184 string strFileRes = strFile + ".resilver";
185 CDB db(strFile.c_str(), "r");
186 Db* pdbCopy = new Db(&dbenv, 0);
188 int ret = pdbCopy->open(NULL, // Txn pointer
189 strFileRes.c_str(), // Filename
190 "main", // Logical db name
191 DB_BTREE, // Database type
196 printf("Cannot create database file %s\n", strFileRes.c_str());
200 Dbc* pcursor = db.GetCursor();
206 int ret = db.ReadAtCursor(pcursor, ssKey, ssValue, DB_NEXT);
207 if (ret == DB_NOTFOUND)
215 Dbt datKey(&ssKey[0], ssKey.size());
216 Dbt datValue(&ssValue[0], ssValue.size());
217 int ret2 = pdbCopy->put(NULL, &datKey, &datValue, DB_NOOVERWRITE);
223 Db* pdb = mapDb[strFile];
226 if (pdbCopy->close(0))
230 mapDb[strFile] = NULL;
235 if (dbA.remove(strFile.c_str(), NULL, 0))
238 if (dbB.rename(strFileRes.c_str(), NULL, strFile.c_str(), 0))
242 printf("Resilvering of %s FAILED!\n", strFileRes.c_str());
252 void DBFlush(bool fShutdown)
254 // Flush log data to the actual data file
255 // on all files that are not in use
256 printf("DBFlush(%s)%s\n", fShutdown ? "true" : "false", fDbEnvInit ? "" : " db not started");
259 CRITICAL_BLOCK(cs_db)
261 map<string, int>::iterator mi = mapFileUseCount.begin();
262 while (mi != mapFileUseCount.end())
264 string strFile = (*mi).first;
265 int nRefCount = (*mi).second;
266 printf("%s refcount=%d\n", strFile.c_str(), nRefCount);
269 // Move log data to the dat file
271 dbenv.txn_checkpoint(0, 0, 0);
272 printf("%s flush\n", strFile.c_str());
273 dbenv.lsn_reset(strFile.c_str(), 0);
274 mapFileUseCount.erase(mi++);
282 if (mapFileUseCount.empty())
283 dbenv.log_archive(&listp, DB_ARCH_REMOVE);
299 bool CTxDB::ReadTxIndex(uint256 hash, CTxIndex& txindex)
303 return Read(make_pair(string("tx"), hash), txindex);
306 bool CTxDB::UpdateTxIndex(uint256 hash, const CTxIndex& txindex)
309 return Write(make_pair(string("tx"), hash), txindex);
312 bool CTxDB::AddTxIndex(const CTransaction& tx, const CDiskTxPos& pos, int nHeight)
317 uint256 hash = tx.GetHash();
318 CTxIndex txindex(pos, tx.vout.size());
319 return Write(make_pair(string("tx"), hash), txindex);
322 bool CTxDB::EraseTxIndex(const CTransaction& tx)
325 uint256 hash = tx.GetHash();
327 return Erase(make_pair(string("tx"), hash));
330 bool CTxDB::ContainsTx(uint256 hash)
333 return Exists(make_pair(string("tx"), hash));
336 bool CTxDB::ReadOwnerTxes(uint160 hash160, int nMinHeight, vector<CTransaction>& vtx)
342 Dbc* pcursor = GetCursor();
346 unsigned int fFlags = DB_SET_RANGE;
351 if (fFlags == DB_SET_RANGE)
352 ssKey << string("owner") << hash160 << CDiskTxPos(0, 0, 0);
354 int ret = ReadAtCursor(pcursor, ssKey, ssValue, fFlags);
356 if (ret == DB_NOTFOUND)
368 ssKey >> strType >> hashItem >> pos;
370 ssValue >> nItemHeight;
373 if (strType != "owner" || hashItem != hash160)
375 if (nItemHeight >= nMinHeight)
377 vtx.resize(vtx.size()+1);
378 if (!vtx.back().ReadFromDisk(pos))
390 bool CTxDB::ReadDiskTx(uint256 hash, CTransaction& tx, CTxIndex& txindex)
394 if (!ReadTxIndex(hash, txindex))
396 return (tx.ReadFromDisk(txindex.pos));
399 bool CTxDB::ReadDiskTx(uint256 hash, CTransaction& tx)
402 return ReadDiskTx(hash, tx, txindex);
405 bool CTxDB::ReadDiskTx(COutPoint outpoint, CTransaction& tx, CTxIndex& txindex)
407 return ReadDiskTx(outpoint.hash, tx, txindex);
410 bool CTxDB::ReadDiskTx(COutPoint outpoint, CTransaction& tx)
413 return ReadDiskTx(outpoint.hash, tx, txindex);
416 bool CTxDB::WriteBlockIndex(const CDiskBlockIndex& blockindex)
418 return Write(make_pair(string("blockindex"), blockindex.GetBlockHash()), blockindex);
421 bool CTxDB::EraseBlockIndex(uint256 hash)
423 return Erase(make_pair(string("blockindex"), hash));
426 bool CTxDB::ReadHashBestChain(uint256& hashBestChain)
428 return Read(string("hashBestChain"), hashBestChain);
431 bool CTxDB::WriteHashBestChain(uint256 hashBestChain)
433 return Write(string("hashBestChain"), hashBestChain);
436 bool CTxDB::ReadBestInvalidWork(CBigNum& bnBestInvalidWork)
438 return Read(string("bnBestInvalidWork"), bnBestInvalidWork);
441 bool CTxDB::WriteBestInvalidWork(CBigNum bnBestInvalidWork)
443 return Write(string("bnBestInvalidWork"), bnBestInvalidWork);
446 CBlockIndex static * InsertBlockIndex(uint256 hash)
452 map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.find(hash);
453 if (mi != mapBlockIndex.end())
457 CBlockIndex* pindexNew = new CBlockIndex();
459 throw runtime_error("LoadBlockIndex() : new CBlockIndex failed");
460 mi = mapBlockIndex.insert(make_pair(hash, pindexNew)).first;
461 pindexNew->phashBlock = &((*mi).first);
466 bool CTxDB::LoadBlockIndex()
468 // Get database cursor
469 Dbc* pcursor = GetCursor();
473 // Load mapBlockIndex
474 unsigned int fFlags = DB_SET_RANGE;
479 if (fFlags == DB_SET_RANGE)
480 ssKey << make_pair(string("blockindex"), uint256(0));
482 int ret = ReadAtCursor(pcursor, ssKey, ssValue, fFlags);
484 if (ret == DB_NOTFOUND)
492 if (strType == "blockindex")
494 CDiskBlockIndex diskindex;
495 ssValue >> diskindex;
497 // Construct block index object
498 CBlockIndex* pindexNew = InsertBlockIndex(diskindex.GetBlockHash());
499 pindexNew->pprev = InsertBlockIndex(diskindex.hashPrev);
500 pindexNew->pnext = InsertBlockIndex(diskindex.hashNext);
501 pindexNew->nFile = diskindex.nFile;
502 pindexNew->nBlockPos = diskindex.nBlockPos;
503 pindexNew->nHeight = diskindex.nHeight;
504 pindexNew->nVersion = diskindex.nVersion;
505 pindexNew->hashMerkleRoot = diskindex.hashMerkleRoot;
506 pindexNew->nTime = diskindex.nTime;
507 pindexNew->nBits = diskindex.nBits;
508 pindexNew->nNonce = diskindex.nNonce;
510 // Watch for genesis block
511 if (pindexGenesisBlock == NULL && diskindex.GetBlockHash() == hashGenesisBlock)
512 pindexGenesisBlock = pindexNew;
514 if (!pindexNew->CheckIndex())
515 return error("LoadBlockIndex() : CheckIndex failed at %d", pindexNew->nHeight);
524 // Calculate bnChainWork
525 vector<pair<int, CBlockIndex*> > vSortedByHeight;
526 vSortedByHeight.reserve(mapBlockIndex.size());
527 BOOST_FOREACH(const PAIRTYPE(uint256, CBlockIndex*)& item, mapBlockIndex)
529 CBlockIndex* pindex = item.second;
530 vSortedByHeight.push_back(make_pair(pindex->nHeight, pindex));
532 sort(vSortedByHeight.begin(), vSortedByHeight.end());
533 BOOST_FOREACH(const PAIRTYPE(int, CBlockIndex*)& item, vSortedByHeight)
535 CBlockIndex* pindex = item.second;
536 pindex->bnChainWork = (pindex->pprev ? pindex->pprev->bnChainWork : 0) + pindex->GetBlockWork();
539 // Load hashBestChain pointer to end of best chain
540 if (!ReadHashBestChain(hashBestChain))
542 if (pindexGenesisBlock == NULL)
544 return error("CTxDB::LoadBlockIndex() : hashBestChain not loaded");
546 if (!mapBlockIndex.count(hashBestChain))
547 return error("CTxDB::LoadBlockIndex() : hashBestChain not found in the block index");
548 pindexBest = mapBlockIndex[hashBestChain];
549 nBestHeight = pindexBest->nHeight;
550 bnBestChainWork = pindexBest->bnChainWork;
551 printf("LoadBlockIndex(): hashBestChain=%s height=%d\n", hashBestChain.ToString().substr(0,20).c_str(), nBestHeight);
553 // Load bnBestInvalidWork, OK if it doesn't exist
554 ReadBestInvalidWork(bnBestInvalidWork);
556 // Verify blocks in the best chain
557 CBlockIndex* pindexFork = NULL;
558 for (CBlockIndex* pindex = pindexBest; pindex && pindex->pprev; pindex = pindex->pprev)
560 if (pindex->nHeight < nBestHeight-2500 && !mapArgs.count("-checkblocks"))
563 if (!block.ReadFromDisk(pindex))
564 return error("LoadBlockIndex() : block.ReadFromDisk failed");
565 if (!block.CheckBlock())
567 printf("LoadBlockIndex() : *** found bad block at %d, hash=%s\n", pindex->nHeight, pindex->GetBlockHash().ToString().c_str());
568 pindexFork = pindex->pprev;
573 // Reorg back to the fork
574 printf("LoadBlockIndex() : *** moving best chain pointer back to block %d\n", pindexFork->nHeight);
576 if (!block.ReadFromDisk(pindexFork))
577 return error("LoadBlockIndex() : block.ReadFromDisk failed");
579 block.SetBestChain(txdb, pindexFork);
593 bool CAddrDB::WriteAddress(const CAddress& addr)
595 return Write(make_pair(string("addr"), addr.GetKey()), addr);
598 bool CAddrDB::EraseAddress(const CAddress& addr)
600 return Erase(make_pair(string("addr"), addr.GetKey()));
603 bool CAddrDB::LoadAddresses()
605 CRITICAL_BLOCK(cs_mapAddresses)
607 // Load user provided addresses
608 CAutoFile filein = fopen((GetDataDir() + "/addr.txt").c_str(), "rt");
614 while (fgets(psz, sizeof(psz), filein))
616 CAddress addr(psz, false, NODE_NETWORK);
617 addr.nTime = 0; // so it won't relay unless successfully connected
626 Dbc* pcursor = GetCursor();
635 int ret = ReadAtCursor(pcursor, ssKey, ssValue);
636 if (ret == DB_NOTFOUND)
644 if (strType == "addr")
648 mapAddresses.insert(make_pair(addr.GetKey(), addr));
653 printf("Loaded %d addresses\n", mapAddresses.size());
661 return CAddrDB("cr+").LoadAddresses();
671 bool CWalletDB::WriteName(const string& strAddress, const string& strName)
674 return Write(make_pair(string("name"), strAddress), strName);
677 bool CWalletDB::EraseName(const string& strAddress)
679 // This should only be used for sending addresses, never for receiving addresses,
680 // receiving addresses must always have an address book entry if they're not change return.
682 return Erase(make_pair(string("name"), strAddress));
685 bool CWalletDB::ReadAccount(const string& strAccount, CAccount& account)
688 return Read(make_pair(string("acc"), strAccount), account);
691 bool CWalletDB::WriteAccount(const string& strAccount, const CAccount& account)
693 return Write(make_pair(string("acc"), strAccount), account);
696 bool CWalletDB::WriteAccountingEntry(const CAccountingEntry& acentry)
698 return Write(boost::make_tuple(string("acentry"), acentry.strAccount, ++nAccountingEntryNumber), acentry);
701 int64 CWalletDB::GetAccountCreditDebit(const string& strAccount)
703 list<CAccountingEntry> entries;
704 ListAccountCreditDebit(strAccount, entries);
706 int64 nCreditDebit = 0;
707 BOOST_FOREACH (const CAccountingEntry& entry, entries)
708 nCreditDebit += entry.nCreditDebit;
713 void CWalletDB::ListAccountCreditDebit(const string& strAccount, list<CAccountingEntry>& entries)
715 bool fAllAccounts = (strAccount == "*");
717 Dbc* pcursor = GetCursor();
719 throw runtime_error("CWalletDB::ListAccountCreditDebit() : cannot create DB cursor");
720 unsigned int fFlags = DB_SET_RANGE;
725 if (fFlags == DB_SET_RANGE)
726 ssKey << boost::make_tuple(string("acentry"), (fAllAccounts? string("") : strAccount), uint64(0));
728 int ret = ReadAtCursor(pcursor, ssKey, ssValue, fFlags);
730 if (ret == DB_NOTFOUND)
735 throw runtime_error("CWalletDB::ListAccountCreditDebit() : error scanning DB");
741 if (strType != "acentry")
743 CAccountingEntry acentry;
744 ssKey >> acentry.strAccount;
745 if (!fAllAccounts && acentry.strAccount != strAccount)
749 entries.push_back(acentry);
756 int CWalletDB::LoadWallet(CWallet* pwallet)
758 pwallet->vchDefaultKey.clear();
759 int nFileVersion = 0;
760 vector<uint256> vWalletUpgrade;
761 bool fIsResilvered = false;
762 bool fIsEncrypted = false;
766 // Tray icon sometimes disappears on 9.10 karmic koala 64-bit, leaving no way to access the program
767 fMinimizeToTray = false;
768 fMinimizeOnClose = false;
771 //// todo: shouldn't we catch exceptions and try to recover and continue?
772 CRITICAL_BLOCK(pwallet->cs_wallet)
775 Dbc* pcursor = GetCursor();
784 int ret = ReadAtCursor(pcursor, ssKey, ssValue);
785 if (ret == DB_NOTFOUND)
791 // Taking advantage of the fact that pair serialization
792 // is just the two items serialized one after the other
795 if (strType == "name")
799 ssValue >> pwallet->mapAddressBook[strAddress];
801 else if (strType == "tx")
805 CWalletTx& wtx = pwallet->mapWallet[hash];
807 wtx.pwallet = pwallet;
809 if (wtx.GetHash() != hash)
810 printf("Error in wallet.dat, hash mismatch\n");
812 // Undo serialize changes in 31600
813 if (31404 <= wtx.fTimeReceivedIsTxTime && wtx.fTimeReceivedIsTxTime <= 31703)
815 if (!ssValue.empty())
819 ssValue >> fTmp >> fUnused >> wtx.strFromAccount;
820 printf("LoadWallet() upgrading tx ver=%d %d '%s' %s\n", wtx.fTimeReceivedIsTxTime, fTmp, wtx.strFromAccount.c_str(), hash.ToString().c_str());
821 wtx.fTimeReceivedIsTxTime = fTmp;
825 printf("LoadWallet() repairing tx ver=%d %s\n", wtx.fTimeReceivedIsTxTime, hash.ToString().c_str());
826 wtx.fTimeReceivedIsTxTime = 0;
828 vWalletUpgrade.push_back(hash);
832 //printf("LoadWallet %s\n", wtx.GetHash().ToString().c_str());
833 //printf(" %12I64d %s %s %s\n",
834 // wtx.vout[0].nValue,
835 // DateTimeStrFormat("%x %H:%M:%S", wtx.GetBlockTime()).c_str(),
836 // wtx.hashBlock.ToString().substr(0,20).c_str(),
837 // wtx.mapValue["message"].c_str());
839 else if (strType == "acentry")
845 if (nNumber > nAccountingEntryNumber)
846 nAccountingEntryNumber = nNumber;
848 else if (strType == "key" || strType == "wkey")
850 vector<unsigned char> vchPubKey;
853 if (strType == "key")
857 key.SetPrivKey(pkey);
863 key.SetPrivKey(wkey.vchPrivKey);
865 if (!pwallet->LoadKey(key))
868 else if (strType == "mkey")
872 CMasterKey kMasterKey;
873 ssValue >> kMasterKey;
874 if(pwallet->mapMasterKeys.count(nID) != 0)
876 pwallet->mapMasterKeys[nID] = kMasterKey;
877 if (pwallet->nMasterKeyMaxID < nID)
878 pwallet->nMasterKeyMaxID = nID;
880 else if (strType == "ckey")
882 vector<unsigned char> vchPubKey;
884 vector<unsigned char> vchPrivKey;
885 ssValue >> vchPrivKey;
886 if (!pwallet->LoadCryptedKey(vchPubKey, vchPrivKey))
890 else if (strType == "defaultkey")
892 ssValue >> pwallet->vchDefaultKey;
894 else if (strType == "pool")
898 pwallet->setKeyPool.insert(nIndex);
900 else if (strType == "version")
902 ssValue >> nFileVersion;
903 if (nFileVersion == 10300)
906 else if (strType == "setting")
913 if (strKey == "fGenerateBitcoins") ssValue >> fGenerateBitcoins;
915 if (strKey == "nTransactionFee") ssValue >> nTransactionFee;
916 if (strKey == "fLimitProcessors") ssValue >> fLimitProcessors;
917 if (strKey == "nLimitProcessors") ssValue >> nLimitProcessors;
918 if (strKey == "fMinimizeToTray") ssValue >> fMinimizeToTray;
919 if (strKey == "fMinimizeOnClose") ssValue >> fMinimizeOnClose;
920 if (strKey == "fUseProxy") ssValue >> fUseProxy;
921 if (strKey == "addrProxy") ssValue >> addrProxy;
922 if (strKey == "fIsResilvered") ssValue >> fIsResilvered;
923 if (fHaveUPnP && strKey == "fUseUPnP") ssValue >> fUseUPnP;
925 else if (strType == "minversion")
928 ssValue >> nMinVersion;
929 if (nMinVersion > VERSION)
936 BOOST_FOREACH(uint256 hash, vWalletUpgrade)
937 WriteTx(hash, pwallet->mapWallet[hash]);
939 printf("nFileVersion = %d\n", nFileVersion);
940 printf("fGenerateBitcoins = %d\n", fGenerateBitcoins);
941 printf("nTransactionFee = %"PRI64d"\n", nTransactionFee);
942 printf("fMinimizeToTray = %d\n", fMinimizeToTray);
943 printf("fMinimizeOnClose = %d\n", fMinimizeOnClose);
944 printf("fUseProxy = %d\n", fUseProxy);
945 printf("addrProxy = %s\n", addrProxy.ToString().c_str());
947 printf("fUseUPnP = %d\n", fUseUPnP);
951 if (nFileVersion < VERSION)
953 // Get rid of old debug.log file in current directory
954 if (nFileVersion <= 105 && !pszSetDataDir[0])
957 WriteVersion(VERSION);
960 if (fIsEncrypted && !fIsResilvered)
961 return DB_NEED_RESILVER;
966 void ThreadFlushWalletDB(void* parg)
968 const string& strFile = ((const string*)parg)[0];
969 static bool fOneThread;
973 if (mapArgs.count("-noflushwallet"))
976 unsigned int nLastSeen = nWalletDBUpdated;
977 unsigned int nLastFlushed = nWalletDBUpdated;
978 int64 nLastWalletUpdate = GetTime();
983 if (nLastSeen != nWalletDBUpdated)
985 nLastSeen = nWalletDBUpdated;
986 nLastWalletUpdate = GetTime();
989 if (nLastFlushed != nWalletDBUpdated && GetTime() - nLastWalletUpdate >= 2)
991 TRY_CRITICAL_BLOCK(cs_db)
993 // Don't do this if any databases are in use
995 map<string, int>::iterator mi = mapFileUseCount.begin();
996 while (mi != mapFileUseCount.end())
998 nRefCount += (*mi).second;
1002 if (nRefCount == 0 && !fShutdown)
1004 map<string, int>::iterator mi = mapFileUseCount.find(strFile);
1005 if (mi != mapFileUseCount.end())
1007 printf("%s ", DateTimeStrFormat("%x %H:%M:%S", GetTime()).c_str());
1008 printf("Flushing wallet.dat\n");
1009 nLastFlushed = nWalletDBUpdated;
1010 int64 nStart = GetTimeMillis();
1012 // Flush wallet.dat so it's self contained
1014 dbenv.txn_checkpoint(0, 0, 0);
1015 dbenv.lsn_reset(strFile.c_str(), 0);
1017 mapFileUseCount.erase(mi++);
1018 printf("Flushed wallet.dat %"PRI64d"ms\n", GetTimeMillis() - nStart);
1026 bool BackupWallet(const CWallet& wallet, const string& strDest)
1028 if (!wallet.fFileBacked)
1032 CRITICAL_BLOCK(cs_db)
1034 if (!mapFileUseCount.count(wallet.strWalletFile) || mapFileUseCount[wallet.strWalletFile] == 0)
1036 // Flush log data to the dat file
1037 CloseDb(wallet.strWalletFile);
1038 dbenv.txn_checkpoint(0, 0, 0);
1039 dbenv.lsn_reset(wallet.strWalletFile.c_str(), 0);
1040 mapFileUseCount.erase(wallet.strWalletFile);
1043 filesystem::path pathSrc(GetDataDir() + "/" + wallet.strWalletFile);
1044 filesystem::path pathDest(strDest);
1045 if (filesystem::is_directory(pathDest))
1046 pathDest = pathDest / wallet.strWalletFile;
1047 #if BOOST_VERSION >= 104000
1048 filesystem::copy_file(pathSrc, pathDest, filesystem::copy_option::overwrite_if_exists);
1050 filesystem::copy_file(pathSrc, pathDest);
1052 printf("copied wallet.dat to %s\n", pathDest.string().c_str());