Bitcoin Core
32.1.0
P2P Digital Currency
Toggle main menu visibility
Loading...
Searching...
No Matches
src
wallet
walletutil.h
Go to the documentation of this file.
1
// Copyright (c) 2017-present 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 <
script/descriptor.h
>
9
#include <
util/fs.h
>
10
11
#include <vector>
12
13
namespace
wallet
{
14
15
enum
WalletFlags
: uint64_t {
16
// wallet flags in the upper section (> 1 << 31) will lead to not opening the wallet if flag is unknown
17
// unknown wallet flags in the lower section <= (1 << 31) will be tolerated
18
19
// will categorize coins as clean (not reused) and dirty (reused), and handle
20
// them with privacy considerations in mind
21
WALLET_FLAG_AVOID_REUSE
= (1ULL << 0),
22
23
// Indicates that the metadata has already been upgraded to contain key origins
24
WALLET_FLAG_KEY_ORIGIN_METADATA
= (1ULL << 1),
25
26
// Indicates that the descriptor cache has been upgraded to cache last hardened xpubs
27
WALLET_FLAG_LAST_HARDENED_XPUB_CACHED
= (1ULL << 2),
28
29
// will enforce the rule that the wallet can't contain any private keys (only watch-only/pubkeys)
30
WALLET_FLAG_DISABLE_PRIVATE_KEYS
= (1ULL << 32),
31
50
WALLET_FLAG_BLANK_WALLET
= (1ULL << 33),
51
53
WALLET_FLAG_DESCRIPTORS
= (1ULL << 34),
54
56
WALLET_FLAG_EXTERNAL_SIGNER
= (1ULL << 35),
57
};
58
60
fs::path
GetWalletDir
();
61
63
class
WalletDescriptor
64
{
65
private
:
66
int32_t
range_start
= 0;
// First item in range; start of range, inclusive, i.e. [range_start, range_end). This never changes.
67
int32_t
next_index
= 0;
// Position of the next item to generate
68
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()
69
70
mutable
std::optional<uint256>
m_canonical_hash
;
// Hash of the canonical string, used as a shortcut for comparing canonical strings
71
72
uint256
GetCanonicalHash
()
const
;
73
74
public
:
75
const
std::shared_ptr<const Descriptor>
descriptor
;
76
uint64_t
creation_time
= 0;
77
DescriptorCache
cache
;
78
79
int32_t
GetStart
()
const
{
return
range_start
; }
80
int32_t
GetNext
()
const
{
return
next_index
; }
81
int32_t
GetEnd
()
const
{
return
range_end
; }
82
84
void
IncNext
()
85
{
86
next_index
++;
87
}
88
90
void
DecNext
()
91
{
92
next_index
--;
93
}
94
96
void
SetEnd
(int32_t end)
97
{
98
if
(!
descriptor
->IsRange()) {
99
CHECK_NONFATAL
(end == 1);
100
}
101
range_end
= end;
102
}
103
104
template
<
typename
Stream>
105
void
Serialize
(Stream& s)
const
106
{
107
std::string descriptor_str =
descriptor
->ToString();
108
s << descriptor_str <<
creation_time
<<
next_index
<<
range_start
<<
range_end
;
109
}
110
111
template
<
typename
Stream>
112
static
WalletDescriptor
FromStream
(
deserialize_type
, Stream& s)
113
{
114
std::string descriptor_str;
115
uint64_t
creation_time
;
116
int32_t
next_index
,
range_start
,
range_end
;
117
s >> descriptor_str >>
creation_time
>>
next_index
>>
range_start
>>
range_end
;
118
119
std::string error;
120
FlatSigningProvider
keys
;
121
auto
descs =
Parse
(descriptor_str,
keys
, error,
true
);
122
if
(descs.empty()) {
123
throw
std::ios_base::failure(
"Invalid descriptor: "
+ error);
124
}
125
if
(descs.size() > 1) {
126
throw
std::ios_base::failure(
"Can't load a multipath descriptor from databases"
);
127
}
128
return
WalletDescriptor
(std::move(descs.at(0)),
creation_time
,
range_start
,
range_end
,
next_index
);
129
}
130
131
WalletDescriptor
() =
delete
;
132
WalletDescriptor
(std::shared_ptr<Descriptor>
descriptor
, uint64_t
creation_time
, int32_t
range_start
, int32_t
range_end
, int32_t
next_index
)
133
:
range_start
(
descriptor
->IsRange() ?
range_start
: 0),
134
next_index
(
next_index
),
135
range_end
(
descriptor
->IsRange() ?
range_end
: 1),
136
descriptor
(
descriptor
),
137
creation_time
(
creation_time
)
138
{}
139
144
void
UpdateFrom
(
const
WalletDescriptor
& other);
145
146
// Compare by using the canonical string to make the hardened indicators consistent for comparison
147
bool
IsCanonicallyEquivalent
(
const
WalletDescriptor
& other)
const
;
148
};
149
150
WalletDescriptor
GenerateWalletDescriptor
(
const
CExtPubKey
& master_key,
const
OutputType
& output_type,
bool
internal);
151
}
// namespace wallet
152
153
#endif
// BITCOIN_WALLET_WALLETUTIL_H
CHECK_NONFATAL
#define CHECK_NONFATAL(condition)
Identity function.
Definition
check.h:112
DescriptorCache
Cache for single descriptor's derived extended pubkeys.
Definition
descriptor.h:29
WalletDescriptor
Descriptor with some wallet metadata.
Definition
walletutil.h:64
uint256
256-bit opaque blob.
Definition
uint256.h:196
wallet::WalletDescriptor
Descriptor with some wallet metadata.
Definition
walletutil.h:64
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:132
wallet::WalletDescriptor::GetStart
int32_t GetStart() const
Definition
walletutil.h:79
wallet::WalletDescriptor::GetCanonicalHash
uint256 GetCanonicalHash() const
Definition
walletutil.cpp:100
wallet::WalletDescriptor::m_canonical_hash
std::optional< uint256 > m_canonical_hash
Definition
walletutil.h:70
wallet::WalletDescriptor::FromStream
static WalletDescriptor FromStream(deserialize_type, Stream &s)
Definition
walletutil.h:112
wallet::WalletDescriptor::next_index
int32_t next_index
Definition
walletutil.h:67
wallet::WalletDescriptor::Serialize
void Serialize(Stream &s) const
Definition
walletutil.h:105
wallet::WalletDescriptor::WalletDescriptor
WalletDescriptor()=delete
wallet::WalletDescriptor::IsCanonicallyEquivalent
bool IsCanonicallyEquivalent(const WalletDescriptor &other) const
Definition
walletutil.cpp:110
wallet::WalletDescriptor::GetNext
int32_t GetNext() const
Definition
walletutil.h:80
wallet::WalletDescriptor::IncNext
void IncNext()
Increments the next_index of the descriptor.
Definition
walletutil.h:84
wallet::WalletDescriptor::SetEnd
void SetEnd(int32_t end)
Sets the range_end of the descriptor.
Definition
walletutil.h:96
wallet::WalletDescriptor::range_start
int32_t range_start
Definition
walletutil.h:66
wallet::WalletDescriptor::range_end
int32_t range_end
Definition
walletutil.h:68
wallet::WalletDescriptor::GetEnd
int32_t GetEnd() const
Definition
walletutil.h:81
wallet::WalletDescriptor::DecNext
void DecNext()
Increments the next_index of the descriptor.
Definition
walletutil.h:90
wallet::WalletDescriptor::descriptor
const std::shared_ptr< const Descriptor > descriptor
Definition
walletutil.h:75
wallet::WalletDescriptor::creation_time
uint64_t creation_time
Definition
walletutil.h:76
wallet::WalletDescriptor::UpdateFrom
void UpdateFrom(const WalletDescriptor &other)
Replaces all metadata (range, start, end, creation time), and cache from another WalletDescriptor if ...
Definition
walletutil.cpp:88
wallet::WalletDescriptor::cache
DescriptorCache cache
Definition
walletutil.h:77
fs.h
wallet
Definition
coin_selection.cpp:31
wallet::GetWalletDir
fs::path GetWalletDir()
Get the path of the wallet directory.
Definition
walletutil.cpp:13
wallet::WalletFlags
WalletFlags
Definition
walletutil.h:15
wallet::WALLET_FLAG_EXTERNAL_SIGNER
@ WALLET_FLAG_EXTERNAL_SIGNER
Indicates that the wallet needs an external signer.
Definition
walletutil.h:56
wallet::WALLET_FLAG_LAST_HARDENED_XPUB_CACHED
@ WALLET_FLAG_LAST_HARDENED_XPUB_CACHED
Definition
walletutil.h:27
wallet::WALLET_FLAG_KEY_ORIGIN_METADATA
@ WALLET_FLAG_KEY_ORIGIN_METADATA
Definition
walletutil.h:24
wallet::WALLET_FLAG_AVOID_REUSE
@ WALLET_FLAG_AVOID_REUSE
Definition
walletutil.h:21
wallet::WALLET_FLAG_DESCRIPTORS
@ WALLET_FLAG_DESCRIPTORS
Indicate that this wallet supports DescriptorScriptPubKeyMan.
Definition
walletutil.h:53
wallet::WALLET_FLAG_DISABLE_PRIVATE_KEYS
@ WALLET_FLAG_DISABLE_PRIVATE_KEYS
Definition
walletutil.h:30
wallet::WALLET_FLAG_BLANK_WALLET
@ WALLET_FLAG_BLANK_WALLET
Definition
walletutil.h:50
wallet::GenerateWalletDescriptor
WalletDescriptor GenerateWalletDescriptor(const CExtPubKey &master_key, const OutputType &addr_type, bool internal)
Definition
walletutil.cpp:35
OutputType
OutputType
Definition
outputtype.h:18
Parse
std::vector< std::unique_ptr< Descriptor > > Parse(std::string_view descriptor, FlatSigningProvider &out, std::string &error, bool require_checksum)
Parse a descriptor string.
Definition
descriptor.cpp:2994
descriptor.h
CExtPubKey
Definition
pubkey.h:342
FlatSigningProvider
Definition
signingprovider.h:235
deserialize_type
Dummy data type to identify deserializing constructors.
Definition
serialize.h:51
keys
std::vector< uint16_t > keys
Definition
dbwrapper.cpp:376
Generated on
for Bitcoin Core by
1.18.0