1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2012 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/version.hpp>
10 #include <boost/filesystem.hpp>
11 #include <boost/filesystem/fstream.hpp>
14 using namespace boost;
17 unsigned int nWalletDBUpdated;
18 uint64 nAccountingEntryNumber = 0;
26 static CCriticalSection cs_db;
27 static bool fDbEnvInit = false;
29 static map<string, int> mapFileUseCount;
30 static map<string, Db*> mapDb;
32 static void EnvShutdown()
42 catch (const DbException& e)
44 printf("EnvShutdown exception: %s (%d)\n", e.what(), e.get_errno());
46 DbEnv(0).remove(GetDataDir().c_str(), 0);
63 CDB::CDB(const char* pszFile, const char* pszMode) : pdb(NULL)
69 fReadOnly = (!strchr(pszMode, '+') && !strchr(pszMode, 'w'));
70 bool fCreate = strchr(pszMode, 'c');
71 unsigned int nFlags = DB_THREAD;
81 string strDataDir = GetDataDir();
82 string strLogDir = strDataDir + "/database";
83 filesystem::create_directory(strLogDir.c_str());
84 string strErrorFile = strDataDir + "/db.log";
85 printf("dbenv.open strLogDir=%s strErrorFile=%s\n", strLogDir.c_str(), strErrorFile.c_str());
87 dbenv.set_lg_dir(strLogDir.c_str());
88 dbenv.set_lg_max(10000000);
89 dbenv.set_lk_max_locks(10000);
90 dbenv.set_lk_max_objects(10000);
91 dbenv.set_errfile(fopen(strErrorFile.c_str(), "a")); /// debug
92 dbenv.set_flags(DB_AUTO_COMMIT, 1);
93 ret = dbenv.open(strDataDir.c_str(),
103 throw runtime_error(strprintf("CDB() : error %d opening database environment", ret));
108 ++mapFileUseCount[strFile];
109 pdb = mapDb[strFile];
112 pdb = new Db(&dbenv, 0);
114 ret = pdb->open(NULL, // Txn pointer
116 "main", // Logical db name
117 DB_BTREE, // Database type
125 CRITICAL_BLOCK(cs_db)
126 --mapFileUseCount[strFile];
128 throw runtime_error(strprintf("CDB() : can't open database file %s, error %d", pszFile, ret));
131 if (fCreate && !Exists(string("version")))
133 bool fTmp = fReadOnly;
135 WriteVersion(CLIENT_VERSION);
139 mapDb[strFile] = pdb;
149 vTxn.front()->abort();
153 // Flush database activity from memory pool to disk log
154 unsigned int nMinutes = 0;
157 if (strFile == "addr.dat")
159 if (strFile == "blkindex.dat" && IsInitialBlockDownload() && nBestHeight % 500 != 0)
161 dbenv.txn_checkpoint(0, nMinutes, 0);
163 CRITICAL_BLOCK(cs_db)
164 --mapFileUseCount[strFile];
167 void static CloseDb(const string& strFile)
169 CRITICAL_BLOCK(cs_db)
171 if (mapDb[strFile] != NULL)
173 // Close the database handle
174 Db* pdb = mapDb[strFile];
177 mapDb[strFile] = NULL;
182 bool CDB::Rewrite(const string& strFile, const char* pszSkip)
186 CRITICAL_BLOCK(cs_db)
188 if (!mapFileUseCount.count(strFile) || mapFileUseCount[strFile] == 0)
190 // Flush log data to the dat file
192 dbenv.txn_checkpoint(0, 0, 0);
193 dbenv.lsn_reset(strFile.c_str(), 0);
194 mapFileUseCount.erase(strFile);
196 bool fSuccess = true;
197 printf("Rewriting %s...\n", strFile.c_str());
198 string strFileRes = strFile + ".rewrite";
199 { // surround usage of db with extra {}
200 CDB db(strFile.c_str(), "r");
201 Db* pdbCopy = new Db(&dbenv, 0);
203 int ret = pdbCopy->open(NULL, // Txn pointer
204 strFileRes.c_str(), // Filename
205 "main", // Logical db name
206 DB_BTREE, // Database type
211 printf("Cannot create database file %s\n", strFileRes.c_str());
215 Dbc* pcursor = db.GetCursor();
221 int ret = db.ReadAtCursor(pcursor, ssKey, ssValue, DB_NEXT);
222 if (ret == DB_NOTFOUND)
234 strncmp(&ssKey[0], pszSkip, std::min(ssKey.size(), strlen(pszSkip))) == 0)
236 if (strncmp(&ssKey[0], "\x07version", 8) == 0)
240 ssValue << CLIENT_VERSION;
242 Dbt datKey(&ssKey[0], ssKey.size());
243 Dbt datValue(&ssValue[0], ssValue.size());
244 int ret2 = pdbCopy->put(NULL, &datKey, &datValue, DB_NOOVERWRITE);
252 if (pdbCopy->close(0))
260 if (dbA.remove(strFile.c_str(), NULL, 0))
263 if (dbB.rename(strFileRes.c_str(), NULL, strFile.c_str(), 0))
267 printf("Rewriting of %s FAILED!\n", strFileRes.c_str());
277 void DBFlush(bool fShutdown)
279 // Flush log data to the actual data file
280 // on all files that are not in use
281 printf("DBFlush(%s)%s\n", fShutdown ? "true" : "false", fDbEnvInit ? "" : " db not started");
284 CRITICAL_BLOCK(cs_db)
286 map<string, int>::iterator mi = mapFileUseCount.begin();
287 while (mi != mapFileUseCount.end())
289 string strFile = (*mi).first;
290 int nRefCount = (*mi).second;
291 printf("%s refcount=%d\n", strFile.c_str(), nRefCount);
294 // Move log data to the dat file
296 dbenv.txn_checkpoint(0, 0, 0);
297 printf("%s flush\n", strFile.c_str());
298 dbenv.lsn_reset(strFile.c_str(), 0);
299 mapFileUseCount.erase(mi++);
307 if (mapFileUseCount.empty())
309 dbenv.log_archive(&listp, DB_ARCH_REMOVE);
325 bool CTxDB::ReadTxIndex(uint256 hash, CTxIndex& txindex)
329 return Read(make_pair(string("tx"), hash), txindex);
332 bool CTxDB::UpdateTxIndex(uint256 hash, const CTxIndex& txindex)
335 return Write(make_pair(string("tx"), hash), txindex);
338 bool CTxDB::AddTxIndex(const CTransaction& tx, const CDiskTxPos& pos, int nHeight)
343 uint256 hash = tx.GetHash();
344 CTxIndex txindex(pos, tx.vout.size());
345 return Write(make_pair(string("tx"), hash), txindex);
348 bool CTxDB::EraseTxIndex(const CTransaction& tx)
351 uint256 hash = tx.GetHash();
353 return Erase(make_pair(string("tx"), hash));
356 bool CTxDB::ContainsTx(uint256 hash)
359 return Exists(make_pair(string("tx"), hash));
362 bool CTxDB::ReadOwnerTxes(uint160 hash160, int nMinHeight, vector<CTransaction>& vtx)
368 Dbc* pcursor = GetCursor();
372 unsigned int fFlags = DB_SET_RANGE;
377 if (fFlags == DB_SET_RANGE)
378 ssKey << string("owner") << hash160 << CDiskTxPos(0, 0, 0);
380 int ret = ReadAtCursor(pcursor, ssKey, ssValue, fFlags);
382 if (ret == DB_NOTFOUND)
394 ssKey >> strType >> hashItem >> pos;
396 ssValue >> nItemHeight;
399 if (strType != "owner" || hashItem != hash160)
401 if (nItemHeight >= nMinHeight)
403 vtx.resize(vtx.size()+1);
404 if (!vtx.back().ReadFromDisk(pos))
416 bool CTxDB::ReadDiskTx(uint256 hash, CTransaction& tx, CTxIndex& txindex)
420 if (!ReadTxIndex(hash, txindex))
422 return (tx.ReadFromDisk(txindex.pos));
425 bool CTxDB::ReadDiskTx(uint256 hash, CTransaction& tx)
428 return ReadDiskTx(hash, tx, txindex);
431 bool CTxDB::ReadDiskTx(COutPoint outpoint, CTransaction& tx, CTxIndex& txindex)
433 return ReadDiskTx(outpoint.hash, tx, txindex);
436 bool CTxDB::ReadDiskTx(COutPoint outpoint, CTransaction& tx)
439 return ReadDiskTx(outpoint.hash, tx, txindex);
442 bool CTxDB::WriteBlockIndex(const CDiskBlockIndex& blockindex)
444 return Write(make_pair(string("blockindex"), blockindex.GetBlockHash()), blockindex);
447 bool CTxDB::EraseBlockIndex(uint256 hash)
449 return Erase(make_pair(string("blockindex"), hash));
452 bool CTxDB::ReadHashBestChain(uint256& hashBestChain)
454 return Read(string("hashBestChain"), hashBestChain);
457 bool CTxDB::WriteHashBestChain(uint256 hashBestChain)
459 return Write(string("hashBestChain"), hashBestChain);
462 bool CTxDB::ReadBestInvalidWork(CBigNum& bnBestInvalidWork)
464 return Read(string("bnBestInvalidWork"), bnBestInvalidWork);
467 bool CTxDB::WriteBestInvalidWork(CBigNum bnBestInvalidWork)
469 return Write(string("bnBestInvalidWork"), bnBestInvalidWork);
472 CBlockIndex static * InsertBlockIndex(uint256 hash)
478 map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.find(hash);
479 if (mi != mapBlockIndex.end())
483 CBlockIndex* pindexNew = new CBlockIndex();
485 throw runtime_error("LoadBlockIndex() : new CBlockIndex failed");
486 mi = mapBlockIndex.insert(make_pair(hash, pindexNew)).first;
487 pindexNew->phashBlock = &((*mi).first);
492 bool CTxDB::LoadBlockIndex()
494 // Get database cursor
495 Dbc* pcursor = GetCursor();
499 // Load mapBlockIndex
500 unsigned int fFlags = DB_SET_RANGE;
505 if (fFlags == DB_SET_RANGE)
506 ssKey << make_pair(string("blockindex"), uint256(0));
508 int ret = ReadAtCursor(pcursor, ssKey, ssValue, fFlags);
510 if (ret == DB_NOTFOUND)
518 if (strType == "blockindex")
520 CDiskBlockIndex diskindex;
521 ssValue >> diskindex;
523 // Construct block index object
524 CBlockIndex* pindexNew = InsertBlockIndex(diskindex.GetBlockHash());
525 pindexNew->pprev = InsertBlockIndex(diskindex.hashPrev);
526 pindexNew->pnext = InsertBlockIndex(diskindex.hashNext);
527 pindexNew->nFile = diskindex.nFile;
528 pindexNew->nBlockPos = diskindex.nBlockPos;
529 pindexNew->nHeight = diskindex.nHeight;
530 pindexNew->nVersion = diskindex.nVersion;
531 pindexNew->hashMerkleRoot = diskindex.hashMerkleRoot;
532 pindexNew->nTime = diskindex.nTime;
533 pindexNew->nBits = diskindex.nBits;
534 pindexNew->nNonce = diskindex.nNonce;
536 // Watch for genesis block
537 if (pindexGenesisBlock == NULL && diskindex.GetBlockHash() == hashGenesisBlock)
538 pindexGenesisBlock = pindexNew;
540 if (!pindexNew->CheckIndex())
541 return error("LoadBlockIndex() : CheckIndex failed at %d", pindexNew->nHeight);
550 // Calculate bnChainWork
551 vector<pair<int, CBlockIndex*> > vSortedByHeight;
552 vSortedByHeight.reserve(mapBlockIndex.size());
553 BOOST_FOREACH(const PAIRTYPE(uint256, CBlockIndex*)& item, mapBlockIndex)
555 CBlockIndex* pindex = item.second;
556 vSortedByHeight.push_back(make_pair(pindex->nHeight, pindex));
558 sort(vSortedByHeight.begin(), vSortedByHeight.end());
559 BOOST_FOREACH(const PAIRTYPE(int, CBlockIndex*)& item, vSortedByHeight)
561 CBlockIndex* pindex = item.second;
562 pindex->bnChainWork = (pindex->pprev ? pindex->pprev->bnChainWork : 0) + pindex->GetBlockWork();
565 // Load hashBestChain pointer to end of best chain
566 if (!ReadHashBestChain(hashBestChain))
568 if (pindexGenesisBlock == NULL)
570 return error("CTxDB::LoadBlockIndex() : hashBestChain not loaded");
572 if (!mapBlockIndex.count(hashBestChain))
573 return error("CTxDB::LoadBlockIndex() : hashBestChain not found in the block index");
574 pindexBest = mapBlockIndex[hashBestChain];
575 nBestHeight = pindexBest->nHeight;
576 bnBestChainWork = pindexBest->bnChainWork;
577 printf("LoadBlockIndex(): hashBestChain=%s height=%d\n", hashBestChain.ToString().substr(0,20).c_str(), nBestHeight);
579 // Load bnBestInvalidWork, OK if it doesn't exist
580 ReadBestInvalidWork(bnBestInvalidWork);
582 // Verify blocks in the best chain
583 CBlockIndex* pindexFork = NULL;
584 for (CBlockIndex* pindex = pindexBest; pindex && pindex->pprev; pindex = pindex->pprev)
586 if (pindex->nHeight < nBestHeight-2500 && !mapArgs.count("-checkblocks"))
589 if (!block.ReadFromDisk(pindex))
590 return error("LoadBlockIndex() : block.ReadFromDisk failed");
591 if (!block.CheckBlock())
593 printf("LoadBlockIndex() : *** found bad block at %d, hash=%s\n", pindex->nHeight, pindex->GetBlockHash().ToString().c_str());
594 pindexFork = pindex->pprev;
599 // Reorg back to the fork
600 printf("LoadBlockIndex() : *** moving best chain pointer back to block %d\n", pindexFork->nHeight);
602 if (!block.ReadFromDisk(pindexFork))
603 return error("LoadBlockIndex() : block.ReadFromDisk failed");
605 block.SetBestChain(txdb, pindexFork);
619 bool CAddrDB::WriteAddress(const CAddress& addr)
621 return Write(make_pair(string("addr"), addr.GetKey()), addr);
624 bool CAddrDB::EraseAddress(const CAddress& addr)
626 return Erase(make_pair(string("addr"), addr.GetKey()));
629 bool CAddrDB::LoadAddresses()
631 CRITICAL_BLOCK(cs_mapAddresses)
634 Dbc* pcursor = GetCursor();
643 int ret = ReadAtCursor(pcursor, ssKey, ssValue);
644 if (ret == DB_NOTFOUND)
652 if (strType == "addr")
656 mapAddresses.insert(make_pair(addr.GetKey(), addr));
661 printf("Loaded %d addresses\n", mapAddresses.size());
669 return CAddrDB("cr+").LoadAddresses();
679 bool CWalletDB::WriteName(const string& strAddress, const string& strName)
682 return Write(make_pair(string("name"), strAddress), strName);
685 bool CWalletDB::EraseName(const string& strAddress)
687 // This should only be used for sending addresses, never for receiving addresses,
688 // receiving addresses must always have an address book entry if they're not change return.
690 return Erase(make_pair(string("name"), strAddress));
693 bool CWalletDB::ReadAccount(const string& strAccount, CAccount& account)
696 return Read(make_pair(string("acc"), strAccount), account);
699 bool CWalletDB::WriteAccount(const string& strAccount, const CAccount& account)
701 return Write(make_pair(string("acc"), strAccount), account);
704 bool CWalletDB::WriteAccountingEntry(const CAccountingEntry& acentry)
706 return Write(boost::make_tuple(string("acentry"), acentry.strAccount, ++nAccountingEntryNumber), acentry);
709 int64 CWalletDB::GetAccountCreditDebit(const string& strAccount)
711 list<CAccountingEntry> entries;
712 ListAccountCreditDebit(strAccount, entries);
714 int64 nCreditDebit = 0;
715 BOOST_FOREACH (const CAccountingEntry& entry, entries)
716 nCreditDebit += entry.nCreditDebit;
721 void CWalletDB::ListAccountCreditDebit(const string& strAccount, list<CAccountingEntry>& entries)
723 bool fAllAccounts = (strAccount == "*");
725 Dbc* pcursor = GetCursor();
727 throw runtime_error("CWalletDB::ListAccountCreditDebit() : cannot create DB cursor");
728 unsigned int fFlags = DB_SET_RANGE;
733 if (fFlags == DB_SET_RANGE)
734 ssKey << boost::make_tuple(string("acentry"), (fAllAccounts? string("") : strAccount), uint64(0));
736 int ret = ReadAtCursor(pcursor, ssKey, ssValue, fFlags);
738 if (ret == DB_NOTFOUND)
743 throw runtime_error("CWalletDB::ListAccountCreditDebit() : error scanning DB");
749 if (strType != "acentry")
751 CAccountingEntry acentry;
752 ssKey >> acentry.strAccount;
753 if (!fAllAccounts && acentry.strAccount != strAccount)
757 entries.push_back(acentry);
764 int CWalletDB::LoadWallet(CWallet* pwallet)
766 pwallet->vchDefaultKey.clear();
767 int nFileVersion = 0;
768 vector<uint256> vWalletUpgrade;
769 bool fIsEncrypted = false;
771 //// todo: shouldn't we catch exceptions and try to recover and continue?
772 CRITICAL_BLOCK(pwallet->cs_wallet)
775 Dbc* pcursor = GetCursor();
778 printf("Error getting wallet database cursor\n");
787 int ret = ReadAtCursor(pcursor, ssKey, ssValue);
788 if (ret == DB_NOTFOUND)
792 printf("Error reading next record from wallet database\n");
797 // Taking advantage of the fact that pair serialization
798 // is just the two items serialized one after the other
801 if (strType == "name")
805 ssValue >> pwallet->mapAddressBook[strAddress];
807 else if (strType == "tx")
811 CWalletTx& wtx = pwallet->mapWallet[hash];
813 wtx.BindWallet(pwallet);
815 if (wtx.GetHash() != hash)
816 printf("Error in wallet.dat, hash mismatch\n");
818 // Undo serialize changes in 31600
819 if (31404 <= wtx.fTimeReceivedIsTxTime && wtx.fTimeReceivedIsTxTime <= 31703)
821 if (!ssValue.empty())
825 ssValue >> fTmp >> fUnused >> wtx.strFromAccount;
826 printf("LoadWallet() upgrading tx ver=%d %d '%s' %s\n", wtx.fTimeReceivedIsTxTime, fTmp, wtx.strFromAccount.c_str(), hash.ToString().c_str());
827 wtx.fTimeReceivedIsTxTime = fTmp;
831 printf("LoadWallet() repairing tx ver=%d %s\n", wtx.fTimeReceivedIsTxTime, hash.ToString().c_str());
832 wtx.fTimeReceivedIsTxTime = 0;
834 vWalletUpgrade.push_back(hash);
838 //printf("LoadWallet %s\n", wtx.GetHash().ToString().c_str());
839 //printf(" %12I64d %s %s %s\n",
840 // wtx.vout[0].nValue,
841 // DateTimeStrFormat("%x %H:%M:%S", wtx.GetBlockTime()).c_str(),
842 // wtx.hashBlock.ToString().substr(0,20).c_str(),
843 // wtx.mapValue["message"].c_str());
845 else if (strType == "acentry")
851 if (nNumber > nAccountingEntryNumber)
852 nAccountingEntryNumber = nNumber;
854 else if (strType == "key" || strType == "wkey")
856 vector<unsigned char> vchPubKey;
859 if (strType == "key")
863 key.SetPubKey(vchPubKey);
864 key.SetPrivKey(pkey);
865 if (key.GetPubKey() != vchPubKey)
867 printf("Error reading wallet database: CPrivKey pubkey inconsistency\n");
872 printf("Error reading wallet database: invalid CPrivKey\n");
880 key.SetPubKey(vchPubKey);
881 key.SetPrivKey(wkey.vchPrivKey);
882 if (key.GetPubKey() != vchPubKey)
884 printf("Error reading wallet database: CWalletKey pubkey inconsistency\n");
889 printf("Error reading wallet database: invalid CWalletKey\n");
893 if (!pwallet->LoadKey(key))
895 printf("Error reading wallet database: LoadKey failed\n");
899 else if (strType == "mkey")
903 CMasterKey kMasterKey;
904 ssValue >> kMasterKey;
905 if(pwallet->mapMasterKeys.count(nID) != 0)
907 printf("Error reading wallet database: duplicate CMasterKey id %u\n", nID);
910 pwallet->mapMasterKeys[nID] = kMasterKey;
911 if (pwallet->nMasterKeyMaxID < nID)
912 pwallet->nMasterKeyMaxID = nID;
914 else if (strType == "ckey")
916 vector<unsigned char> vchPubKey;
918 vector<unsigned char> vchPrivKey;
919 ssValue >> vchPrivKey;
920 if (!pwallet->LoadCryptedKey(vchPubKey, vchPrivKey))
922 printf("Error reading wallet database: LoadCryptedKey failed\n");
927 else if (strType == "defaultkey")
929 ssValue >> pwallet->vchDefaultKey;
931 else if (strType == "pool")
935 pwallet->setKeyPool.insert(nIndex);
937 else if (strType == "version")
939 ssValue >> nFileVersion;
940 if (nFileVersion == 10300)
943 else if (strType == "minversion")
946 ssValue >> nMinVersion;
947 if (nMinVersion > CLIENT_VERSION)
949 pwallet->LoadMinVersion(nMinVersion);
951 else if (strType == "cscript")
957 if (!pwallet->LoadCScript(script))
959 printf("Error reading wallet database: LoadCScript failed\n");
967 BOOST_FOREACH(uint256 hash, vWalletUpgrade)
968 WriteTx(hash, pwallet->mapWallet[hash]);
970 printf("nFileVersion = %d\n", nFileVersion);
973 // Rewrite encrypted wallets of versions 0.4.0 and 0.5.0rc:
974 if (fIsEncrypted && (nFileVersion == 40000 || nFileVersion == 50000))
975 return DB_NEED_REWRITE;
977 if (nFileVersion < CLIENT_VERSION) // Update
979 // Get rid of old debug.log file in current directory
980 if (nFileVersion <= 105 && !pszSetDataDir[0])
983 WriteVersion(CLIENT_VERSION);
989 void ThreadFlushWalletDB(void* parg)
991 const string& strFile = ((const string*)parg)[0];
992 static bool fOneThread;
996 if (!GetBoolArg("-flushwallet", true))
999 unsigned int nLastSeen = nWalletDBUpdated;
1000 unsigned int nLastFlushed = nWalletDBUpdated;
1001 int64 nLastWalletUpdate = GetTime();
1006 if (nLastSeen != nWalletDBUpdated)
1008 nLastSeen = nWalletDBUpdated;
1009 nLastWalletUpdate = GetTime();
1012 if (nLastFlushed != nWalletDBUpdated && GetTime() - nLastWalletUpdate >= 2)
1014 TRY_CRITICAL_BLOCK(cs_db)
1016 // Don't do this if any databases are in use
1018 map<string, int>::iterator mi = mapFileUseCount.begin();
1019 while (mi != mapFileUseCount.end())
1021 nRefCount += (*mi).second;
1025 if (nRefCount == 0 && !fShutdown)
1027 map<string, int>::iterator mi = mapFileUseCount.find(strFile);
1028 if (mi != mapFileUseCount.end())
1030 printf("%s ", DateTimeStrFormat("%x %H:%M:%S", GetTime()).c_str());
1031 printf("Flushing wallet.dat\n");
1032 nLastFlushed = nWalletDBUpdated;
1033 int64 nStart = GetTimeMillis();
1035 // Flush wallet.dat so it's self contained
1037 dbenv.txn_checkpoint(0, 0, 0);
1038 dbenv.lsn_reset(strFile.c_str(), 0);
1040 mapFileUseCount.erase(mi++);
1041 printf("Flushed wallet.dat %"PRI64d"ms\n", GetTimeMillis() - nStart);
1049 bool BackupWallet(const CWallet& wallet, const string& strDest)
1051 if (!wallet.fFileBacked)
1055 CRITICAL_BLOCK(cs_db)
1057 if (!mapFileUseCount.count(wallet.strWalletFile) || mapFileUseCount[wallet.strWalletFile] == 0)
1059 // Flush log data to the dat file
1060 CloseDb(wallet.strWalletFile);
1061 dbenv.txn_checkpoint(0, 0, 0);
1062 dbenv.lsn_reset(wallet.strWalletFile.c_str(), 0);
1063 mapFileUseCount.erase(wallet.strWalletFile);
1066 filesystem::path pathSrc(GetDataDir() + "/" + wallet.strWalletFile);
1067 filesystem::path pathDest(strDest);
1068 if (filesystem::is_directory(pathDest))
1069 pathDest = pathDest / wallet.strWalletFile;
1072 #if BOOST_VERSION >= 104000
1073 filesystem::copy_file(pathSrc, pathDest, filesystem::copy_option::overwrite_if_exists);
1075 filesystem::copy_file(pathSrc, pathDest);
1077 printf("copied wallet.dat to %s\n", pathDest.string().c_str());
1079 } catch(const filesystem::filesystem_error &e) {
1080 printf("error copying wallet.dat to %s - %s\n", pathDest.string().c_str(), e.what());