20    wallet->WalletLogPrintf(
"Releasing wallet\n");
 
   47    std::unique_ptr<WalletDatabase> database = 
MakeDatabase(path, options, status, 
error);
 
   57        load_wallet_ret = wallet_instance->LoadWallet();
 
   58    } 
catch (
const std::runtime_error&) {
 
   59        tfm::format(std::cerr, 
"Error loading %s. Is wallet being used by another process?\n", 
name);
 
   64        wallet_instance = 
nullptr;
 
   69            tfm::format(std::cerr, 
"Error reading %s! All keys read correctly, but transaction data" 
   70                            " or address book entries might be missing or incorrect.",
 
   73            tfm::format(std::cerr, 
"Error loading %s: Wallet requires newer version of %s",
 
   80            tfm::format(std::cerr, 
"Error reading %s! Some transaction data might be missing or" 
   81                           " incorrect. Wallet requires a rescan.",
 
   91    return wallet_instance;
 
   98    tfm::format(std::cout, 
"Wallet info\n===========\n");
 
  105    tfm::format(std::cout, 
"Transactions: %zu\n", wallet_instance->mapWallet.size());
 
  106    tfm::format(std::cout, 
"Address Book: %zu\n", wallet_instance->m_address_book.size());
 
  111    if (args.
IsArgSet(
"-format") && command != 
"createfromdump") {
 
  112        tfm::format(std::cerr, 
"The -format option can only be used with the \"createfromdump\" command.\n");
 
  115    if (args.
IsArgSet(
"-dumpfile") && command != 
"dump" && command != 
"createfromdump") {
 
  116        tfm::format(std::cerr, 
"The -dumpfile option can only be used with the \"dump\" and \"createfromdump\" commands.\n");
 
  119    if (args.
IsArgSet(
"-descriptors") && command != 
"create") {
 
  120        tfm::format(std::cerr, 
"The -descriptors option can only be used with the 'create' command.\n");
 
  123    if (args.
IsArgSet(
"-legacy") && command != 
"create") {
 
  124        tfm::format(std::cerr, 
"The -legacy option can only be used with the 'create' command.\n");
 
  127    if (command == 
"create" && !args.
IsArgSet(
"-wallet")) {
 
  128        tfm::format(std::cerr, 
"Wallet name must be provided when creating a new wallet.\n");
 
  131    const std::string 
name = args.
GetArg(
"-wallet", 
"");
 
  134    if (command == 
"create") {
 
  138        bool make_legacy = args.
GetBoolArg(
"-legacy", 
false);
 
  141        if (make_legacy && make_descriptors) {
 
  142            tfm::format(std::cerr, 
"Only one of -legacy or -descriptors can be set to true, not both\n");
 
  145        if (!make_legacy && !make_descriptors) {
 
  146            tfm::format(std::cerr, 
"One of -legacy or -descriptors must be set to true (or omitted)\n");
 
  149        if (make_descriptors) {
 
  154        const std::shared_ptr<CWallet> wallet_instance = 
MakeWallet(
name, path, options);
 
  155        if (wallet_instance) {
 
  157            wallet_instance->Close();
 
  159    } 
else if (command == 
"info") {
 
  162        const std::shared_ptr<CWallet> wallet_instance = 
MakeWallet(
name, path, options);
 
  163        if (!wallet_instance) 
return false;
 
  165        wallet_instance->Close();
 
  166    } 
else if (command == 
"salvage") {
 
  169        std::vector<bilingual_str> warnings;
 
  172            for (
const auto& warning : warnings) {
 
  175            if (!
error.empty()) {
 
  181        tfm::format(std::cerr, 
"Salvage command is not available as BDB support is not compiled");
 
  184    } 
else if (command == 
"dump") {
 
  187        const std::shared_ptr<CWallet> wallet_instance = 
MakeWallet(
name, path, options);
 
  188        if (!wallet_instance) 
return false;
 
  191        if (!ret && !
error.empty()) {
 
  195        tfm::format(std::cout, 
"The dumpfile may contain private keys. To ensure the safety of your Bitcoin, do not share the dumpfile.\n");
 
  197    } 
else if (command == 
"createfromdump") {
 
  199        std::vector<bilingual_str> warnings;
 
  201        for (
const auto& warning : warnings) {
 
  204        if (!ret && !
error.empty()) {
 
  209        tfm::format(std::cerr, 
"Invalid command: %s\n", command);
 
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.
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
RecursiveMutex cs_wallet
Main wallet lock.
void SetupDescriptorScriptPubKeyMans() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Create new DescriptorScriptPubKeyMans and add them to the wallet.
LegacyScriptPubKeyMan * GetOrCreateLegacyScriptPubKeyMan()
const std::string & GetName() const
Get a name for this wallet for logging/debugging purposes.
WalletDatabase & GetDatabase() const override
bool SetupGeneration(bool force=false) override
Sets up the key generation stuff, i.e.
virtual std::string Format()=0
Path class wrapper to prepare application code for transition from boost::filesystem library to std::...
std::unique_ptr< WalletDatabase > MakeDatabase(const fs::path &path, const DatabaseOptions &options, DatabaseStatus &status, bilingual_str &error)
bool CreateFromDump(const std::string &name, const fs::path &wallet_path, bilingual_str &error, std::vector< bilingual_str > &warnings)
bool DumpWallet(CWallet &wallet, bilingual_str &error)
unsigned int GetKeyPoolSize() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
bool TopUpKeyPool(unsigned int kpSize=0)
bool AddWalletFlags(uint64_t flags)
overwrite all flags by the given uint64_t returns false if unknown, non-tolerable flags are present
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
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.
bool RecoverDatabaseFile(const fs::path &file_path, bilingual_str &error, std::vector< bilingual_str > &warnings)
std::optional< DatabaseFormat > require_format
bool error(const char *fmt, const Args &... args)
DBErrors
Error statuses for the wallet database.
fs::path GetWalletDir()
Get the path of the wallet directory.
@ WALLET_FLAG_DESCRIPTORS
Indicate that this wallet supports DescriptorScriptPubKeyMan.