@@ -15,7 +15,7 @@ static const char *HEADER_END = "HEADER=END";
15
15
static const char *DATA_END = " DATA=END" ;
16
16
typedef std::pair<std::vector<unsigned char >, std::vector<unsigned char > > KeyValPair;
17
17
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)
19
19
{
20
20
std::string filename;
21
21
std::shared_ptr<BerkeleyEnvironment> env = GetWalletEnv (file_path, filename);
@@ -28,7 +28,7 @@ bool RecoverDatabaseFile(const fs::path& file_path, void *callbackDataIn, bool (
28
28
// Set -rescan so any missing transactions will be
29
29
// found.
30
30
int64_t now = GetTime ();
31
- newFilename = strprintf (" %s.%d.bak" , filename, now);
31
+ std::string newFilename = strprintf (" %s.%d.bak" , filename, now);
32
32
33
33
int result = env->dbenv ->dbrename (nullptr , filename.c_str (), nullptr ,
34
34
newFilename.c_str (), DB_AUTO_COMMIT);
@@ -116,14 +116,26 @@ bool RecoverDatabaseFile(const fs::path& file_path, void *callbackDataIn, bool (
116
116
}
117
117
118
118
DbTxn* ptxn = env->TxnBegin ();
119
+ CWallet dummyWallet (nullptr , WalletLocation (), WalletDatabase::CreateDummy ());
119
120
for (KeyValPair& row : salvagedData)
120
121
{
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 ;
122
127
{
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 ;
127
139
}
128
140
Dbt datKey (&row.first [0 ], row.first .size ());
129
141
Dbt datValue (&row.second [0 ], row.second .size ());
@@ -136,25 +148,3 @@ bool RecoverDatabaseFile(const fs::path& file_path, void *callbackDataIn, bool (
136
148
137
149
return fSuccess ;
138
150
}
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