Bitcoin Core  0.20.99
P2P Digital Currency
walletutil.h
Go to the documentation of this file.
1 // Copyright (c) 2017-2019 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 #ifndef BITCOIN_WALLET_WALLETUTIL_H
6 #define BITCOIN_WALLET_WALLETUTIL_H
7 
8 #include <fs.h>
9 #include <script/descriptor.h>
10 
11 #include <vector>
12 
15 {
16  FEATURE_BASE = 10500, // the earliest version new wallets supports (only useful for getwalletinfo's clientversion output)
17 
18  FEATURE_WALLETCRYPT = 40000, // wallet encryption
19  FEATURE_COMPRPUBKEY = 60000, // compressed public keys
20 
21  FEATURE_HD = 130000, // Hierarchical key derivation after BIP32 (HD Wallet)
22 
23  FEATURE_HD_SPLIT = 139900, // Wallet with HD chain split (change outputs will use m/0'/1'/k)
24 
25  FEATURE_NO_DEFAULT_KEY = 159900, // Wallet without a default key written
26 
27  FEATURE_PRE_SPLIT_KEYPOOL = 169900, // Upgraded to HD SPLIT and can have a pre-split keypool
28 
30 };
31 
32 
33 
34 enum WalletFlags : uint64_t {
35  // wallet flags in the upper section (> 1 << 31) will lead to not opening the wallet if flag is unknown
36  // unknown wallet flags in the lower section <= (1 << 31) will be tolerated
37 
38  // will categorize coins as clean (not reused) and dirty (reused), and handle
39  // them with privacy considerations in mind
40  WALLET_FLAG_AVOID_REUSE = (1ULL << 0),
41 
42  // Indicates that the metadata has already been upgraded to contain key origins
44 
45  // will enforce the rule that the wallet can't contain any private keys (only watch-only/pubkeys)
47 
58  WALLET_FLAG_BLANK_WALLET = (1ULL << 33),
59 
61  WALLET_FLAG_DESCRIPTORS = (1ULL << 34),
62 };
63 
65 fs::path GetWalletDir();
66 
68 std::vector<fs::path> ListWalletDir();
69 
71 class WalletLocation final
72 {
73  std::string m_name;
74  fs::path m_path;
75 
76 public:
77  explicit WalletLocation() {}
78  explicit WalletLocation(const std::string& name);
79 
81  const std::string& GetName() const { return m_name; }
82 
84  const fs::path& GetPath() const { return m_path; }
85 
87  bool Exists() const;
88 };
89 
92 {
93 public:
94  std::shared_ptr<Descriptor> descriptor;
95  uint64_t creation_time = 0;
96  int32_t range_start = 0; // First item in range; start of range, inclusive, i.e. [range_start, range_end). This never changes.
97  int32_t range_end = 0; // Item after the last; end of range, exclusive, i.e. [range_start, range_end). This will increment with each TopUp()
98  int32_t next_index = 0; // Position of the next item to generate
100 
101  void DeserializeDescriptor(const std::string& str)
102  {
103  std::string error;
104  FlatSigningProvider keys;
105  descriptor = Parse(str, keys, error, true);
106  if (!descriptor) {
107  throw std::ios_base::failure("Invalid descriptor: " + error);
108  }
109  }
110 
112  {
113  std::string descriptor_str;
114  SER_WRITE(obj, descriptor_str = obj.descriptor->ToString());
115  READWRITE(descriptor_str, obj.creation_time, obj.next_index, obj.range_start, obj.range_end);
116  SER_READ(obj, obj.DeserializeDescriptor(descriptor_str));
117  }
118 
120  WalletDescriptor(std::shared_ptr<Descriptor> descriptor, uint64_t creation_time, int32_t range_start, int32_t range_end, int32_t next_index) : descriptor(descriptor), creation_time(creation_time), range_start(range_start), range_end(range_end), next_index(next_index) {}
121 };
122 
123 #endif // BITCOIN_WALLET_WALLETUTIL_H
const fs::path & GetPath() const
Get wallet absolute path.
Definition: walletutil.h:84
fs::path GetWalletDir()
Get the path of the wallet directory.
Definition: dummywallet.cpp:61
fs::path m_path
Definition: walletutil.h:74
std::shared_ptr< Descriptor > descriptor
Definition: walletutil.h:94
std::vector< fs::path > ListWalletDir()
Get wallets in wallet directory.
Definition: dummywallet.cpp:66
bool Exists() const
Return whether the wallet exists.
Definition: walletutil.cpp:101
WalletFeature
(client) version numbers for particular wallet features
Definition: walletutil.h:14
std::unique_ptr< Descriptor > Parse(const std::string &descriptor, FlatSigningProvider &out, std::string &error, bool require_checksum)
Parse a descriptor string.
SERIALIZE_METHODS(WalletDescriptor, obj)
Definition: walletutil.h:111
std::string m_name
Definition: walletutil.h:73
const std::string & GetName() const
Get wallet name.
Definition: walletutil.h:81
const char * name
Definition: rest.cpp:41
DescriptorCache cache
Definition: walletutil.h:99
Flag set when a wallet contains no HD seed and no private keys, scripts, addresses, and other watch only things, and is therefore "blank.".
Definition: walletutil.h:58
Descriptor with some wallet metadata.
Definition: walletutil.h:91
Cache for single descriptor&#39;s derived extended pubkeys.
Definition: descriptor.h:19
WalletFlags
Definition: walletutil.h:34
The WalletLocation class provides wallet information.
Definition: walletutil.h:71
#define SER_READ(obj, code)
Definition: serialize.h:173
#define SER_WRITE(obj, code)
Definition: serialize.h:174
Indicate that this wallet supports DescriptorScriptPubKeyMan.
Definition: walletutil.h:61
#define READWRITE(...)
Definition: serialize.h:171
void DeserializeDescriptor(const std::string &str)
Definition: walletutil.h:101
bool error(const char *fmt, const Args &... args)
Definition: system.h:49
WalletDescriptor(std::shared_ptr< Descriptor > descriptor, uint64_t creation_time, int32_t range_start, int32_t range_end, int32_t next_index)
Definition: walletutil.h:120