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>
10 #include <script/signingprovider.h>
12 #include <vector>
14 // Descriptors are strings that describe a set of scriptPubKeys, together with
15 // all information necessary to solve them. By combining all information into
16 // one, they avoid the need to separately import keys and scripts.
17 //
18 // Descriptors may be ranged, which occurs when the public keys inside are
19 // specified in the form of HD chains (xpubs).
20 //
21 // Descriptors always represent public information - public keys and scripts -
22 // but in cases where private keys need to be conveyed along with a descriptor,
23 // they can be included inside by changing public keys to private keys (WIF
24 // format), and changing xpubs by xprvs.
25 //
26 // Reference documentation about the descriptor language can be found in
27 // doc/
30 struct Descriptor {
31  virtual ~Descriptor() = default;
34  virtual bool IsRange() const = 0;
38  virtual bool IsSolvable() const = 0;
41  virtual std::string ToString() const = 0;
44  virtual bool ToPrivateString(const SigningProvider& provider, std::string& out) const = 0;
54  virtual bool Expand(int pos, const SigningProvider& provider, std::vector<CScript>& output_scripts, FlatSigningProvider& out, std::vector<unsigned char>* cache = nullptr) const = 0;
63  virtual bool ExpandFromCache(int pos, const std::vector<unsigned char>& cache, std::vector<CScript>& output_scripts, FlatSigningProvider& out) const = 0;
71  virtual void ExpandPrivate(int pos, const SigningProvider& provider, FlatSigningProvider& out) const = 0;
72 };
82 std::unique_ptr<Descriptor> Parse(const std::string& descriptor, FlatSigningProvider& out, std::string& error, bool require_checksum = false);
90 std::string GetDescriptorChecksum(const std::string& descriptor);
106 std::unique_ptr<Descriptor> InferDescriptor(const CScript& script, const SigningProvider& provider);
std::unique_ptr< Descriptor > Parse(const std::string &descriptor, FlatSigningProvider &out, std::string &error, bool require_checksum=false)
Parse a descriptor string.
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.
std::string GetDescriptorChecksum(const std::string &descriptor)
Get the checksum for a descriptor.
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...
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.
bool error(const char *fmt, const Args &... args)
Definition: system.h:47
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:30