Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/walletutil.h
// Copyright (c) 2017 The Bitcoin Core developers | // Copyright (c) 2017 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#ifndef BITCOIN_WALLET_WALLETUTIL_H | #ifndef BITCOIN_WALLET_WALLETUTIL_H | ||||
#define BITCOIN_WALLET_WALLETUTIL_H | #define BITCOIN_WALLET_WALLETUTIL_H | ||||
#include <fs.h> | #include <fs.h> | ||||
#include <script/descriptor.h> | |||||
#include <vector> | #include <vector> | ||||
/** (client) version numbers for particular wallet features */ | /** (client) version numbers for particular wallet features */ | ||||
enum WalletFeature { | enum WalletFeature { | ||||
// the earliest version new wallets supports (only useful for | // the earliest version new wallets supports (only useful for | ||||
// getwalletinfo's clientversion output) | // getwalletinfo's clientversion output) | ||||
FEATURE_BASE = 10500, | FEATURE_BASE = 10500, | ||||
▲ Show 20 Lines • Show All 72 Lines • ▼ Show 20 Lines | public: | ||||
//! Get wallet absolute path. | //! Get wallet absolute path. | ||||
const fs::path &GetPath() const { return m_path; } | const fs::path &GetPath() const { return m_path; } | ||||
//! Return whether the wallet exists. | //! Return whether the wallet exists. | ||||
bool Exists() const; | bool Exists() const; | ||||
}; | }; | ||||
/** Descriptor with some wallet metadata */ | |||||
class WalletDescriptor { | |||||
public: | |||||
std::shared_ptr<Descriptor> descriptor; | |||||
uint64_t creation_time; | |||||
int32_t range_start; // First item in range; start of range, inclusive, i.e. | |||||
// [range_start, range_end). This never changes. | |||||
int32_t range_end; // Item after the last; end of range, exclusive, i.e. | |||||
// [range_start, range_end). This will increment with | |||||
// each TopUp() | |||||
int32_t next_index; // Position of the next item to generate | |||||
DescriptorCache cache; | |||||
ADD_SERIALIZE_METHODS; | |||||
template <typename Stream, typename Operation> | |||||
inline void SerializationOp(Stream &s, Operation ser_action) { | |||||
if (ser_action.ForRead()) { | |||||
std::string desc; | |||||
std::string error; | |||||
READWRITE(desc); | |||||
FlatSigningProvider keys; | |||||
descriptor = Parse(desc, keys, error, true); | |||||
if (!descriptor) { | |||||
throw std::ios_base::failure("Invalid descriptor: " + error); | |||||
} | |||||
} else { | |||||
READWRITE(descriptor->ToString()); | |||||
} | |||||
READWRITE(creation_time); | |||||
READWRITE(next_index); | |||||
READWRITE(range_start); | |||||
READWRITE(range_end); | |||||
} | |||||
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_) {} | |||||
}; | |||||
#endif // BITCOIN_WALLET_WALLETUTIL_H | #endif // BITCOIN_WALLET_WALLETUTIL_H |