diff --git a/src/wallet/dump.cpp b/src/wallet/dump.cpp index 5ef4cfa0a8..157ec02a38 100644 --- a/src/wallet/dump.cpp +++ b/src/wallet/dump.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -20,7 +21,7 @@ namespace wallet { static const std::string DUMP_MAGIC = "BITCOIN_CORE_WALLET_DUMP"; uint32_t DUMP_VERSION = 1; -bool DumpWallet(CWallet& wallet, bilingual_str& error, const std::string& dump_filename) +bool DumpWallet(WalletDatabase& db, bilingual_str& error, const std::string& dump_filename) { fs::path path = fs::PathFromString(dump_filename); path = fs::absolute(path); @@ -37,7 +38,6 @@ bool DumpWallet(CWallet& wallet, bilingual_str& error, const std::string& dump_f HashWriter hasher{}; - WalletDatabase& db = wallet.GetDatabase(); std::unique_ptr batch = db.MakeBatch(); bool ret = true; diff --git a/src/wallet/dump.h b/src/wallet/dump.h index 8ab38ec92b..c7b626decf 100644 --- a/src/wallet/dump.h +++ b/src/wallet/dump.h @@ -14,8 +14,9 @@ struct bilingual_str; class ArgsManager; namespace wallet { -class CWallet; -bool DumpWallet(CWallet& wallet, bilingual_str& error, const std::string& dump_filename); +class WalletDatabase; + +bool DumpWallet(WalletDatabase& db, bilingual_str& error, const std::string& dump_filename); bool CreateFromDump(const ArgsManager& args, const std::string& name, const fs::path& wallet_path, bilingual_str& error, std::vector& warnings); } // namespace wallet diff --git a/src/wallet/interfaces.cpp b/src/wallet/interfaces.cpp index a4207540c7..a07141ba50 100644 --- a/src/wallet/interfaces.cpp +++ b/src/wallet/interfaces.cpp @@ -167,7 +167,10 @@ public: bool backupWallet(const std::string& filename, const WalletBackupFormat format, bilingual_str& error) override { switch (format) { case WalletBackupFormat::DbDump: - return DumpWallet(*m_wallet, error, filename); + { + WalletDatabase& db = m_wallet->GetDatabase(); + return DumpWallet(db, error, filename); + } case WalletBackupFormat::Raw: return m_wallet->BackupWallet(filename); } diff --git a/src/wallet/wallettool.cpp b/src/wallet/wallettool.cpp index aaa0082423..97d781fd63 100644 --- a/src/wallet/wallettool.cpp +++ b/src/wallet/wallettool.cpp @@ -235,8 +235,13 @@ bool ExecuteWalletToolFunc(const ArgsManager& args, const std::string& command) DatabaseOptions options; ReadDatabaseArgs(args, options); options.require_existing = true; - const std::shared_ptr wallet_instance = MakeWallet(name, path, options); - if (!wallet_instance) return false; + DatabaseStatus status; + bilingual_str error; + std::unique_ptr database = MakeDatabase(path, options, status, error); + if (!database) { + tfm::format(std::cerr, "%s\n", error.original); + return false; + } // Get the dumpfile std::string dump_filename = args.GetArg("-dumpfile", ""); @@ -245,9 +250,7 @@ bool ExecuteWalletToolFunc(const ArgsManager& args, const std::string& command) return false; } - bilingual_str error; - bool ret = DumpWallet(*wallet_instance, error, dump_filename); - wallet_instance->Close(); + bool ret = DumpWallet(*database, error, dump_filename); if (!ret && !error.empty()) { tfm::format(std::cerr, "%s\n", error.original); return ret;