mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-29 14:59:39 -04:00
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.
This commit is contained in:
parent
40c80e36b1
commit
d83bea42d1
3 changed files with 13 additions and 10 deletions
|
@ -8,6 +8,7 @@
|
||||||
#include <util/fs.h>
|
#include <util/fs.h>
|
||||||
#include <util/translation.h>
|
#include <util/translation.h>
|
||||||
#include <wallet/wallet.h>
|
#include <wallet/wallet.h>
|
||||||
|
#include <wallet/walletdb.h>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
@ -20,7 +21,7 @@ namespace wallet {
|
||||||
static const std::string DUMP_MAGIC = "BITCOIN_CORE_WALLET_DUMP";
|
static const std::string DUMP_MAGIC = "BITCOIN_CORE_WALLET_DUMP";
|
||||||
uint32_t DUMP_VERSION = 1;
|
uint32_t DUMP_VERSION = 1;
|
||||||
|
|
||||||
bool DumpWallet(const ArgsManager& args, CWallet& wallet, bilingual_str& error)
|
bool DumpWallet(const ArgsManager& args, WalletDatabase& db, bilingual_str& error)
|
||||||
{
|
{
|
||||||
// Get the dumpfile
|
// Get the dumpfile
|
||||||
std::string dump_filename = args.GetArg("-dumpfile", "");
|
std::string dump_filename = args.GetArg("-dumpfile", "");
|
||||||
|
@ -44,7 +45,6 @@ bool DumpWallet(const ArgsManager& args, CWallet& wallet, bilingual_str& error)
|
||||||
|
|
||||||
HashWriter hasher{};
|
HashWriter hasher{};
|
||||||
|
|
||||||
WalletDatabase& db = wallet.GetDatabase();
|
|
||||||
std::unique_ptr<DatabaseBatch> batch = db.MakeBatch();
|
std::unique_ptr<DatabaseBatch> batch = db.MakeBatch();
|
||||||
|
|
||||||
bool ret = true;
|
bool ret = true;
|
||||||
|
@ -90,9 +90,6 @@ bool DumpWallet(const ArgsManager& args, CWallet& wallet, bilingual_str& error)
|
||||||
cursor.reset();
|
cursor.reset();
|
||||||
batch.reset();
|
batch.reset();
|
||||||
|
|
||||||
// Close the wallet after we're done with it. The caller won't be doing this
|
|
||||||
wallet.Close();
|
|
||||||
|
|
||||||
if (ret) {
|
if (ret) {
|
||||||
// Write the hash
|
// Write the hash
|
||||||
tfm::format(dump_file, "checksum,%s\n", HexStr(hasher.GetHash()));
|
tfm::format(dump_file, "checksum,%s\n", HexStr(hasher.GetHash()));
|
||||||
|
|
|
@ -14,8 +14,9 @@ struct bilingual_str;
|
||||||
class ArgsManager;
|
class ArgsManager;
|
||||||
|
|
||||||
namespace wallet {
|
namespace wallet {
|
||||||
class CWallet;
|
class WalletDatabase;
|
||||||
bool DumpWallet(const ArgsManager& args, CWallet& wallet, bilingual_str& error);
|
|
||||||
|
bool DumpWallet(const ArgsManager& args, WalletDatabase& db, bilingual_str& error);
|
||||||
bool CreateFromDump(const ArgsManager& args, const std::string& name, const fs::path& wallet_path, bilingual_str& error, std::vector<bilingual_str>& warnings);
|
bool CreateFromDump(const ArgsManager& args, const std::string& name, const fs::path& wallet_path, bilingual_str& error, std::vector<bilingual_str>& warnings);
|
||||||
} // namespace wallet
|
} // namespace wallet
|
||||||
|
|
||||||
|
|
|
@ -193,10 +193,15 @@ bool ExecuteWalletToolFunc(const ArgsManager& args, const std::string& command)
|
||||||
DatabaseOptions options;
|
DatabaseOptions options;
|
||||||
ReadDatabaseArgs(args, options);
|
ReadDatabaseArgs(args, options);
|
||||||
options.require_existing = true;
|
options.require_existing = true;
|
||||||
const std::shared_ptr<CWallet> wallet_instance = MakeWallet(name, path, options);
|
DatabaseStatus status;
|
||||||
if (!wallet_instance) return false;
|
|
||||||
bilingual_str error;
|
bilingual_str error;
|
||||||
bool ret = DumpWallet(args, *wallet_instance, error);
|
std::unique_ptr<WalletDatabase> database = MakeDatabase(path, options, status, error);
|
||||||
|
if (!database) {
|
||||||
|
tfm::format(std::cerr, "%s\n", error.original);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ret = DumpWallet(args, *database, error);
|
||||||
if (!ret && !error.empty()) {
|
if (!ret && !error.empty()) {
|
||||||
tfm::format(std::cerr, "%s\n", error.original);
|
tfm::format(std::cerr, "%s\n", error.original);
|
||||||
return ret;
|
return ret;
|
||||||
|
|
Loading…
Add table
Reference in a new issue