forked from bitcoin/bitcoin
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathwalletutil.h
More file actions
131 lines (108 loc) · 5.56 KB
/
Copy pathwalletutil.h
File metadata and controls
131 lines (108 loc) · 5.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// Copyright (c) 2017-2021 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef BITCOIN_WALLET_WALLETUTIL_H
#define BITCOIN_WALLET_WALLETUTIL_H
#include <fs.h>
#include <script/descriptor.h>
#include <support/allocators/secure.h>
#include <vector>
namespace wallet {
/** (client) version numbers for particular wallet features */
enum WalletFeature
{
FEATURE_BASE = 10500, // the earliest version new wallets supports (only useful for getwalletinfo's clientversion output)
FEATURE_WALLETCRYPT = 40000, // wallet encryption
FEATURE_COMPRPUBKEY = 60000, // compressed public keys
FEATURE_HD = 120200, // Hierarchical key derivation after BIP32 (HD Wallet), BIP44 (multi-coin), BIP39 (mnemonic)
// which uses on-the-fly private key derivation
FEATURE_LATEST = FEATURE_HD
};
bool IsFeatureSupported(int wallet_version, int feature_version);
WalletFeature GetClosestWalletFeature(int version);
enum WalletFlags : uint64_t {
// wallet flags in the upper section (> 1 << 31) will lead to not opening the wallet if flag is unknown
// unknown wallet flags in the lower section <= (1 << 31) will be tolerated
// will categorize coins as clean (not reused) and dirty (reused), and handle
// them with privacy considerations in mind
WALLET_FLAG_AVOID_REUSE = (1ULL << 0),
// Indicates that the metadata has already been upgraded to contain key origins
WALLET_FLAG_KEY_ORIGIN_METADATA = (1ULL << 1),
// Indicates that the descriptor cache has been upgraded to cache last hardened xpubs
WALLET_FLAG_LAST_HARDENED_XPUB_CACHED = (1ULL << 2),
// will enforce the rule that the wallet can't contain any private keys (only watch-only/pubkeys)
WALLET_FLAG_DISABLE_PRIVATE_KEYS = (1ULL << 32),
//! Flag set when a wallet contains no HD seed and no private keys, scripts,
//! addresses, and other watch only things, and is therefore "blank."
//!
//! The only function this flag serves is to distinguish a blank wallet from
//! a newly created wallet when the wallet database is loaded, to avoid
//! initialization that should only happen on first run.
//!
//! This flag is also a mandatory flag to prevent previous versions of
//! bitcoin from opening the wallet, thinking it was newly created, and
//! then improperly reinitializing it.
WALLET_FLAG_BLANK_WALLET = (1ULL << 33),
//! Indicate that this wallet supports DescriptorScriptPubKeyMan
WALLET_FLAG_DESCRIPTORS = (1ULL << 34),
//! Indicates that the wallet needs an external signer
WALLET_FLAG_EXTERNAL_SIGNER = (1ULL << 35),
};
//! Get the path of the wallet directory.
fs::path GetWalletDir();
/** Descriptor with some wallet metadata */
class WalletDescriptor
{
public:
std::shared_ptr<Descriptor> descriptor;
uint256 id; // Descriptor ID (calculated once at descriptor initialization/deserialization)
uint64_t creation_time = 0;
int32_t range_start = 0; // First item in range; start of range, inclusive, i.e. [range_start, range_end). This never changes.
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()
int32_t next_index = 0; // Position of the next item to generate
DescriptorCache cache;
void DeserializeDescriptor(const std::string& str)
{
std::string error;
FlatSigningProvider keys;
descriptor = Parse(str, keys, error, true);
if (!descriptor) {
throw std::ios_base::failure("Invalid descriptor: " + error);
}
id = DescriptorID(*descriptor);
}
SERIALIZE_METHODS(WalletDescriptor, obj)
{
std::string descriptor_str;
SER_WRITE(obj, descriptor_str = obj.descriptor->ToString());
READWRITE(descriptor_str, obj.creation_time, obj.next_index, obj.range_start, obj.range_end);
SER_READ(obj, obj.DeserializeDescriptor(descriptor_str));
}
WalletDescriptor() {}
WalletDescriptor(std::shared_ptr<Descriptor> descriptor, uint64_t creation_time, int32_t range_start, int32_t range_end, int32_t next_index) : descriptor(descriptor), id(DescriptorID(*descriptor)), creation_time(creation_time), range_start(range_start), range_end(range_end), next_index(next_index) { }
};
class CWallet;
class DescriptorScriptPubKeyMan;
/** struct containing information needed for migrating legacy wallets to descriptor wallets */
struct MigrationData
{
CExtKey master_key;
SecureString mnemonic;
SecureString mnemonic_passphrase;
// Highest BIP44 index the legacy wallet ever derived per chain (external/0,
// internal/1). The active pkh() descriptors created during migration must
// start handing out the next address from this index, otherwise post-
// migration getnewaddress would re-derive addresses the legacy wallet had
// already given out. Carried via MigrationData purely to advance the active
// descriptors' next_index — the inactive combo descriptors built in
// MigrateToDescriptor already cover the history themselves.
uint32_t external_chain_counter{0};
uint32_t internal_chain_counter{0};
std::vector<std::pair<std::string, int64_t>> watch_descs;
std::vector<std::pair<std::string, int64_t>> solvable_descs;
std::vector<std::unique_ptr<DescriptorScriptPubKeyMan>> desc_spkms;
std::shared_ptr<CWallet> watchonly_wallet{nullptr};
std::shared_ptr<CWallet> solvable_wallet{nullptr};
};
} // namespace wallet
#endif // BITCOIN_WALLET_WALLETUTIL_H