/tmp/bitcoin/src/wallet/scriptpubkeyman.h
Line | Count | Source |
1 | | // Copyright (c) 2019-present 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_WALLET_SCRIPTPUBKEYMAN_H |
6 | | #define BITCOIN_WALLET_SCRIPTPUBKEYMAN_H |
7 | | |
8 | | #include <addresstype.h> |
9 | | #include <btcsignals.h> |
10 | | #include <common/messages.h> |
11 | | #include <common/signmessage.h> |
12 | | #include <common/types.h> |
13 | | #include <logging.h> |
14 | | #include <musig.h> |
15 | | #include <node/types.h> |
16 | | #include <psbt.h> |
17 | | #include <script/descriptor.h> |
18 | | #include <script/script.h> |
19 | | #include <script/signingprovider.h> |
20 | | #include <util/result.h> |
21 | | #include <util/time.h> |
22 | | #include <wallet/crypter.h> |
23 | | #include <wallet/types.h> |
24 | | #include <wallet/walletdb.h> |
25 | | #include <wallet/walletutil.h> |
26 | | |
27 | | #include <functional> |
28 | | #include <optional> |
29 | | #include <unordered_map> |
30 | | |
31 | | enum class OutputType; |
32 | | |
33 | | namespace wallet { |
34 | | struct MigrationData; |
35 | | class ScriptPubKeyMan; |
36 | | |
37 | | // Wallet storage things that ScriptPubKeyMans need in order to be able to store things to the wallet database. |
38 | | // It provides access to things that are part of the entire wallet and not specific to a ScriptPubKeyMan such as |
39 | | // wallet flags, wallet version, encryption keys, encryption status, and the database itself. This allows a |
40 | | // ScriptPubKeyMan to have callbacks into CWallet without causing a circular dependency. |
41 | | // WalletStorage should be the same for all ScriptPubKeyMans of a wallet. |
42 | | class WalletStorage |
43 | | { |
44 | | public: |
45 | 1.03k | virtual ~WalletStorage() = default; |
46 | | virtual std::string LogName() const = 0; |
47 | | virtual WalletDatabase& GetDatabase() const = 0; |
48 | | virtual bool IsWalletFlagSet(uint64_t) const = 0; |
49 | | virtual void UnsetBlankWalletFlag(WalletBatch&) = 0; |
50 | | //! Pass the encryption key to cb(). |
51 | | virtual bool WithEncryptionKey(std::function<bool (const CKeyingMaterial&)> cb) const = 0; |
52 | | virtual bool HasEncryptionKeys() const = 0; |
53 | | virtual bool IsLocked() const = 0; |
54 | | //! Callback function for after TopUp completes containing any scripts that were added by a SPKMan |
55 | | virtual void TopUpCallback(const std::set<CScript>&, ScriptPubKeyMan*) = 0; |
56 | | }; |
57 | | |
58 | | //! Constant representing an unknown spkm creation time |
59 | | static constexpr int64_t UNKNOWN_TIME = std::numeric_limits<int64_t>::max(); |
60 | | |
61 | | //! Default for -keypool |
62 | | static const unsigned int DEFAULT_KEYPOOL_SIZE = 1000; |
63 | | |
64 | | std::vector<CKeyID> GetAffectedKeys(const CScript& spk, const SigningProvider& provider); |
65 | | |
66 | | struct WalletDestination |
67 | | { |
68 | | CTxDestination dest; |
69 | | std::optional<bool> internal; |
70 | | }; |
71 | | |
72 | | /* |
73 | | * A class implementing ScriptPubKeyMan manages some (or all) scriptPubKeys used in a wallet. |
74 | | * It contains the scripts and keys related to the scriptPubKeys it manages. |
75 | | * A ScriptPubKeyMan will be able to give out scriptPubKeys to be used, as well as marking |
76 | | * when a scriptPubKey has been used. It also handles when and how to store a scriptPubKey |
77 | | * and its related scripts and keys, including encryption. |
78 | | */ |
79 | | class ScriptPubKeyMan |
80 | | { |
81 | | protected: |
82 | | WalletStorage& m_storage; |
83 | | |
84 | | public: |
85 | 7.15k | explicit ScriptPubKeyMan(WalletStorage& storage) : m_storage(storage) {} |
86 | 7.15k | virtual ~ScriptPubKeyMan() = default; |
87 | 0 | virtual util::Result<CTxDestination> GetNewDestination(const OutputType type) { return util::Error{Untranslated("Not supported")}; } |
88 | 0 | virtual bool IsMine(const CScript& script) const { return false; } |
89 | | |
90 | | //! Check that the given decryption key is valid for this ScriptPubKeyMan, i.e. it decrypts all of the keys handled by it. |
91 | 0 | virtual bool CheckDecryptionKey(const CKeyingMaterial& master_key) { return false; } |
92 | 0 | virtual bool Encrypt(const CKeyingMaterial& master_key, WalletBatch* batch) { return false; } |
93 | | |
94 | 0 | virtual util::Result<CTxDestination> GetReservedDestination(const OutputType type, bool internal, int64_t& index) { return util::Error{Untranslated("Not supported")}; } |
95 | 1.99k | virtual void KeepDestination(int64_t index, const OutputType& type) {} |
96 | 0 | virtual void ReturnDestination(int64_t index, bool internal, const CTxDestination& addr) {} |
97 | | |
98 | | /** Fills internal address pool. Use within ScriptPubKeyMan implementations should be used sparingly and only |
99 | | * when something from the address pool is removed, excluding GetNewDestination and GetReservedDestination. |
100 | | * External wallet code is primarily responsible for topping up prior to fetching new addresses |
101 | | */ |
102 | 43 | virtual bool TopUp(unsigned int size = 0) { return false; } |
103 | | |
104 | | /** Mark unused addresses as being used |
105 | | * Affects all keys up to and including the one determined by provided script. |
106 | | * |
107 | | * @param script determines the last key to mark as used |
108 | | * |
109 | | * @return All of the addresses affected |
110 | | */ |
111 | 0 | virtual std::vector<WalletDestination> MarkUnusedAddresses(const CScript& script) { return {}; } |
112 | | |
113 | | /* Returns true if HD is enabled */ |
114 | 0 | virtual bool IsHDEnabled() const { return false; } |
115 | | |
116 | | /* Returns true if the wallet can give out new addresses. This means it has keys in the keypool or can generate new keys */ |
117 | 0 | virtual bool CanGetAddresses(bool internal = false) const { return false; } |
118 | | |
119 | 2 | virtual bool HavePrivateKeys() const { return false; } |
120 | 0 | virtual bool HaveCryptedKeys() const { return false; } |
121 | | |
122 | 43 | virtual unsigned int GetKeyPoolSize() const { return 0; } |
123 | | |
124 | 43 | virtual int64_t GetTimeFirstKey() const { return 0; } |
125 | | |
126 | 0 | virtual std::unique_ptr<CKeyMetadata> GetMetadata(const CTxDestination& dest) const { return nullptr; } |
127 | | |
128 | 0 | virtual std::unique_ptr<SigningProvider> GetSolvingProvider(const CScript& script) const { return nullptr; } |
129 | | |
130 | | /** Whether this ScriptPubKeyMan can provide a SigningProvider (via GetSolvingProvider) that, combined with |
131 | | * sigdata, can produce solving data. |
132 | | */ |
133 | 0 | virtual bool CanProvide(const CScript& script, SignatureData& sigdata) { return false; } |
134 | | |
135 | | /** Creates new signatures and adds them to the transaction. Returns whether all inputs were signed */ |
136 | 0 | virtual bool SignTransaction(CMutableTransaction& tx, const std::map<COutPoint, Coin>& coins, int sighash, std::map<int, bilingual_str>& input_errors) const { return false; } |
137 | | /** Sign a message with the given script */ |
138 | 0 | virtual SigningResult SignMessage(const std::string& message, const PKHash& pkhash, std::string& str_sig) const { return SigningResult::SIGNING_FAILED; }; |
139 | | /** Adds script and derivation path information to a PSBT, and optionally signs it. */ |
140 | 0 | virtual std::optional<common::PSBTError> FillPSBT(PartiallySignedTransaction& psbt, const PrecomputedTransactionData& txdata, const common::PSBTFillOptions& options, int* n_signed = nullptr) const { return common::PSBTError::UNSUPPORTED; } |
141 | | |
142 | 0 | virtual uint256 GetID() const { return uint256(); } |
143 | | |
144 | | /** Returns a set of all the scriptPubKeys that this ScriptPubKeyMan watches */ |
145 | 0 | virtual std::unordered_set<CScript, SaltedSipHasher> GetScriptPubKeys() const { return {}; }; |
146 | | |
147 | | /** Prepends the wallet name in logging output to ease debugging in multi-wallet use cases */ |
148 | | template <typename... Params> |
149 | | void WalletLogPrintf(util::ConstevalFormatString<sizeof...(Params)> wallet_fmt, const Params&... params) const |
150 | 507 | { |
151 | 507 | LogInfo("[%s] %s", m_storage.LogName(), tfm::format(wallet_fmt, params...)); |
152 | 507 | }; Unexecuted instantiation: void wallet::ScriptPubKeyMan::WalletLogPrintf<char [12], unsigned int, unsigned int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>(util::ConstevalFormatString<sizeof...(char [12], unsigned int, unsigned int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)>, char const (&) [12], unsigned int const&, unsigned int const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&) const void wallet::ScriptPubKeyMan::WalletLogPrintf<char [20], int>(util::ConstevalFormatString<sizeof...(char [20], int)>, char const (&) [20], int const&) const Line | Count | Source | 150 | 507 | { | 151 | 507 | LogInfo("[%s] %s", m_storage.LogName(), tfm::format(wallet_fmt, params...)); | 152 | 507 | }; |
Unexecuted instantiation: void wallet::ScriptPubKeyMan::WalletLogPrintf<char [20]>(util::ConstevalFormatString<sizeof...(char [20])>, char const (&) [20]) const |
153 | | |
154 | | /** Keypool has new keys */ |
155 | | btcsignals::signal<void ()> NotifyCanGetAddressesChanged; |
156 | | |
157 | | /** Birth time changed */ |
158 | | btcsignals::signal<void (const ScriptPubKeyMan* spkm, int64_t new_birth_time)> NotifyFirstKeyTimeChanged; |
159 | | }; |
160 | | |
161 | | /** OutputTypes supported by the LegacyScriptPubKeyMan */ |
162 | | static const std::unordered_set<OutputType> LEGACY_OUTPUT_TYPES { |
163 | | OutputType::LEGACY, |
164 | | OutputType::P2SH_SEGWIT, |
165 | | OutputType::BECH32, |
166 | | }; |
167 | | |
168 | | // Manages the data for a LegacyScriptPubKeyMan. |
169 | | // This is the minimum necessary to load a legacy wallet so that it can be migrated. |
170 | | class LegacyDataSPKM : public ScriptPubKeyMan, public FillableSigningProvider |
171 | | { |
172 | | private: |
173 | | using WatchOnlySet = std::set<CScript>; |
174 | | using WatchKeyMap = std::map<CKeyID, CPubKey>; |
175 | | using CryptedKeyMap = std::map<CKeyID, std::pair<CPubKey, std::vector<unsigned char>>>; |
176 | | |
177 | | CryptedKeyMap mapCryptedKeys GUARDED_BY(cs_KeyStore); |
178 | | WatchOnlySet setWatchOnly GUARDED_BY(cs_KeyStore); |
179 | | WatchKeyMap mapWatchKeys GUARDED_BY(cs_KeyStore); |
180 | | |
181 | | /* the HD chain data model (external chain counters) */ |
182 | | CHDChain m_hd_chain; |
183 | | std::unordered_map<CKeyID, CHDChain, SaltedSipHasher> m_inactive_hd_chains; |
184 | | |
185 | | //! keeps track of whether Unlock has run a thorough check before |
186 | | bool fDecryptionThoroughlyChecked = true; |
187 | | |
188 | | bool AddWatchOnlyInMem(const CScript &dest); |
189 | | virtual bool AddKeyPubKeyInner(const CKey& key, const CPubKey &pubkey); |
190 | | bool AddCryptedKeyInner(const CPubKey &vchPubKey, const std::vector<unsigned char> &vchCryptedSecret); |
191 | | |
192 | | // Helper function to retrieve a conservative superset of all output scripts that may be relevant to this LegacyDataSPKM. |
193 | | // It may include scripts that are invalid or not actually watched by this LegacyDataSPKM. |
194 | | // Used only in migration. |
195 | | std::unordered_set<CScript, SaltedSipHasher> GetCandidateScriptPubKeys() const; |
196 | | |
197 | | bool IsMine(const CScript& script) const override; |
198 | | bool CanProvide(const CScript& script, SignatureData& sigdata) override; |
199 | | public: |
200 | | using ScriptPubKeyMan::ScriptPubKeyMan; |
201 | | |
202 | | // Map from Key ID to key metadata. |
203 | | std::map<CKeyID, CKeyMetadata> mapKeyMetadata GUARDED_BY(cs_KeyStore); |
204 | | |
205 | | // Map from Script ID to key metadata (for watch-only keys). |
206 | | std::map<CScriptID, CKeyMetadata> m_script_metadata GUARDED_BY(cs_KeyStore); |
207 | | |
208 | | // ScriptPubKeyMan overrides |
209 | | bool CheckDecryptionKey(const CKeyingMaterial& master_key) override; |
210 | | std::unordered_set<CScript, SaltedSipHasher> GetScriptPubKeys() const override; |
211 | | std::unique_ptr<SigningProvider> GetSolvingProvider(const CScript& script) const override; |
212 | 77 | uint256 GetID() const override { return uint256::ONE; } |
213 | | |
214 | | // FillableSigningProvider overrides |
215 | | bool HaveKey(const CKeyID &address) const override; |
216 | | bool GetKey(const CKeyID &address, CKey& keyOut) const override; |
217 | | bool GetPubKey(const CKeyID &address, CPubKey& vchPubKeyOut) const override; |
218 | | bool GetKeyOrigin(const CKeyID& keyid, KeyOriginInfo& info) const override; |
219 | | |
220 | | //! Load metadata (used by LoadWallet) |
221 | | virtual void LoadKeyMetadata(const CKeyID& keyID, const CKeyMetadata &metadata); |
222 | | virtual void LoadScriptMetadata(const CScriptID& script_id, const CKeyMetadata &metadata); |
223 | | |
224 | | //! Adds a watch-only address to the store, without saving it to disk (used by LoadWallet) |
225 | | bool LoadWatchOnly(const CScript &dest); |
226 | | //! Returns whether the watch-only script is in the wallet |
227 | | bool HaveWatchOnly(const CScript &dest) const; |
228 | | //! Adds a key to the store, without saving it to disk (used by LoadWallet) |
229 | | bool LoadKey(const CKey& key, const CPubKey &pubkey); |
230 | | //! Adds an encrypted key to the store, without saving it to disk (used by LoadWallet) |
231 | | bool LoadCryptedKey(const CPubKey &vchPubKey, const std::vector<unsigned char> &vchCryptedSecret, bool checksum_valid); |
232 | | //! Adds a CScript to the store |
233 | | bool LoadCScript(const CScript& redeemScript); |
234 | | //! Load a HD chain model (used by LoadWallet) |
235 | | void LoadHDChain(const CHDChain& chain); |
236 | | void AddInactiveHDChain(const CHDChain& chain); |
237 | 39 | const CHDChain& GetHDChain() const { return m_hd_chain; } |
238 | | |
239 | | //! Fetches a pubkey from mapWatchKeys if it exists there |
240 | | bool GetWatchPubKey(const CKeyID &address, CPubKey &pubkey_out) const; |
241 | | |
242 | | /** |
243 | | * Retrieves scripts that were imported by bugs into the legacy spkm and are |
244 | | * simply invalid, such as a sh(sh(pkh())) script, or not watched. |
245 | | */ |
246 | | std::unordered_set<CScript, SaltedSipHasher> GetNotMineScriptPubKeys() const; |
247 | | |
248 | | /** Get the DescriptorScriptPubKeyMans (with private keys) that have the same scriptPubKeys as this LegacyScriptPubKeyMan. |
249 | | * Does not modify this ScriptPubKeyMan. */ |
250 | | std::optional<MigrationData> MigrateToDescriptor(); |
251 | | /** Delete all the records of this LegacyScriptPubKeyMan from disk*/ |
252 | | bool DeleteRecordsWithDB(WalletBatch& batch); |
253 | | }; |
254 | | |
255 | | /** Wraps a LegacyScriptPubKeyMan so that it can be returned in a new unique_ptr. Does not provide privkeys */ |
256 | | class LegacySigningProvider : public SigningProvider |
257 | | { |
258 | | private: |
259 | | const LegacyDataSPKM& m_spk_man; |
260 | | public: |
261 | 90 | explicit LegacySigningProvider(const LegacyDataSPKM& spk_man) : m_spk_man(spk_man) {} |
262 | | |
263 | 69 | bool GetCScript(const CScriptID &scriptid, CScript& script) const override { return m_spk_man.GetCScript(scriptid, script); } |
264 | 0 | bool HaveCScript(const CScriptID &scriptid) const override { return m_spk_man.HaveCScript(scriptid); } |
265 | 42 | bool GetPubKey(const CKeyID &address, CPubKey& pubkey) const override { return m_spk_man.GetPubKey(address, pubkey); } |
266 | 0 | bool GetKey(const CKeyID &address, CKey& key) const override { return false; } |
267 | 0 | bool HaveKey(const CKeyID &address) const override { return false; } |
268 | 93 | bool GetKeyOrigin(const CKeyID& keyid, KeyOriginInfo& info) const override { return m_spk_man.GetKeyOrigin(keyid, info); } |
269 | | }; |
270 | | |
271 | | class DescriptorScriptPubKeyMan : public ScriptPubKeyMan |
272 | | { |
273 | | friend class LegacyDataSPKM; |
274 | | private: |
275 | | using ScriptPubKeyMap = std::map<CScript, int32_t>; // Map of scripts to descriptor range index |
276 | | using PubKeyMap = std::map<CPubKey, int32_t>; // Map of pubkeys involved in scripts to descriptor range index |
277 | | using CryptedKeyMap = std::map<CKeyID, std::pair<CPubKey, std::vector<unsigned char>>>; |
278 | | using KeyMap = std::map<CKeyID, CKey>; |
279 | | |
280 | | ScriptPubKeyMap m_map_script_pub_keys GUARDED_BY(cs_desc_man); |
281 | | PubKeyMap m_map_pubkeys GUARDED_BY(cs_desc_man); |
282 | | int32_t m_max_cached_index = -1; |
283 | | |
284 | | KeyMap m_map_keys GUARDED_BY(cs_desc_man); |
285 | | CryptedKeyMap m_map_crypted_keys GUARDED_BY(cs_desc_man); |
286 | | |
287 | | //! keeps track of whether Unlock has run a thorough check before |
288 | | bool m_decryption_thoroughly_checked = false; |
289 | | |
290 | | //! Number of pre-generated keys/scripts (part of the look-ahead process, used to detect payments) |
291 | | int64_t m_keypool_size GUARDED_BY(cs_desc_man){DEFAULT_KEYPOOL_SIZE}; |
292 | | |
293 | | /** Map of a session id to MuSig2 secnonce |
294 | | * |
295 | | * Stores MuSig2 secnonces while the MuSig2 signing session is still ongoing. |
296 | | * Note that these secnonces must not be reused. In order to avoid being tricked into |
297 | | * reusing a nonce, this map is held only in memory and must not be written to disk. |
298 | | * The side effect is that signing sessions cannot persist across restarts, but this |
299 | | * must be done in order to prevent nonce reuse. |
300 | | * |
301 | | * The session id is an arbitrary value set by the signer in order for the signing logic |
302 | | * to find ongoing signing sessions. It is the SHA256 of aggregate xonly key, + participant pubkey + sighash. |
303 | | */ |
304 | | mutable std::map<uint256, MuSig2SecNonce> m_musig2_secnonces; |
305 | | |
306 | | bool AddDescriptorKeyWithDB(WalletBatch& batch, const CKey& key, const CPubKey &pubkey) EXCLUSIVE_LOCKS_REQUIRED(cs_desc_man); |
307 | | |
308 | | KeyMap GetKeys() const EXCLUSIVE_LOCKS_REQUIRED(cs_desc_man); |
309 | | |
310 | | // Cached FlatSigningProviders to avoid regenerating them each time they are needed. |
311 | | mutable std::map<int32_t, FlatSigningProvider> m_map_signing_providers; |
312 | | // Fetch the SigningProvider for the given script and optionally include private keys |
313 | | std::unique_ptr<FlatSigningProvider> GetSigningProvider(const CScript& script, bool include_private = false) const; |
314 | | // Fetch the SigningProvider for a given index and optionally include private keys. Called by the above functions. |
315 | | std::unique_ptr<FlatSigningProvider> GetSigningProvider(int32_t index, bool include_private = false) const EXCLUSIVE_LOCKS_REQUIRED(cs_desc_man); |
316 | | |
317 | | protected: |
318 | | WalletDescriptor m_wallet_descriptor GUARDED_BY(cs_desc_man); |
319 | | |
320 | | //! Same as 'TopUp' but designed for use within a batch transaction context |
321 | | bool TopUpWithDB(WalletBatch& batch, unsigned int size = 0); |
322 | | |
323 | | public: |
324 | | DescriptorScriptPubKeyMan(WalletStorage& storage, WalletDescriptor& descriptor, int64_t keypool_size) |
325 | 3.45k | : ScriptPubKeyMan(storage), |
326 | 3.45k | m_keypool_size(keypool_size), |
327 | 3.45k | m_wallet_descriptor(descriptor) |
328 | 3.45k | {} |
329 | | DescriptorScriptPubKeyMan(WalletStorage& storage, int64_t keypool_size) |
330 | 3.65k | : ScriptPubKeyMan(storage), |
331 | 3.65k | m_keypool_size(keypool_size) |
332 | 3.65k | {} |
333 | | |
334 | | mutable RecursiveMutex cs_desc_man; |
335 | | |
336 | | util::Result<CTxDestination> GetNewDestination(OutputType type) override; |
337 | | bool IsMine(const CScript& script) const override; |
338 | | |
339 | | bool CheckDecryptionKey(const CKeyingMaterial& master_key) override; |
340 | | bool Encrypt(const CKeyingMaterial& master_key, WalletBatch* batch) override; |
341 | | |
342 | | util::Result<CTxDestination> GetReservedDestination(OutputType type, bool internal, int64_t& index) override; |
343 | | void ReturnDestination(int64_t index, bool internal, const CTxDestination& addr) override; |
344 | | |
345 | | // Tops up the descriptor cache and m_map_script_pub_keys. The cache is stored in the wallet file |
346 | | // and is used to expand the descriptor in GetNewDestination. DescriptorScriptPubKeyMan relies |
347 | | // more on ephemeral data than LegacyScriptPubKeyMan. For wallets using unhardened derivation |
348 | | // (with or without private keys), the "keypool" is a single xpub. |
349 | | bool TopUp(unsigned int size = 0) override; |
350 | | |
351 | | std::vector<WalletDestination> MarkUnusedAddresses(const CScript& script) override; |
352 | | |
353 | | bool IsHDEnabled() const override; |
354 | | |
355 | | //! Setup descriptors based on the given CExtkey |
356 | | bool SetupDescriptorGeneration(WalletBatch& batch, const CExtKey& master_key, OutputType addr_type, bool internal); |
357 | | |
358 | | bool HavePrivateKeys() const override; |
359 | | bool HasPrivKey(const CKeyID& keyid) const EXCLUSIVE_LOCKS_REQUIRED(cs_desc_man); |
360 | | //! Retrieve the particular key if it is available. Returns nullopt if the key is not in the wallet, or if the wallet is locked. |
361 | | std::optional<CKey> GetKey(const CKeyID& keyid) const EXCLUSIVE_LOCKS_REQUIRED(cs_desc_man); |
362 | | bool HaveCryptedKeys() const override; |
363 | | |
364 | | unsigned int GetKeyPoolSize() const override; |
365 | | |
366 | | int64_t GetTimeFirstKey() const override; |
367 | | |
368 | | std::unique_ptr<CKeyMetadata> GetMetadata(const CTxDestination& dest) const override; |
369 | | |
370 | | bool CanGetAddresses(bool internal = false) const override; |
371 | | |
372 | | std::unique_ptr<SigningProvider> GetSolvingProvider(const CScript& script) const override; |
373 | | |
374 | | bool CanProvide(const CScript& script, SignatureData& sigdata) override; |
375 | | |
376 | | // Fetch the SigningProvider for the given pubkey and always include private keys. This should only be called by signing code. |
377 | | std::unique_ptr<FlatSigningProvider> GetSigningProvider(const CPubKey& pubkey) const; |
378 | | |
379 | | bool SignTransaction(CMutableTransaction& tx, const std::map<COutPoint, Coin>& coins, int sighash, std::map<int, bilingual_str>& input_errors) const override; |
380 | | SigningResult SignMessage(const std::string& message, const PKHash& pkhash, std::string& str_sig) const override; |
381 | | std::optional<common::PSBTError> FillPSBT(PartiallySignedTransaction& psbt, const PrecomputedTransactionData& txdata, const common::PSBTFillOptions& options, int* n_signed = nullptr) const override; |
382 | | |
383 | | uint256 GetID() const override; |
384 | | |
385 | | void SetCache(const DescriptorCache& cache); |
386 | | |
387 | | bool AddKey(const CKeyID& key_id, const CKey& key); |
388 | | bool AddCryptedKey(const CKeyID& key_id, const CPubKey& pubkey, const std::vector<unsigned char>& crypted_key); |
389 | | |
390 | | bool HasWalletDescriptor(const WalletDescriptor& desc) const; |
391 | | util::Result<void> UpdateWalletDescriptor(WalletDescriptor& descriptor); |
392 | | bool CanUpdateToWalletDescriptor(const WalletDescriptor& descriptor, std::string& error); |
393 | | void AddDescriptorKey(const CKey& key, const CPubKey &pubkey); |
394 | | void WriteDescriptor(); |
395 | | |
396 | | WalletDescriptor GetWalletDescriptor() const EXCLUSIVE_LOCKS_REQUIRED(cs_desc_man); |
397 | | std::unordered_set<CScript, SaltedSipHasher> GetScriptPubKeys() const override; |
398 | | std::unordered_set<CScript, SaltedSipHasher> GetScriptPubKeys(int32_t minimum_index) const; |
399 | | int32_t GetEndRange() const; |
400 | | |
401 | | [[nodiscard]] bool GetDescriptorString(std::string& out, bool priv) const; |
402 | | |
403 | | void UpgradeDescriptorCache(); |
404 | | }; |
405 | | |
406 | | /** struct containing information needed for migrating legacy wallets to descriptor wallets */ |
407 | | struct MigrationData |
408 | | { |
409 | | CExtKey master_key; |
410 | | std::vector<std::pair<std::string, int64_t>> watch_descs; |
411 | | std::vector<std::pair<std::string, int64_t>> solvable_descs; |
412 | | std::vector<std::unique_ptr<DescriptorScriptPubKeyMan>> desc_spkms; |
413 | | std::shared_ptr<CWallet> watchonly_wallet{nullptr}; |
414 | | std::shared_ptr<CWallet> solvable_wallet{nullptr}; |
415 | | }; |
416 | | |
417 | | } // namespace wallet |
418 | | |
419 | | #endif // BITCOIN_WALLET_SCRIPTPUBKEYMAN_H |