Bitcoin ABC  0.22.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 
74 fs::path GetWalletDir();
75 
77 std::vector<fs::path> ListWalletDir();
78 
80 class WalletLocation final {
81  std::string m_name;
82  fs::path m_path;
83 
84 public:
85  explicit WalletLocation() {}
86  explicit WalletLocation(const std::string &name);
87 
89  const std::string &GetName() const { return m_name; }
90 
92  const fs::path &GetPath() const { return m_path; }
93 
95  bool Exists() const;
96 };
97 
100 public:
101  std::shared_ptr<Descriptor> descriptor;
102  uint64_t creation_time;
103  int32_t range_start; // First item in range; start of range, inclusive, i.e.
104  // [range_start, range_end). This never changes.
105  int32_t range_end; // Item after the last; end of range, exclusive, i.e.
106  // [range_start, range_end). This will increment with
107  // each TopUp()
108  int32_t next_index; // Position of the next item to generate
110 
112 
113  template <typename Stream, typename Operation>
114  inline void SerializationOp(Stream &s, Operation ser_action) {
115  if (ser_action.ForRead()) {
116  std::string desc;
117  std::string error;
118  READWRITE(desc);
119  FlatSigningProvider keys;
120  descriptor = Parse(desc, keys, error, true);
121  if (!descriptor) {
122  throw std::ios_base::failure("Invalid descriptor: " + error);
123  }
124  } else {
125  READWRITE(descriptor->ToString());
126  }
127  READWRITE(creation_time);
128  READWRITE(next_index);
129  READWRITE(range_start);
130  READWRITE(range_end);
131  }
132 
134  WalletDescriptor(std::shared_ptr<Descriptor> descriptor_,
135  uint64_t creation_time_, int32_t range_start_,
136  int32_t range_end_, int32_t next_index_)
137  : descriptor(descriptor_), creation_time(creation_time_),
138  range_start(range_start_), range_end(range_end_),
139  next_index(next_index_) {}
140 };
141 
142 #endif // BITCOIN_WALLET_WALLETUTIL_H
const fs::path & GetPath() const
Get wallet absolute path.
Definition: walletutil.h:92
fs::path GetWalletDir()
Get the path of the wallet directory.
Definition: dummywallet.cpp:45
int32_t next_index
Definition: walletutil.h:108
fs::path m_path
Definition: walletutil.h:82
std::shared_ptr< Descriptor > descriptor
Definition: walletutil.h:101
std::vector< fs::path > ListWalletDir()
Get wallets in wallet directory.
Definition: dummywallet.cpp:49
void SerializationOp(Stream &s, Operation ser_action)
Definition: walletutil.h:114
int32_t range_end
Definition: walletutil.h:105
bool Exists() const
Return whether the wallet exists.
Definition: walletutil.cpp:114
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.
int32_t range_start
Definition: walletutil.h:103
std::string m_name
Definition: walletutil.h:81
const std::string & GetName() const
Get wallet name.
Definition: walletutil.h:89
const char * name
Definition: rest.cpp:43
DescriptorCache cache
Definition: walletutil.h:109
uint64_t creation_time
Definition: walletutil.h:102
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:67
Descriptor with some wallet metadata.
Definition: walletutil.h:99
Cache for single descriptor&#39;s derived extended pubkeys.
Definition: descriptor.h:18
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:134
WalletFlags
Definition: walletutil.h:39
The WalletLocation class provides wallet information.
Definition: walletutil.h:80
Indicate that this wallet supports DescriptorScriptPubKeyMan.
Definition: walletutil.h:70
#define READWRITE(...)
Definition: serialize.h:191
bool error(const char *fmt, const Args &... args)
Definition: system.h:47