Bitcoin Core  22.99.0
P2P Digital Currency
walletutil.cpp
Go to the documentation of this file.
1 // Copyright (c) 2017-2021 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #include <wallet/walletutil.h>
6 
7 #include <logging.h>
8 #include <util/system.h>
9 
10 namespace wallet {
12 {
13  fs::path path;
14 
15  if (gArgs.IsArgSet("-walletdir")) {
16  path = gArgs.GetPathArg("-walletdir");
17  if (!fs::is_directory(path)) {
18  // If the path specified doesn't exist, we return the deliberately
19  // invalid empty string.
20  path = "";
21  }
22  } else {
23  path = gArgs.GetDataDirNet();
24  // If a wallets directory exists, use that, otherwise default to GetDataDir
25  if (fs::is_directory(path / "wallets")) {
26  path /= "wallets";
27  }
28  }
29 
30  return path;
31 }
32 
33 bool IsFeatureSupported(int wallet_version, int feature_version)
34 {
35  return wallet_version >= feature_version;
36 }
37 
39 {
41  for (const WalletFeature& wf : wallet_features) {
42  if (version >= wf) return wf;
43  }
44  return static_cast<WalletFeature>(0);
45 }
46 } // namespace wallet
wallet::FEATURE_BASE
@ FEATURE_BASE
Definition: walletutil.h:17
ArgsManager::GetDataDirNet
const fs::path & GetDataDirNet() const
Get data directory path with appended network identifier.
Definition: system.h:304
ArgsManager::GetPathArg
fs::path GetPathArg(std::string pathlike_arg) const
Get a normalized path from a specified pathlike argument.
Definition: system.cpp:390
ArgsManager::IsArgSet
bool IsArgSet(const std::string &strArg) const
Return true if the given argument has been manually set.
Definition: system.cpp:494
wallet::FEATURE_NO_DEFAULT_KEY
@ FEATURE_NO_DEFAULT_KEY
Definition: walletutil.h:26
wallet
Definition: node.h:38
wallet::FEATURE_COMPRPUBKEY
@ FEATURE_COMPRPUBKEY
Definition: walletutil.h:20
wallet::WalletFeature
WalletFeature
(client) version numbers for particular wallet features
Definition: walletutil.h:15
walletutil.h
wallet::FEATURE_LATEST
@ FEATURE_LATEST
Definition: walletutil.h:30
wallet::FEATURE_HD_SPLIT
@ FEATURE_HD_SPLIT
Definition: walletutil.h:24
fs::path
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
Definition: fs.h:29
gArgs
ArgsManager gArgs
Definition: system.cpp:87
wallet::FEATURE_PRE_SPLIT_KEYPOOL
@ FEATURE_PRE_SPLIT_KEYPOOL
Definition: walletutil.h:28
wallet::FEATURE_HD
@ FEATURE_HD
Definition: walletutil.h:22
system.h
wallet::GetClosestWalletFeature
WalletFeature GetClosestWalletFeature(int version)
Definition: walletutil.cpp:38
wallet::FEATURE_WALLETCRYPT
@ FEATURE_WALLETCRYPT
Definition: walletutil.h:19
wallet::GetWalletDir
fs::path GetWalletDir()
Get the path of the wallet directory.
Definition: walletutil.cpp:11
wallet::IsFeatureSupported
bool IsFeatureSupported(int wallet_version, int feature_version)
Definition: walletutil.cpp:33