Bitcoin Core  0.19.99
P2P Digital Currency
descriptor.h
Go to the documentation of this file.
1 // Copyright (c) 2018-2019 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #ifndef BITCOIN_SCRIPT_DESCRIPTOR_H
6 #define BITCOIN_SCRIPT_DESCRIPTOR_H
7 
8 #include <optional.h>
9 #include <outputtype.h>
10 #include <script/script.h>
11 #include <script/sign.h>
12 #include <script/signingprovider.h>
13 
14 #include <vector>
15 
16 
34 struct Descriptor {
35  virtual ~Descriptor() = default;
36 
38  virtual bool IsRange() const = 0;
39 
42  virtual bool IsSolvable() const = 0;
43 
45  virtual std::string ToString() const = 0;
46 
48  virtual bool ToPrivateString(const SigningProvider& provider, std::string& out) const = 0;
49 
58  virtual bool Expand(int pos, const SigningProvider& provider, std::vector<CScript>& output_scripts, FlatSigningProvider& out, std::vector<unsigned char>* cache = nullptr) const = 0;
59 
67  virtual bool ExpandFromCache(int pos, const std::vector<unsigned char>& cache, std::vector<CScript>& output_scripts, FlatSigningProvider& out) const = 0;
68 
75  virtual void ExpandPrivate(int pos, const SigningProvider& provider, FlatSigningProvider& out) const = 0;
76 
78  virtual Optional<OutputType> GetOutputType() const = 0;
79 };
80 
89 std::unique_ptr<Descriptor> Parse(const std::string& descriptor, FlatSigningProvider& out, std::string& error, bool require_checksum = false);
90 
97 std::string GetDescriptorChecksum(const std::string& descriptor);
98 
113 std::unique_ptr<Descriptor> InferDescriptor(const CScript& script, const SigningProvider& provider);
114 
115 #endif // BITCOIN_SCRIPT_DESCRIPTOR_H
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.
virtual Optional< OutputType > GetOutputType() const =0
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...
boost::optional< T > Optional
Substitute for C++17 std::optional.
Definition: optional.h:14
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:49
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:34