Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/salvage.cpp
// Copyright (c) 2009-2010 Satoshi Nakamoto | // Copyright (c) 2009-2010 Satoshi Nakamoto | ||||
// Copyright (c) 2009-2020 The Bitcoin Core developers | // Copyright (c) 2009-2020 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include <config.h> | #include <config.h> | ||||
#include <fs.h> | #include <fs.h> | ||||
#include <streams.h> | #include <streams.h> | ||||
#include <util/translation.h> | |||||
#include <wallet/salvage.h> | #include <wallet/salvage.h> | ||||
#include <wallet/wallet.h> | #include <wallet/wallet.h> | ||||
#include <wallet/walletdb.h> | #include <wallet/walletdb.h> | ||||
/* End of headers, beginning of key/value data */ | /* End of headers, beginning of key/value data */ | ||||
static const char *HEADER_END = "HEADER=END"; | static const char *HEADER_END = "HEADER=END"; | ||||
/* End of key/value data */ | /* End of key/value data */ | ||||
static const char *DATA_END = "DATA=END"; | static const char *DATA_END = "DATA=END"; | ||||
typedef std::pair<std::vector<uint8_t>, std::vector<uint8_t>> KeyValPair; | typedef std::pair<std::vector<uint8_t>, std::vector<uint8_t>> KeyValPair; | ||||
bool RecoverDatabaseFile(const fs::path &file_path) { | bool RecoverDatabaseFile(const fs::path &file_path) { | ||||
std::string filename; | std::string filename; | ||||
std::shared_ptr<BerkeleyEnvironment> env = | std::shared_ptr<BerkeleyEnvironment> env = | ||||
GetWalletEnv(file_path, filename); | GetWalletEnv(file_path, filename); | ||||
if (!env->Open(true /* retry */)) { | bilingual_str open_err; | ||||
tfm::format(std::cerr, | if (!env->Open(open_err)) { | ||||
"Error initializing wallet database environment %s!", | tfm::format(std::cerr, "%s\n", open_err.original); | ||||
env->Directory()); | |||||
return false; | return false; | ||||
} | } | ||||
// Recovery procedure: | // Recovery procedure: | ||||
// move wallet file to walletfilename.timestamp.bak | // move wallet file to walletfilename.timestamp.bak | ||||
// Call Salvage with fAggressive=true to | // Call Salvage with fAggressive=true to | ||||
// get as much data as possible. | // get as much data as possible. | ||||
// Rewrite salvaged data to fresh wallet file | // Rewrite salvaged data to fresh wallet file | ||||
▲ Show 20 Lines • Show All 131 Lines • Show Last 20 Lines |