Bitcoin Core  0.18.99
P2P Digital Currency
Go to the documentation of this file.
1 // Copyright (c) 2018 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or
8 #include <script/script.h>
9 #include <script/sign.h>
11 #include <vector>
13 // Descriptors are strings that describe a set of scriptPubKeys, together with
14 // all information necessary to solve them. By combining all information into
15 // one, they avoid the need to separately import keys and scripts.
16 //
17 // Descriptors may be ranged, which occurs when the public keys inside are
18 // specified in the form of HD chains (xpubs).
19 //
20 // Descriptors always represent public information - public keys and scripts -
21 // but in cases where private keys need to be conveyed along with a descriptor,
22 // they can be included inside by changing public keys to private keys (WIF
23 // format), and changing xpubs by xprvs.
24 //
25 // Reference documentation about the descriptor language can be found in
26 // doc/
29 struct Descriptor {
30  virtual ~Descriptor() = default;
33  virtual bool IsRange() const = 0;
37  virtual bool IsSolvable() const = 0;
40  virtual std::string ToString() const = 0;
43  virtual bool ToPrivateString(const SigningProvider& provider, std::string& out) const = 0;
53  virtual bool Expand(int pos, const SigningProvider& provider, std::vector<CScript>& output_scripts, FlatSigningProvider& out, std::vector<unsigned char>* cache = nullptr) const = 0;
62  virtual bool ExpandFromCache(int pos, const std::vector<unsigned char>& cache, std::vector<CScript>& output_scripts, FlatSigningProvider& out) const = 0;
70  virtual void ExpandPrivate(int pos, const SigningProvider& provider, FlatSigningProvider& out) const = 0;
71 };
81 std::unique_ptr<Descriptor> Parse(const std::string& descriptor, FlatSigningProvider& out, bool require_checksum = false);
97 std::unique_ptr<Descriptor> InferDescriptor(const CScript& script, const SigningProvider& provider);
std::unique_ptr< Descriptor > Parse(const std::string &descriptor, FlatSigningProvider &out, bool require_checksum=false)
Parse a descriptor string.
Definition: descriptor.cpp:913
virtual bool IsSolvable() const =0
Whether this descriptor has all information about signing ignoring lack of private keys...
virtual ~Descriptor()=default
virtual std::string ToString() const =0
Convert the descriptor back to a string, undoing parsing.
virtual void ExpandPrivate(int pos, const SigningProvider &provider, FlatSigningProvider &out) const =0
Expand the private key for a descriptor at a specified position, if possible.
An interface to be implemented by keystores that support signing.
Definition: sign.h:49
virtual bool Expand(int pos, const SigningProvider &provider, std::vector< CScript > &output_scripts, FlatSigningProvider &out, std::vector< unsigned char > *cache=nullptr) const =0
Expand a descriptor at a specified position.
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:390
std::unique_ptr< Descriptor > InferDescriptor(const CScript &script, const SigningProvider &provider)
Find a descriptor for the specified script, using information from provider where possible...
Definition: descriptor.cpp:934
virtual bool IsRange() const =0
Whether the expansion of this descriptor depends on the position.
virtual bool ToPrivateString(const SigningProvider &provider, std::string &out) const =0
Convert the descriptor to a private string.
virtual bool ExpandFromCache(int pos, const std::vector< unsigned char > &cache, std::vector< CScript > &output_scripts, FlatSigningProvider &out) const =0
Expand a descriptor at a specified position using cached expansion data.
Interface for parsed descriptor objects.
Definition: descriptor.h:29