Bitcoin Core
31.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
public
:
66
std::shared_ptr<Descriptor>
descriptor
;
67
uint256
id
;
// Descriptor ID (calculated once at descriptor initialization/deserialization)
68
uint64_t
creation_time
= 0;
69
int32_t
range_start
= 0;
// First item in range; start of range, inclusive, i.e. [range_start, range_end). This never changes.
70
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()
71
int32_t
next_index
= 0;
// Position of the next item to generate
72
DescriptorCache
cache
;
73
74
void
DeserializeDescriptor
(
const
std::string& str)
75
{
76
std::string error;
77
FlatSigningProvider
keys;
78
auto
descs =
Parse
(str, keys, error,
true
);
79
if
(descs.empty()) {
80
throw
std::ios_base::failure(
"Invalid descriptor: "
+ error);
81
}
82
if
(descs.size() > 1) {
83
throw
std::ios_base::failure(
"Can't load a multipath descriptor from databases"
);
84
}
85
descriptor
= std::move(descs.at(0));
86
id
=
DescriptorID
(*
descriptor
);
87
}
88
89
SERIALIZE_METHODS
(
WalletDescriptor
, obj)
90
{
91
std::string descriptor_str;
92
SER_WRITE
(obj, descriptor_str = obj.descriptor->ToString());
93
READWRITE
(descriptor_str, obj.creation_time, obj.next_index, obj.range_start, obj.range_end);
94
SER_READ
(obj, obj.DeserializeDescriptor(descriptor_str));
95
}
96
97
WalletDescriptor
() =
default
;
98
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
) { }
99
};
100
101
WalletDescriptor
GenerateWalletDescriptor
(
const
CExtPubKey
& master_key,
const
OutputType
& output_type,
bool
internal);
102
}
// namespace wallet
103
104
#endif
// BITCOIN_WALLET_WALLETUTIL_H
DescriptorCache
Cache for single descriptor's derived extended pubkeys.
Definition
descriptor.h:19
WalletDescriptor
Descriptor with some wallet metadata.
Definition
walletutil.h:64
uint256
256-bit opaque blob.
Definition
uint256.h:195
wallet::WalletDescriptor::WalletDescriptor
WalletDescriptor()=default
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:98
wallet::WalletDescriptor::next_index
int32_t next_index
Definition
walletutil.h:71
wallet::WalletDescriptor::DeserializeDescriptor
void DeserializeDescriptor(const std::string &str)
Definition
walletutil.h:74
wallet::WalletDescriptor::range_start
int32_t range_start
Definition
walletutil.h:69
wallet::WalletDescriptor::range_end
int32_t range_end
Definition
walletutil.h:70
wallet::WalletDescriptor::SERIALIZE_METHODS
SERIALIZE_METHODS(WalletDescriptor, obj)
Definition
walletutil.h:89
wallet::WalletDescriptor::descriptor
std::shared_ptr< Descriptor > descriptor
Definition
walletutil.h:66
wallet::WalletDescriptor::id
uint256 id
Definition
walletutil.h:67
wallet::WalletDescriptor::creation_time
uint64_t creation_time
Definition
walletutil.h:68
wallet::WalletDescriptor::cache
DescriptorCache cache
Definition
walletutil.h:72
Parse
static UniValue Parse(std::string_view raw, ParamFormat format=ParamFormat::JSON)
Parse string to UniValue or throw runtime_error if string contains invalid JSON.
Definition
client.cpp:395
fs.h
wallet
Definition
wallet_balance.cpp:26
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
DescriptorID
uint256 DescriptorID(const Descriptor &desc)
Unique identifier that may not change over time, unless explicitly marked as not backwards compatible...
Definition
descriptor.cpp:2902
descriptor.h
SER_WRITE
#define SER_WRITE(obj, code)
Definition
serialize.h:147
SER_READ
#define SER_READ(obj, code)
Definition
serialize.h:146
READWRITE
#define READWRITE(...)
Definition
serialize.h:145
CExtPubKey
Definition
pubkey.h:336
FlatSigningProvider
Definition
signingprovider.h:224
Generated on
for Bitcoin Core by
1.17.0