5#include <bitcoin-build-config.h>
25 wallet->WalletLogPrintf(
"Releasing wallet\n");
52 std::unique_ptr<WalletDatabase> database =
MakeDatabase(path, options, status, error);
62 load_wallet_ret = wallet_instance->LoadWallet();
63 }
catch (
const std::runtime_error&) {
64 tfm::format(std::cerr,
"Error loading %s. Is wallet being used by another process?\n",
name);
73 tfm::format(std::cerr,
"Error reading %s! All keys read correctly, but transaction data"
74 " or address book entries might be missing or incorrect.",
77 tfm::format(std::cerr,
"Error loading %s: Wallet requires newer version of %s",
81 tfm::format(std::cerr,
"Wallet needed to be rewritten: restart %s to complete", CLIENT_NAME);
84 tfm::format(std::cerr,
"Error reading %s! Some transaction data might be missing or"
85 " incorrect. Wallet requires a rescan.",
95 return wallet_instance;
102 tfm::format(std::cout,
"Wallet info\n===========\n");
109 tfm::format(std::cout,
"Transactions: %zu\n", wallet_instance->mapWallet.size());
110 tfm::format(std::cout,
"Address Book: %zu\n", wallet_instance->m_address_book.size());
116 tfm::format(std::cerr,
"The -format option can only be used with the \"createfromdump\" command.\n");
120 tfm::format(std::cerr,
"The -dumpfile option can only be used with the \"dump\" and \"createfromdump\" commands.\n");
124 tfm::format(std::cerr,
"The -descriptors option can only be used with the 'create' command.\n");
128 tfm::format(std::cerr,
"The -legacy option can only be used with the 'create' command.\n");
132 tfm::format(std::cerr,
"Wallet name must be provided when creating a new wallet.\n");
146 if (make_legacy && make_descriptors) {
147 tfm::format(std::cerr,
"Only one of -legacy or -descriptors can be set to true, not both\n");
150 if (!make_legacy && !make_descriptors) {
151 tfm::format(std::cerr,
"One of -legacy or -descriptors must be set to true (or omitted)\n");
154 if (make_descriptors) {
159 const std::shared_ptr<CWallet> wallet_instance =
MakeWallet(
name, path, options);
160 if (wallet_instance) {
162 wallet_instance->Close();
164 }
else if (
command ==
"info") {
168 const std::shared_ptr<CWallet> wallet_instance =
MakeWallet(
name, path, options);
169 if (!wallet_instance)
return false;
171 wallet_instance->Close();
172 }
else if (
command ==
"salvage") {
175 std::vector<bilingual_str> warnings;
178 for (
const auto& warning : warnings) {
181 if (!error.
empty()) {
187 tfm::format(std::cerr,
"Salvage command is not available as BDB support is not compiled");
190 }
else if (
command ==
"dump") {
201 std::unique_ptr<WalletDatabase> database =
MakeDatabase(path, options, status, error);
212 tfm::format(std::cout,
"The dumpfile may contain private keys. To ensure the safety of your Bitcoin, do not share the dumpfile.\n");
214 }
else if (
command ==
"createfromdump") {
216 std::vector<bilingual_str> warnings;
218 for (
const auto& warning : warnings) {
bool IsArgSet(const std::string &strArg) const
Return true if the given argument has been manually set.
std::string GetArg(const std::string &strArg, const std::string &strDefault) const
Return string argument or default value.
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
const std::string & GetName() const
Get a name for this wallet for logging/debugging purposes.
void SetupDescriptorScriptPubKeyMans(WalletBatch &batch, const CExtKey &master_key) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Create new DescriptorScriptPubKeyMans and add them to the wallet.
WalletDatabase & GetDatabase() const override
RecursiveMutex cs_wallet
Main wallet lock.
LegacyScriptPubKeyMan * GetOrCreateLegacyScriptPubKeyMan()
bool SetupGeneration(bool force=false) override
Sets up the key generation stuff, i.e.
virtual std::string Format()=0
bool TopUpKeyPool(unsigned int kpSize=0)
unsigned int GetKeyPoolSize() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
void SetMinVersion(enum WalletFeature, WalletBatch *batch_in=nullptr) override
signify that a particular wallet feature is now used.
bool IsWalletFlagSet(uint64_t flag) const override
check if a certain wallet flag is set
void InitWalletFlags(uint64_t flags)
overwrite all flags by the given uint64_t flags must be uninitialised (or 0) only known flags may be ...
static path PathFromString(const std::string &string)
Convert byte string to path object.
fs::path AbsPathJoin(const fs::path &base, const fs::path &path)
Helper function for joining two paths.
void ReadDatabaseArgs(const ArgsManager &args, DatabaseOptions &options)
std::unique_ptr< WalletDatabase > MakeDatabase(const fs::path &path, const DatabaseOptions &options, DatabaseStatus &status, bilingual_str &error)
DBErrors
Error statuses for the wallet database.
bool CreateFromDump(const ArgsManager &args, const std::string &name, const fs::path &wallet_path, bilingual_str &error, std::vector< bilingual_str > &warnings)
fs::path GetWalletDir()
Get the path of the wallet directory.
bool IsBDBFile(const fs::path &path)
fs::path BDBDataFile(const fs::path &wallet_path)
bool DumpWallet(const ArgsManager &args, WalletDatabase &db, bilingual_str &error)
@ WALLET_FLAG_DESCRIPTORS
Indicate that this wallet supports DescriptorScriptPubKeyMan.
bool RecoverDatabaseFile(const ArgsManager &args, const fs::path &file_path, bilingual_str &error, std::vector< bilingual_str > &warnings)
std::optional< DatabaseFormat > require_format