Skip to content

Commit b426c77

Browse files
committed
Make BerkeleyBatch::Recover and WalletBatch::RecoverKeysOnlyFilter standalone
Instead of having these be class static functions, just make them be standalone. Also removes WalletBatch::Recover which just passed through to BerkeleyBatch::Recover.
1 parent 2741774 commit b426c77

File tree

5 files changed

+9
-26
lines changed

5 files changed

+9
-26
lines changed

src/wallet/db.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ static const char *HEADER_END = "HEADER=END";
323323
static const char *DATA_END = "DATA=END";
324324
typedef std::pair<std::vector<unsigned char>, std::vector<unsigned char> > KeyValPair;
325325

326-
bool BerkeleyBatch::Recover(const fs::path& file_path, void *callbackDataIn, bool (*recoverKVcallback)(void* callbackData, CDataStream ssKey, CDataStream ssValue), std::string& newFilename)
326+
bool RecoverDatabaseFile(const fs::path& file_path, void *callbackDataIn, bool (*recoverKVcallback)(void* callbackData, CDataStream ssKey, CDataStream ssValue), std::string& newFilename)
327327
{
328328
std::string filename;
329329
std::shared_ptr<BerkeleyEnvironment> env = GetWalletEnv(file_path, filename);

src/wallet/db.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,6 @@ class BerkeleyBatch
226226

227227
void Flush();
228228
void Close();
229-
static bool Recover(const fs::path& file_path, void *callbackDataIn, bool (*recoverKVcallback)(void* callbackData, CDataStream ssKey, CDataStream ssValue), std::string& out_backup_filename);
230229

231230
/* flush the wallet passively (TRY_LOCK)
232231
ideal to be called periodically */
@@ -390,6 +389,8 @@ class BerkeleyBatch
390389
bool static Rewrite(BerkeleyDatabase& database, const char* pszSkip = nullptr);
391390
};
392391

392+
bool RecoverDatabaseFile(const fs::path& file_path, void *callbackDataIn, bool (*recoverKVcallback)(void* callbackData, CDataStream ssKey, CDataStream ssValue), std::string& out_backup_filename);
393+
393394
std::string BerkeleyDatabaseVersion();
394395

395396
#endif // BITCOIN_WALLET_DB_H

src/wallet/walletdb.cpp

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -885,22 +885,7 @@ void MaybeCompactWalletDB()
885885
fOneThread = false;
886886
}
887887

888-
//
889-
// Try to (very carefully!) recover wallet file if there is a problem.
890-
//
891-
bool WalletBatch::Recover(const fs::path& wallet_path, void *callbackDataIn, bool (*recoverKVcallback)(void* callbackData, CDataStream ssKey, CDataStream ssValue), std::string& out_backup_filename)
892-
{
893-
return BerkeleyBatch::Recover(wallet_path, callbackDataIn, recoverKVcallback, out_backup_filename);
894-
}
895-
896-
bool WalletBatch::Recover(const fs::path& wallet_path, std::string& out_backup_filename)
897-
{
898-
// recover without a key filter callback
899-
// results in recovering all record types
900-
return WalletBatch::Recover(wallet_path, nullptr, nullptr, out_backup_filename);
901-
}
902-
903-
bool WalletBatch::RecoverKeysOnlyFilter(void *callbackData, CDataStream ssKey, CDataStream ssValue)
888+
bool RecoverKeysOnlyFilter(void *callbackData, CDataStream ssKey, CDataStream ssValue)
904889
{
905890
CWallet *dummyWallet = reinterpret_cast<CWallet*>(callbackData);
906891
std::string strType, strErr;
@@ -910,7 +895,7 @@ bool WalletBatch::RecoverKeysOnlyFilter(void *callbackData, CDataStream ssKey, C
910895
LOCK(dummyWallet->cs_wallet);
911896
fReadOK = ReadKeyValue(dummyWallet, ssKey, ssValue, strType, strErr);
912897
}
913-
if (!IsKeyType(strType) && strType != DBKeys::HDCHAIN) {
898+
if (!WalletBatch::IsKeyType(strType) && strType != DBKeys::HDCHAIN) {
914899
return false;
915900
}
916901
if (!fReadOK)

src/wallet/walletdb.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -263,12 +263,6 @@ class WalletBatch
263263
DBErrors FindWalletTx(std::vector<uint256>& vTxHash, std::list<CWalletTx>& vWtx);
264264
DBErrors ZapWalletTx(std::list<CWalletTx>& vWtx);
265265
DBErrors ZapSelectTx(std::vector<uint256>& vHashIn, std::vector<uint256>& vHashOut);
266-
/* Try to (very carefully!) recover wallet database (with a possible key type filter) */
267-
static bool Recover(const fs::path& wallet_path, void *callbackDataIn, bool (*recoverKVcallback)(void* callbackData, CDataStream ssKey, CDataStream ssValue), std::string& out_backup_filename);
268-
/* Recover convenience-function to bypass the key filter callback, called when verify fails, recovers everything */
269-
static bool Recover(const fs::path& wallet_path, std::string& out_backup_filename);
270-
/* Recover filter (used as callback), will only let keys (cryptographical keys) as KV/key-type pass through */
271-
static bool RecoverKeysOnlyFilter(void *callbackData, CDataStream ssKey, CDataStream ssValue);
272266
/* Function to determine if a certain KV/key-type is a key (cryptographical key) type */
273267
static bool IsKeyType(const std::string& strType);
274268
/* verifies the database environment */
@@ -297,4 +291,7 @@ void MaybeCompactWalletDB();
297291
//! Unserialize a given Key-Value pair and load it into the wallet
298292
bool ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue, std::string& strType, std::string& strErr);
299293

294+
/* Recover filter (used as callback), will only let keys (cryptographical keys) as KV/key-type pass through */
295+
bool RecoverKeysOnlyFilter(void *callbackData, CDataStream ssKey, CDataStream ssValue);
296+
300297
#endif // BITCOIN_WALLET_WALLETDB_H

src/wallet/wallettool.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ static bool SalvageWallet(const fs::path& path)
123123
// Perform the recovery
124124
CWallet dummy_wallet(nullptr, WalletLocation(), WalletDatabase::CreateDummy());
125125
std::string backup_filename;
126-
return WalletBatch::Recover(path, (void*)&dummy_wallet, WalletBatch::RecoverKeysOnlyFilter, backup_filename);
126+
return RecoverDatabaseFile(path, (void*)&dummy_wallet, RecoverKeysOnlyFilter, backup_filename);
127127
}
128128

129129
bool ExecuteWalletToolFunc(const std::string& command, const std::string& name)

0 commit comments

Comments
 (0)