mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-08 10:31:50 -05:00
Introduce WalletDescriptor class
WalletDescriptor is a Descriptor with other wallet metadata
This commit is contained in:
parent
6b13cd3fa8
commit
3194a7f88a
2 changed files with 59 additions and 0 deletions
|
@ -637,4 +637,25 @@ BOOST_FIXTURE_TEST_CASE(dummy_input_size_test, TestChain100Setup)
|
|||
BOOST_CHECK_EQUAL(CalculateNestedKeyhashInputSize(true), DUMMY_NESTED_P2WPKH_INPUT_SIZE);
|
||||
}
|
||||
|
||||
bool malformed_descriptor(std::ios_base::failure e)
|
||||
{
|
||||
std::string s(e.what());
|
||||
return s.find("Missing checksum") != std::string::npos;
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(wallet_descriptor_test, BasicTestingSetup)
|
||||
{
|
||||
std::vector<unsigned char> malformed_record;
|
||||
CVectorWriter vw(0, 0, malformed_record, 0);
|
||||
vw << std::string("notadescriptor");
|
||||
vw << (uint64_t)0;
|
||||
vw << (int32_t)0;
|
||||
vw << (int32_t)0;
|
||||
vw << (int32_t)1;
|
||||
|
||||
VectorReader vr(0, 0, malformed_record, 0);
|
||||
WalletDescriptor w_desc;
|
||||
BOOST_CHECK_EXCEPTION(vr >> w_desc, std::ios_base::failure, malformed_descriptor);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#define BITCOIN_WALLET_WALLETUTIL_H
|
||||
|
||||
#include <fs.h>
|
||||
#include <script/descriptor.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
|
@ -86,4 +87,41 @@ public:
|
|||
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
|
||||
|
|
Loading…
Add table
Reference in a new issue