Bitcoin ABC  0.22.13
P2P Digital Currency
descriptor.h
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 http://www.opensource.org/licenses/mit-license.php.
4 
5 #ifndef BITCOIN_SCRIPT_DESCRIPTOR_H
6 #define BITCOIN_SCRIPT_DESCRIPTOR_H
7 
8 #include <outputtype.h>
9 #include <script/script.h>
10 #include <script/sign.h>
11 #include <script/signingprovider.h>
12 
13 #include <vector>
14 
15 using ExtPubKeyMap = std::unordered_map<uint32_t, CExtPubKey>;
16 
19 private:
21  std::unordered_map<uint32_t, ExtPubKeyMap> m_derived_xpubs;
24 
25 public:
33  void CacheParentExtPubKey(uint32_t key_exp_pos, const CExtPubKey &xpub);
41  bool GetCachedParentExtPubKey(uint32_t key_exp_pos, CExtPubKey &xpub) const;
50  void CacheDerivedExtPubKey(uint32_t key_exp_pos, uint32_t der_index,
51  const CExtPubKey &xpub);
60  bool GetCachedDerivedExtPubKey(uint32_t key_exp_pos, uint32_t der_index,
61  CExtPubKey &xpub) const;
62 
66  const std::unordered_map<uint32_t, ExtPubKeyMap>
68 };
69 
88 struct Descriptor {
89  virtual ~Descriptor() = default;
90 
92  virtual bool IsRange() const = 0;
93 
99  virtual bool IsSolvable() const = 0;
100 
102  virtual std::string ToString() const = 0;
103 
108  virtual bool IsSingleType() const = 0;
109 
114  virtual bool ToPrivateString(const SigningProvider &provider,
115  std::string &out) const = 0;
116 
130  virtual bool Expand(int pos, const SigningProvider &provider,
131  std::vector<CScript> &output_scripts,
132  FlatSigningProvider &out,
133  DescriptorCache *write_cache = nullptr) const = 0;
134 
145  virtual bool ExpandFromCache(int pos, const DescriptorCache &read_cache,
146  std::vector<CScript> &output_scripts,
147  FlatSigningProvider &out) const = 0;
148 
158  virtual void ExpandPrivate(int pos, const SigningProvider &provider,
159  FlatSigningProvider &out) const = 0;
160 
165  virtual std::optional<OutputType> GetOutputType() const = 0;
166 };
167 
177 std::unique_ptr<Descriptor> Parse(const std::string &descriptor,
178  FlatSigningProvider &out, std::string &error,
179  bool require_checksum = false);
180 
189 std::string GetDescriptorChecksum(const std::string &descriptor);
190 
208 std::unique_ptr<Descriptor> InferDescriptor(const CScript &script,
209  const SigningProvider &provider);
210 
211 #endif // BITCOIN_SCRIPT_DESCRIPTOR_H
const std::unordered_map< uint32_t, ExtPubKeyMap > GetCachedDerivedExtPubKeys() const
Retrieve all cached derived xpubs.
std::unique_ptr< Descriptor > Parse(const std::string &descriptor, FlatSigningProvider &out, std::string &error, bool require_checksum=false)
Parse a descriptor string.
ExtPubKeyMap m_parent_xpubs
Map key expression index -> parent xpub.
Definition: descriptor.h:23
bool GetCachedParentExtPubKey(uint32_t key_exp_pos, CExtPubKey &xpub) const
Retrieve a cached parent xpub.
std::string ToString(const T &t)
Locale-independent version of std::to_string.
Definition: string.h:67
bool IsSolvable(const SigningProvider &provider, const CScript &script)
Check whether we know how to sign for an output like this, assuming we have all private keys...
Definition: sign.cpp:423
An interface to be implemented by keystores that support signing.
std::string GetDescriptorChecksum(const std::string &descriptor)
Get the checksum for a descriptor.
std::unordered_map< uint32_t, CExtPubKey > ExtPubKeyMap
Definition: descriptor.h:15
Cache for single descriptor&#39;s derived extended pubkeys.
Definition: descriptor.h:18
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:430
void CacheParentExtPubKey(uint32_t key_exp_pos, const CExtPubKey &xpub)
Cache a parent xpub.
std::unique_ptr< Descriptor > InferDescriptor(const CScript &script, const SigningProvider &provider)
Find a descriptor for the specified script, using information from provider where possible...
const ExtPubKeyMap GetCachedParentExtPubKeys() const
Retrieve all cached parent xpubs.
bool error(const char *fmt, const Args &... args)
Definition: system.h:47
void CacheDerivedExtPubKey(uint32_t key_exp_pos, uint32_t der_index, const CExtPubKey &xpub)
Cache an xpub derived at an index.
std::unordered_map< uint32_t, ExtPubKeyMap > m_derived_xpubs
Map key expression index -> map of (key derivation index -> xpub)
Definition: descriptor.h:21
Interface for parsed descriptor objects.
Definition: descriptor.h:88
bool GetCachedDerivedExtPubKey(uint32_t key_exp_pos, uint32_t der_index, CExtPubKey &xpub) const
Retrieve a cached xpub derived at an index.