Bitcoin Core  22.99.0
P2P Digital Currency
walletutil.h
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 #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 
13 namespace wallet {
16 {
17  FEATURE_BASE = 10500, // the earliest version new wallets supports (only useful for getwalletinfo's clientversion output)
18 
19  FEATURE_WALLETCRYPT = 40000, // wallet encryption
20  FEATURE_COMPRPUBKEY = 60000, // compressed public keys
21 
22  FEATURE_HD = 130000, // Hierarchical key derivation after BIP32 (HD Wallet)
23 
24  FEATURE_HD_SPLIT = 139900, // Wallet with HD chain split (change outputs will use m/0'/1'/k)
25 
26  FEATURE_NO_DEFAULT_KEY = 159900, // Wallet without a default key written
27 
28  FEATURE_PRE_SPLIT_KEYPOOL = 169900, // Upgraded to HD SPLIT and can have a pre-split keypool
29 
31 };
32 
33 bool IsFeatureSupported(int wallet_version, int feature_version);
35 
36 enum WalletFlags : uint64_t {
37  // wallet flags in the upper section (> 1 << 31) will lead to not opening the wallet if flag is unknown
38  // unknown wallet flags in the lower section <= (1 << 31) will be tolerated
39 
40  // will categorize coins as clean (not reused) and dirty (reused), and handle
41  // them with privacy considerations in mind
42  WALLET_FLAG_AVOID_REUSE = (1ULL << 0),
43 
44  // Indicates that the metadata has already been upgraded to contain key origins
46 
47  // Indicates that the descriptor cache has been upgraded to cache last hardened xpubs
49 
50  // will enforce the rule that the wallet can't contain any private keys (only watch-only/pubkeys)
52 
63  WALLET_FLAG_BLANK_WALLET = (1ULL << 33),
64 
66  WALLET_FLAG_DESCRIPTORS = (1ULL << 34),
67 
70 };
71 
74 
77 {
78 public:
79  std::shared_ptr<Descriptor> descriptor;
80  uint64_t creation_time = 0;
81  int32_t range_start = 0; // First item in range; start of range, inclusive, i.e. [range_start, range_end). This never changes.
82  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()
83  int32_t next_index = 0; // Position of the next item to generate
85 
86  void DeserializeDescriptor(const std::string& str)
87  {
88  std::string error;
90  descriptor = Parse(str, keys, error, true);
91  if (!descriptor) {
92  throw std::ios_base::failure("Invalid descriptor: " + error);
93  }
94  }
95 
97  {
98  std::string descriptor_str;
99  SER_WRITE(obj, descriptor_str = obj.descriptor->ToString());
100  READWRITE(descriptor_str, obj.creation_time, obj.next_index, obj.range_start, obj.range_end);
101  SER_READ(obj, obj.DeserializeDescriptor(descriptor_str));
102  }
103 
106 };
107 } // namespace wallet
108 
109 #endif // BITCOIN_WALLET_WALLETUTIL_H
Parse
std::unique_ptr< Descriptor > Parse(const std::string &descriptor, FlatSigningProvider &out, std::string &error, bool require_checksum)
Parse a descriptor string.
Definition: descriptor.cpp:1394
wallet::FEATURE_BASE
@ FEATURE_BASE
Definition: walletutil.h:17
fs.h
wallet::WalletDescriptor::WalletDescriptor
WalletDescriptor()
Definition: walletutil.h:104
wallet::WalletDescriptor::range_start
int32_t range_start
Definition: walletutil.h:81
wallet::WalletDescriptor::creation_time
uint64_t creation_time
Definition: walletutil.h:80
wallet::FEATURE_NO_DEFAULT_KEY
@ FEATURE_NO_DEFAULT_KEY
Definition: walletutil.h:26
wallet::WALLET_FLAG_DESCRIPTORS
@ WALLET_FLAG_DESCRIPTORS
Indicate that this wallet supports DescriptorScriptPubKeyMan.
Definition: walletutil.h:66
wallet
Definition: node.h:38
wallet::WalletFlags
WalletFlags
Definition: walletutil.h:36
wallet::WalletDescriptor::WalletDescriptor
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:105
wallet::WalletDescriptor::DeserializeDescriptor
void DeserializeDescriptor(const std::string &str)
Definition: walletutil.h:86
wallet::WalletDescriptor::range_end
int32_t range_end
Definition: walletutil.h:82
wallet::FEATURE_COMPRPUBKEY
@ FEATURE_COMPRPUBKEY
Definition: walletutil.h:20
wallet::WALLET_FLAG_EXTERNAL_SIGNER
@ WALLET_FLAG_EXTERNAL_SIGNER
Indicates that the wallet needs an external signer.
Definition: walletutil.h:69
wallet::WalletFeature
WalletFeature
(client) version numbers for particular wallet features
Definition: walletutil.h:15
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
wallet::WalletDescriptor::SERIALIZE_METHODS
SERIALIZE_METHODS(WalletDescriptor, obj)
Definition: walletutil.h:96
wallet::WALLET_FLAG_BLANK_WALLET
@ WALLET_FLAG_BLANK_WALLET
Flag set when a wallet contains no HD seed and no private keys, scripts, addresses,...
Definition: walletutil.h:63
wallet::WALLET_FLAG_DISABLE_PRIVATE_KEYS
@ WALLET_FLAG_DISABLE_PRIVATE_KEYS
Definition: walletutil.h:51
wallet::WALLET_FLAG_AVOID_REUSE
@ WALLET_FLAG_AVOID_REUSE
Definition: walletutil.h:42
wallet::WALLET_FLAG_LAST_HARDENED_XPUB_CACHED
@ WALLET_FLAG_LAST_HARDENED_XPUB_CACHED
Definition: walletutil.h:48
READWRITE
#define READWRITE(...)
Definition: serialize.h:140
DescriptorCache
Cache for single descriptor's derived extended pubkeys.
Definition: descriptor.h:19
wallet::WALLET_FLAG_KEY_ORIGIN_METADATA
@ WALLET_FLAG_KEY_ORIGIN_METADATA
Definition: walletutil.h:45
wallet::FEATURE_PRE_SPLIT_KEYPOOL
@ FEATURE_PRE_SPLIT_KEYPOOL
Definition: walletutil.h:28
wallet::FEATURE_HD
@ FEATURE_HD
Definition: walletutil.h:22
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::WalletDescriptor::next_index
int32_t next_index
Definition: walletutil.h:83
wallet::WalletDescriptor::cache
DescriptorCache cache
Definition: walletutil.h:84
SER_WRITE
#define SER_WRITE(obj, code)
Definition: serialize.h:143
wallet::WalletDescriptor
Descriptor with some wallet metadata.
Definition: walletutil.h:76
error
bool error(const char *fmt, const Args &... args)
Definition: system.h:49
SER_READ
#define SER_READ(obj, code)
Definition: serialize.h:142
FlatSigningProvider
Definition: signingprovider.h:72
wallet::WalletDescriptor::descriptor
std::shared_ptr< Descriptor > descriptor
Definition: walletutil.h:79
descriptor.h
wallet::IsFeatureSupported
bool IsFeatureSupported(int wallet_version, int feature_version)
Definition: walletutil.cpp:33