Skip to content

Commit d83bea4

Browse files
committed
wallettool: Don't create CWallet when dumping DB
It's not necessary to set up an entire CWallet just so we can get access to the WalletDatabase and read the records. Instead we can go one level lower and make just a WalletDatabase.
1 parent 40c80e3 commit d83bea4

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

src/wallet/dump.cpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <util/fs.h>
99
#include <util/translation.h>
1010
#include <wallet/wallet.h>
11+
#include <wallet/walletdb.h>
1112

1213
#include <algorithm>
1314
#include <fstream>
@@ -20,7 +21,7 @@ namespace wallet {
2021
static const std::string DUMP_MAGIC = "BITCOIN_CORE_WALLET_DUMP";
2122
uint32_t DUMP_VERSION = 1;
2223

23-
bool DumpWallet(const ArgsManager& args, CWallet& wallet, bilingual_str& error)
24+
bool DumpWallet(const ArgsManager& args, WalletDatabase& db, bilingual_str& error)
2425
{
2526
// Get the dumpfile
2627
std::string dump_filename = args.GetArg("-dumpfile", "");
@@ -44,7 +45,6 @@ bool DumpWallet(const ArgsManager& args, CWallet& wallet, bilingual_str& error)
4445

4546
HashWriter hasher{};
4647

47-
WalletDatabase& db = wallet.GetDatabase();
4848
std::unique_ptr<DatabaseBatch> batch = db.MakeBatch();
4949

5050
bool ret = true;
@@ -90,9 +90,6 @@ bool DumpWallet(const ArgsManager& args, CWallet& wallet, bilingual_str& error)
9090
cursor.reset();
9191
batch.reset();
9292

93-
// Close the wallet after we're done with it. The caller won't be doing this
94-
wallet.Close();
95-
9693
if (ret) {
9794
// Write the hash
9895
tfm::format(dump_file, "checksum,%s\n", HexStr(hasher.GetHash()));

src/wallet/dump.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ struct bilingual_str;
1414
class ArgsManager;
1515

1616
namespace wallet {
17-
class CWallet;
18-
bool DumpWallet(const ArgsManager& args, CWallet& wallet, bilingual_str& error);
17+
class WalletDatabase;
18+
19+
bool DumpWallet(const ArgsManager& args, WalletDatabase& db, bilingual_str& error);
1920
bool CreateFromDump(const ArgsManager& args, const std::string& name, const fs::path& wallet_path, bilingual_str& error, std::vector<bilingual_str>& warnings);
2021
} // namespace wallet
2122

src/wallet/wallettool.cpp

+8-3
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,15 @@ bool ExecuteWalletToolFunc(const ArgsManager& args, const std::string& command)
193193
DatabaseOptions options;
194194
ReadDatabaseArgs(args, options);
195195
options.require_existing = true;
196-
const std::shared_ptr<CWallet> wallet_instance = MakeWallet(name, path, options);
197-
if (!wallet_instance) return false;
196+
DatabaseStatus status;
198197
bilingual_str error;
199-
bool ret = DumpWallet(args, *wallet_instance, error);
198+
std::unique_ptr<WalletDatabase> database = MakeDatabase(path, options, status, error);
199+
if (!database) {
200+
tfm::format(std::cerr, "%s\n", error.original);
201+
return false;
202+
}
203+
204+
bool ret = DumpWallet(args, *database, error);
200205
if (!ret && !error.empty()) {
201206
tfm::format(std::cerr, "%s\n", error.original);
202207
return ret;

0 commit comments

Comments
 (0)