@@ -15,7 +15,7 @@ static const char *HEADER_END = "HEADER=END";
1515static const char *DATA_END = " DATA=END" ;
1616typedef std::pair<std::vector<unsigned char >, std::vector<unsigned char > > KeyValPair;
1717
18- bool RecoverDatabaseFile (const fs::path& file_path, void *callbackDataIn, bool (*recoverKVcallback)( void * callbackData, CDataStream ssKey, CDataStream ssValue), std::string& newFilename )
18+ bool RecoverDatabaseFile (const fs::path& file_path)
1919{
2020 std::string filename;
2121 std::shared_ptr<BerkeleyEnvironment> env = GetWalletEnv (file_path, filename);
@@ -28,7 +28,7 @@ bool RecoverDatabaseFile(const fs::path& file_path, void *callbackDataIn, bool (
2828 // Set -rescan so any missing transactions will be
2929 // found.
3030 int64_t now = GetTime ();
31- newFilename = strprintf (" %s.%d.bak" , filename, now);
31+ std::string newFilename = strprintf (" %s.%d.bak" , filename, now);
3232
3333 int result = env->dbenv ->dbrename (nullptr , filename.c_str (), nullptr ,
3434 newFilename.c_str (), DB_AUTO_COMMIT);
@@ -116,14 +116,26 @@ bool RecoverDatabaseFile(const fs::path& file_path, void *callbackDataIn, bool (
116116 }
117117
118118 DbTxn* ptxn = env->TxnBegin ();
119+ CWallet dummyWallet (nullptr , WalletLocation (), WalletDatabase::CreateDummy ());
119120 for (KeyValPair& row : salvagedData)
120121 {
121- if (recoverKVcallback)
122+ /* Filter for only private key type KV pairs to be added to the salvaged wallet */
123+ CDataStream ssKey (row.first , SER_DISK, CLIENT_VERSION);
124+ CDataStream ssValue (row.second , SER_DISK, CLIENT_VERSION);
125+ std::string strType, strErr;
126+ bool fReadOK ;
122127 {
123- CDataStream ssKey (row.first , SER_DISK, CLIENT_VERSION);
124- CDataStream ssValue (row.second , SER_DISK, CLIENT_VERSION);
125- if (!(*recoverKVcallback)(callbackDataIn, ssKey, ssValue))
126- continue ;
128+ // Required in LoadKeyMetadata():
129+ LOCK (dummyWallet.cs_wallet );
130+ fReadOK = ReadKeyValue (&dummyWallet, ssKey, ssValue, strType, strErr);
131+ }
132+ if (!WalletBatch::IsKeyType (strType) && strType != DBKeys::HDCHAIN) {
133+ continue ;
134+ }
135+ if (!fReadOK )
136+ {
137+ LogPrintf (" WARNING: WalletBatch::Recover skipping %s: %s\n " , strType, strErr);
138+ continue ;
127139 }
128140 Dbt datKey (&row.first [0 ], row.first .size ());
129141 Dbt datValue (&row.second [0 ], row.second .size ());
@@ -136,25 +148,3 @@ bool RecoverDatabaseFile(const fs::path& file_path, void *callbackDataIn, bool (
136148
137149 return fSuccess ;
138150}
139-
140- bool RecoverKeysOnlyFilter (void *callbackData, CDataStream ssKey, CDataStream ssValue)
141- {
142- CWallet *dummyWallet = reinterpret_cast <CWallet*>(callbackData);
143- std::string strType, strErr;
144- bool fReadOK ;
145- {
146- // Required in LoadKeyMetadata():
147- LOCK (dummyWallet->cs_wallet );
148- fReadOK = ReadKeyValue (dummyWallet, ssKey, ssValue, strType, strErr);
149- }
150- if (!WalletBatch::IsKeyType (strType) && strType != DBKeys::HDCHAIN) {
151- return false ;
152- }
153- if (!fReadOK )
154- {
155- LogPrintf (" WARNING: WalletBatch::Recover skipping %s: %s\n " , strType, strErr);
156- return false ;
157- }
158-
159- return true ;
160- }
0 commit comments