2019-12-30 06:39:22 -03:00
|
|
|
// Copyright (c) 2017-2019 The Bitcoin Core developers
|
2017-10-08 17:48:07 -03:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
2018-03-22 11:19:44 -03:00
|
|
|
#ifndef BITCOIN_WALLET_WALLETUTIL_H
|
|
|
|
#define BITCOIN_WALLET_WALLETUTIL_H
|
2017-10-08 17:48:07 -03:00
|
|
|
|
2018-09-21 20:24:29 -03:00
|
|
|
#include <fs.h>
|
2020-02-28 21:14:12 -03:00
|
|
|
#include <script/descriptor.h>
|
2018-09-21 20:24:29 -03:00
|
|
|
|
|
|
|
#include <vector>
|
2017-10-08 17:48:07 -03:00
|
|
|
|
2019-06-20 17:34:33 -04:00
|
|
|
/** (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 = 130000, // Hierarchical key derivation after BIP32 (HD Wallet)
|
|
|
|
|
|
|
|
FEATURE_HD_SPLIT = 139900, // Wallet with HD chain split (change outputs will use m/0'/1'/k)
|
|
|
|
|
|
|
|
FEATURE_NO_DEFAULT_KEY = 159900, // Wallet without a default key written
|
|
|
|
|
|
|
|
FEATURE_PRE_SPLIT_KEYPOOL = 169900, // Upgraded to HD SPLIT and can have a pre-split keypool
|
|
|
|
|
|
|
|
FEATURE_LATEST = FEATURE_PRE_SPLIT_KEYPOOL
|
|
|
|
};
|
|
|
|
|
2020-04-29 14:48:43 -04:00
|
|
|
bool IsFeatureSupported(int wallet_version, int feature_version);
|
2020-04-29 16:58:12 -04:00
|
|
|
WalletFeature GetClosestWalletFeature(int version);
|
2019-06-20 17:34:33 -04:00
|
|
|
|
|
|
|
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),
|
|
|
|
|
|
|
|
// 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),
|
2019-07-05 22:32:59 -04:00
|
|
|
|
|
|
|
//! Indicate that this wallet supports DescriptorScriptPubKeyMan
|
|
|
|
WALLET_FLAG_DESCRIPTORS = (1ULL << 34),
|
2019-06-20 17:34:33 -04:00
|
|
|
};
|
|
|
|
|
2017-10-08 17:48:07 -03:00
|
|
|
//! Get the path of the wallet directory.
|
|
|
|
fs::path GetWalletDir();
|
|
|
|
|
2018-09-21 20:24:29 -03:00
|
|
|
//! Get wallets in wallet directory.
|
|
|
|
std::vector<fs::path> ListWalletDir();
|
|
|
|
|
2020-02-28 21:14:12 -03:00
|
|
|
/** Descriptor with some wallet metadata */
|
|
|
|
class WalletDescriptor
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
std::shared_ptr<Descriptor> descriptor;
|
2020-04-27 10:20:26 -04:00
|
|
|
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
|
2020-02-28 21:14:12 -03:00
|
|
|
DescriptorCache cache;
|
|
|
|
|
2020-05-24 13:34:52 -04:00
|
|
|
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);
|
2020-02-28 21:14:12 -03:00
|
|
|
}
|
2020-05-24 13:34:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
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));
|
2020-02-28 21:14:12 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
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), creation_time(creation_time), range_start(range_start), range_end(range_end), next_index(next_index) {}
|
|
|
|
};
|
|
|
|
|
2018-03-22 11:19:44 -03:00
|
|
|
#endif // BITCOIN_WALLET_WALLETUTIL_H
|