Bitcoin ABC  0.28.12
P2P Digital Currency
walletutil.h
Go to the documentation of this file.
1 // Copyright (c) 2017 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  // the earliest version new wallets supports (only useful for
16  // getwalletinfo's clientversion output)
17  FEATURE_BASE = 10500,
18 
19  // wallet encryption
21  // compressed public keys
23 
24  // Hierarchical key derivation after BIP32 (HD Wallet)
25  FEATURE_HD = 130000,
26 
27  // Wallet with HD chain split (change outputs will use m/0'/1'/k)
28  FEATURE_HD_SPLIT = 160300,
29 
30  // Wallet without a default key written
32 
33  // Upgraded to HD SPLIT and can have a pre-split keypool
35 
37 };
38 
39 enum WalletFlags : uint64_t {
40  // Wallet flags in the upper section (> 1 << 31) will lead to not opening
41  // the wallet if flag is unknown.
42  // Unknown wallet flags in the lower section <= (1 << 31) will be tolerated.
43 
44  // will categorize coins as clean (not reused) and dirty (reused), and
45  // handle
46  // them with privacy considerations in mind
47  WALLET_FLAG_AVOID_REUSE = (1ULL << 0),
48 
49  // Indicates that the metadata has already been upgraded to contain key
50  // origins
52 
53  // Will enforce the rule that the wallet can't contain any private keys
54  // (only watch-only/pubkeys).
56 
67  WALLET_FLAG_BLANK_WALLET = (1ULL << 33),
68 
70  WALLET_FLAG_DESCRIPTORS = (1ULL << 34),
71 };
72 
75 
77 std::vector<fs::path> ListWalletDir();
78 
81 public:
82  std::shared_ptr<Descriptor> descriptor;
83  uint64_t creation_time = 0;
84  // First item in range; start of range, inclusive, i.e.
85  // [range_start, range_end). This never changes.
86  int32_t range_start = 0;
87  // Item after the last; end of range, exclusive, i.e.
88  // [range_start, range_end). This will increment with each TopUp()
89  int32_t range_end = 0;
90  // Position of the next item to generate
91  int32_t next_index = 0;
93 
94  void DeserializeDescriptor(const std::string &str) {
95  std::string error;
97  descriptor = Parse(str, keys, error, true);
98  if (!descriptor) {
99  throw std::ios_base::failure("Invalid descriptor: " + error);
100  }
101  }
102 
104  std::string descriptor_str;
105  SER_WRITE(obj, descriptor_str = obj.descriptor->ToString());
106  READWRITE(descriptor_str, obj.creation_time, obj.next_index,
107  obj.range_start, obj.range_end);
108  SER_READ(obj, obj.DeserializeDescriptor(descriptor_str));
109  }
110 
112  WalletDescriptor(std::shared_ptr<Descriptor> descriptor_,
113  uint64_t creation_time_, int32_t range_start_,
114  int32_t range_end_, int32_t next_index_)
115  : descriptor(descriptor_), creation_time(creation_time_),
116  range_start(range_start_), range_end(range_end_),
117  next_index(next_index_) {}
118 };
119 
120 #endif // BITCOIN_WALLET_WALLETUTIL_H
Cache for single descriptor's derived extended pubkeys.
Definition: descriptor.h:19
Descriptor with some wallet metadata.
Definition: walletutil.h:80
int32_t range_end
Definition: walletutil.h:89
DescriptorCache cache
Definition: walletutil.h:92
SERIALIZE_METHODS(WalletDescriptor, obj)
Definition: walletutil.h:103
void DeserializeDescriptor(const std::string &str)
Definition: walletutil.h:94
int32_t next_index
Definition: walletutil.h:91
int32_t range_start
Definition: walletutil.h:86
uint64_t creation_time
Definition: walletutil.h:83
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:112
std::shared_ptr< Descriptor > descriptor
Definition: walletutil.h:82
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
Definition: fs.h:30
std::unique_ptr< Descriptor > Parse(const std::string &descriptor, FlatSigningProvider &out, std::string &error, bool require_checksum)
Parse a descriptor string.
#define SER_WRITE(obj, code)
Definition: serialize.h:187
#define SER_READ(obj, code)
Definition: serialize.h:183
#define READWRITE(...)
Definition: serialize.h:180
bool error(const char *fmt, const Args &...args)
Definition: system.h:45
std::vector< fs::path > ListWalletDir()
Get wallets in wallet directory.
Definition: walletutil.cpp:70
WalletFlags
Definition: walletutil.h:39
@ WALLET_FLAG_DISABLE_PRIVATE_KEYS
Definition: walletutil.h:55
@ WALLET_FLAG_AVOID_REUSE
Definition: walletutil.h:47
@ WALLET_FLAG_KEY_ORIGIN_METADATA
Definition: walletutil.h:51
@ WALLET_FLAG_DESCRIPTORS
Indicate that this wallet supports DescriptorScriptPubKeyMan.
Definition: walletutil.h:70
@ WALLET_FLAG_BLANK_WALLET
Flag set when a wallet contains no HD seed and no private keys, scripts, addresses,...
Definition: walletutil.h:67
WalletFeature
(client) version numbers for particular wallet features
Definition: walletutil.h:14
@ FEATURE_HD_SPLIT
Definition: walletutil.h:28
@ FEATURE_WALLETCRYPT
Definition: walletutil.h:20
@ FEATURE_NO_DEFAULT_KEY
Definition: walletutil.h:31
@ FEATURE_PRE_SPLIT_KEYPOOL
Definition: walletutil.h:34
@ FEATURE_BASE
Definition: walletutil.h:17
@ FEATURE_HD
Definition: walletutil.h:25
@ FEATURE_LATEST
Definition: walletutil.h:36
@ FEATURE_COMPRPUBKEY
Definition: walletutil.h:22
fs::path GetWalletDir()
Get the path of the wallet directory.
Definition: walletutil.cpp:13