Bitcoin ABC  0.22.12
P2P Digital Currency
scriptpubkeyman.h
Go to the documentation of this file.
1 // Copyright (c) 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_WALLET_SCRIPTPUBKEYMAN_H
6 #define BITCOIN_WALLET_SCRIPTPUBKEYMAN_H
7 
8 #include <psbt.h>
9 #include <script/descriptor.h>
10 #include <script/signingprovider.h>
11 #include <script/standard.h>
12 #include <util/error.h>
13 #include <util/message.h>
14 #include <wallet/crypter.h>
15 #include <wallet/ismine.h>
16 #include <wallet/walletdb.h>
17 #include <wallet/walletutil.h>
18 
19 #include <boost/signals2/signal.hpp>
20 
21 enum class OutputType;
22 class CChainParams;
23 struct bilingual_str;
24 
25 // Wallet storage things that ScriptPubKeyMans need in order to be able to store
26 // things to the wallet database. It provides access to things that are part of
27 // the entire wallet and not specific to a ScriptPubKeyMan such as wallet flags,
28 // wallet version, encryption keys, encryption status, and the database itself.
29 // This allows a ScriptPubKeyMan to have callbacks into CWallet without causing
30 // a circular dependency. WalletStorage should be the same for all
31 // ScriptPubKeyMans of a wallet.
33 public:
34  virtual ~WalletStorage() = default;
35  virtual const std::string GetDisplayName() const = 0;
36  virtual WalletDatabase &GetDatabase() = 0;
37  virtual const CChainParams &GetChainParams() const = 0;
38  virtual bool IsWalletFlagSet(uint64_t) const = 0;
39  virtual void UnsetBlankWalletFlag(WalletBatch &) = 0;
40  virtual bool CanSupportFeature(enum WalletFeature) const = 0;
41  virtual void SetMinVersion(enum WalletFeature, WalletBatch * = nullptr,
42  bool = false) = 0;
43  virtual const CKeyingMaterial &GetEncryptionKey() const = 0;
44  virtual bool HasEncryptionKeys() const = 0;
45  virtual bool IsLocked() const = 0;
46 };
47 
49 static const unsigned int DEFAULT_KEYPOOL_SIZE = 1000;
50 
51 std::vector<CKeyID> GetAffectedKeys(const CScript &spk,
52  const SigningProvider &provider);
53 
104 class CKeyPool {
105 public:
107  int64_t nTime;
112  bool fInternal;
116 
117  CKeyPool();
118  CKeyPool(const CPubKey &vchPubKeyIn, bool internalIn);
119 
121 
122  template <typename Stream, typename Operation>
123  inline void SerializationOp(Stream &s, Operation ser_action) {
124  int nVersion = s.GetVersion();
125  if (!(s.GetType() & SER_GETHASH)) {
126  READWRITE(nVersion);
127  }
128 
129  READWRITE(nTime);
130  READWRITE(vchPubKey);
131  if (ser_action.ForRead()) {
132  try {
133  READWRITE(fInternal);
134  } catch (std::ios_base::failure &) {
140  fInternal = false;
141  }
142  try {
143  READWRITE(m_pre_split);
144  } catch (std::ios_base::failure &) {
150  m_pre_split = false;
151  }
152  } else {
153  READWRITE(fInternal);
154  READWRITE(m_pre_split);
155  }
156  }
157 };
158 
168 protected:
170 
171 public:
172  ScriptPubKeyMan(WalletStorage &storage) : m_storage(storage) {}
173  virtual ~ScriptPubKeyMan(){};
174  virtual bool GetNewDestination(const OutputType type, CTxDestination &dest,
175  std::string &error) {
176  return false;
177  }
178  virtual isminetype IsMine(const CScript &script) const { return ISMINE_NO; }
179 
182  virtual bool CheckDecryptionKey(const CKeyingMaterial &master_key,
183  bool accept_no_keys = false) {
184  return false;
185  }
186  virtual bool Encrypt(const CKeyingMaterial &master_key,
187  WalletBatch *batch) {
188  return false;
189  }
190 
191  virtual bool GetReservedDestination(const OutputType type, bool internal,
192  CTxDestination &address, int64_t &index,
193  CKeyPool &keypool) {
194  return false;
195  }
196  virtual void KeepDestination(int64_t index, const OutputType &type) {}
197  virtual void ReturnDestination(int64_t index, bool internal,
198  const CTxDestination &addr) {}
199 
207  virtual bool TopUp(unsigned int size = 0) { return false; }
208 
210  virtual void MarkUnusedAddresses(const CScript &script) {}
211 
218  virtual bool SetupGeneration(bool force = false) { return false; }
219 
220  /* Returns true if HD is enabled */
221  virtual bool IsHDEnabled() const { return false; }
222 
227  virtual bool CanGetAddresses(bool internal = false) const { return false; }
228 
230  virtual bool Upgrade(int prev_version, bilingual_str &error) {
231  return false;
232  }
233 
234  virtual bool HavePrivateKeys() const { return false; }
235 
237  virtual void RewriteDB() {}
238 
239  virtual int64_t GetOldestKeyPoolTime() const { return GetTime(); }
240 
241  virtual size_t KeypoolCountExternalKeys() const { return 0; }
242  virtual unsigned int GetKeyPoolSize() const { return 0; }
243 
244  virtual int64_t GetTimeFirstKey() const { return 0; }
245 
246  virtual std::unique_ptr<CKeyMetadata>
247  GetMetadata(const CTxDestination &dest) const {
248  return nullptr;
249  }
250 
251  virtual std::unique_ptr<SigningProvider>
252  GetSolvingProvider(const CScript &script) const {
253  return nullptr;
254  }
255 
261  virtual bool CanProvide(const CScript &script, SignatureData &sigdata) {
262  return false;
263  }
264 
269  virtual bool
271  const std::map<COutPoint, Coin> &coins, SigHashType sighash,
272  std::map<int, std::string> &input_errors) const {
273  return false;
274  }
276  virtual SigningResult SignMessage(const std::string &message,
277  const PKHash &pkhash,
278  std::string &str_sig) const {
280  };
285  virtual TransactionError
287  SigHashType sighash_type = SigHashType().withForkId(),
288  bool sign = true, bool bip32derivs = false) const {
290  }
291 
292  virtual uint256 GetID() const { return uint256(); }
293 
294  virtual void SetType(OutputType type, bool internal) {}
295 
300  template <typename... Params>
301  void WalletLogPrintf(std::string fmt, Params... parameters) const {
302  LogPrintf(("%s " + fmt).c_str(), m_storage.GetDisplayName(),
303  parameters...);
304  };
305 
307  boost::signals2::signal<void(bool fHaveWatchOnly)> NotifyWatchonlyChanged;
308 
310  boost::signals2::signal<void()> NotifyCanGetAddressesChanged;
311 };
312 
314  public FillableSigningProvider {
315 private:
317  bool fDecryptionThoroughlyChecked = false;
318 
319  using WatchOnlySet = std::set<CScript>;
320  using WatchKeyMap = std::map<CKeyID, CPubKey>;
321 
322  WalletBatch *encrypted_batch GUARDED_BY(cs_KeyStore) = nullptr;
323 
324  using CryptedKeyMap =
325  std::map<CKeyID, std::pair<CPubKey, std::vector<uint8_t>>>;
326 
327  CryptedKeyMap mapCryptedKeys GUARDED_BY(cs_KeyStore);
328  WatchOnlySet setWatchOnly GUARDED_BY(cs_KeyStore);
329  WatchKeyMap mapWatchKeys GUARDED_BY(cs_KeyStore);
330 
331  int64_t nTimeFirstKey GUARDED_BY(cs_KeyStore) = 0;
332 
333  bool AddKeyPubKeyInner(const CKey &key, const CPubKey &pubkey);
334  bool AddCryptedKeyInner(const CPubKey &vchPubKey,
335  const std::vector<uint8_t> &vchCryptedSecret);
336 
346  bool AddWatchOnly(const CScript &dest)
347  EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore);
348  bool AddWatchOnlyWithDB(WalletBatch &batch, const CScript &dest)
349  EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore);
350  bool AddWatchOnlyInMem(const CScript &dest);
352  bool AddWatchOnlyWithDB(WalletBatch &batch, const CScript &dest,
353  int64_t create_time)
354  EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore);
355 
357  bool AddKeyPubKeyWithDB(WalletBatch &batch, const CKey &key,
358  const CPubKey &pubkey)
359  EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore);
360 
361  void AddKeypoolPubkeyWithDB(const CPubKey &pubkey, const bool internal,
362  WalletBatch &batch);
363 
365  bool AddCScriptWithDB(WalletBatch &batch, const CScript &script);
366 
368  bool AddKeyOriginWithDB(WalletBatch &batch, const CPubKey &pubkey,
369  const KeyOriginInfo &info);
370 
371  /* the HD chain data model (external chain counters) */
373 
374  /* HD derive new child key (on internal or external chain) */
375  void DeriveNewChildKey(WalletBatch &batch, CKeyMetadata &metadata,
376  CKey &secret, bool internal = false)
377  EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore);
378 
379  std::set<int64_t> setInternalKeyPool GUARDED_BY(cs_KeyStore);
380  std::set<int64_t> setExternalKeyPool GUARDED_BY(cs_KeyStore);
381  std::set<int64_t> set_pre_split_keypool GUARDED_BY(cs_KeyStore);
382  int64_t m_max_keypool_index GUARDED_BY(cs_KeyStore) = 0;
383  std::map<CKeyID, int64_t> m_pool_key_to_index;
384  // Tracks keypool indexes to CKeyIDs of keys that have been taken out of the
385  // keypool but may be returned to it
386  std::map<int64_t, CKeyID> m_index_to_reserved_key;
387 
389  bool GetKeyFromPool(CPubKey &key, const OutputType type,
390  bool internal = false);
391 
406  bool ReserveKeyFromKeyPool(int64_t &nIndex, CKeyPool &keypool,
407  bool fRequestedInternal);
408 
409 public:
411 
412  bool GetNewDestination(const OutputType type, CTxDestination &dest,
413  std::string &error) override;
414  isminetype IsMine(const CScript &script) const override;
415 
416  bool CheckDecryptionKey(const CKeyingMaterial &master_key,
417  bool accept_no_keys = false) override;
418  bool Encrypt(const CKeyingMaterial &master_key,
419  WalletBatch *batch) override;
420 
421  bool GetReservedDestination(const OutputType type, bool internal,
422  CTxDestination &address, int64_t &index,
423  CKeyPool &keypool) override;
424  void KeepDestination(int64_t index, const OutputType &type) override;
425  void ReturnDestination(int64_t index, bool internal,
426  const CTxDestination &) override;
427 
428  bool TopUp(unsigned int size = 0) override;
429 
430  void MarkUnusedAddresses(const CScript &script) override;
431 
434  void UpgradeKeyMetadata();
435 
436  bool IsHDEnabled() const override;
437 
438  bool SetupGeneration(bool force = false) override;
439 
440  bool Upgrade(int prev_version, bilingual_str &error) override;
441 
442  bool HavePrivateKeys() const override;
443 
444  void RewriteDB() override;
445 
446  int64_t GetOldestKeyPoolTime() const override;
447  size_t KeypoolCountExternalKeys() const override;
448  unsigned int GetKeyPoolSize() const override;
449 
450  int64_t GetTimeFirstKey() const override;
451 
452  std::unique_ptr<CKeyMetadata>
453  GetMetadata(const CTxDestination &dest) const override;
454 
455  bool CanGetAddresses(bool internal = false) const override;
456 
457  std::unique_ptr<SigningProvider>
458  GetSolvingProvider(const CScript &script) const override;
459 
460  bool CanProvide(const CScript &script, SignatureData &sigdata) override;
461 
462  bool
464  const std::map<COutPoint, Coin> &coins, SigHashType sighash,
465  std::map<int, std::string> &input_errors) const override;
466  SigningResult SignMessage(const std::string &message, const PKHash &pkhash,
467  std::string &str_sig) const override;
469  FillPSBT(PartiallySignedTransaction &psbt,
470  SigHashType sighash_type = SigHashType().withForkId(),
471  bool sign = true, bool bip32derivs = false) const override;
472 
473  uint256 GetID() const override;
474 
475  void SetType(OutputType type, bool internal) override;
476 
477  // Map from Key ID to key metadata.
478  std::map<CKeyID, CKeyMetadata> mapKeyMetadata GUARDED_BY(cs_KeyStore);
479 
480  // Map from Script ID to key metadata (for watch-only keys).
481  std::map<CScriptID, CKeyMetadata> m_script_metadata GUARDED_BY(cs_KeyStore);
482 
484  bool AddKeyPubKey(const CKey &key, const CPubKey &pubkey) override;
486  bool LoadKey(const CKey &key, const CPubKey &pubkey);
488  bool AddCryptedKey(const CPubKey &vchPubKey,
489  const std::vector<uint8_t> &vchCryptedSecret);
492  bool LoadCryptedKey(const CPubKey &vchPubKey,
493  const std::vector<uint8_t> &vchCryptedSecret);
494  void UpdateTimeFirstKey(int64_t nCreateTime)
495  EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore);
497  bool LoadCScript(const CScript &redeemScript);
499  void LoadKeyMetadata(const CKeyID &keyID, const CKeyMetadata &metadata);
500  void LoadScriptMetadata(const CScriptID &script_id,
501  const CKeyMetadata &metadata);
503  CPubKey GenerateNewKey(WalletBatch &batch, bool internal = false)
504  EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore);
505 
506  /* Set the HD chain model (chain child index counters) */
507  void SetHDChain(const CHDChain &chain, bool memonly);
508  const CHDChain &GetHDChain() const { return hdChain; }
509 
512  bool LoadWatchOnly(const CScript &dest);
514  bool HaveWatchOnly(const CScript &dest) const;
516  bool HaveWatchOnly() const;
518  bool RemoveWatchOnly(const CScript &dest);
519  bool AddWatchOnly(const CScript &dest, int64_t nCreateTime)
520  EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore);
521 
523  bool GetWatchPubKey(const CKeyID &address, CPubKey &pubkey_out) const;
524 
525  /* SigningProvider overrides */
526  bool HaveKey(const CKeyID &address) const override;
527  bool GetKey(const CKeyID &address, CKey &keyOut) const override;
528  bool GetPubKey(const CKeyID &address, CPubKey &vchPubKeyOut) const override;
529  bool AddCScript(const CScript &redeemScript) override;
530  bool GetKeyOrigin(const CKeyID &keyid, KeyOriginInfo &info) const override;
531 
533  void LoadKeyPool(int64_t nIndex, const CKeyPool &keypool);
534  bool NewKeyPool();
535  void MarkPreSplitKeys() EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore);
536 
537  bool ImportScripts(const std::set<CScript> scripts, int64_t timestamp)
538  EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore);
539  bool ImportPrivKeys(const std::map<CKeyID, CKey> &privkey_map,
540  const int64_t timestamp)
541  EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore);
542  bool ImportPubKeys(
543  const std::vector<CKeyID> &ordered_pubkeys,
544  const std::map<CKeyID, CPubKey> &pubkey_map,
545  const std::map<CKeyID, std::pair<CPubKey, KeyOriginInfo>> &key_origins,
546  const bool add_keypool, const bool internal, const int64_t timestamp)
547  EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore);
548  bool ImportScriptPubKeys(const std::set<CScript> &script_pub_keys,
549  const bool have_solving_data,
550  const int64_t timestamp)
551  EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore);
552 
553  /* Returns true if the wallet can generate new keys */
554  bool CanGenerateKeys() const;
555 
556  /* Generates a new HD seed (will not be activated) */
557  CPubKey GenerateNewSeed();
558 
559  /* Derives a new HD seed (will not be activated) */
560  CPubKey DeriveNewSeed(const CKey &key);
561 
562  /* Set the current HD seed (will reset the chain child index counters)
563  Sets the seed's version based on the current wallet version (so the
564  caller must ensure the current wallet version is correct before calling
565  this function). */
566  void SetHDSeed(const CPubKey &key);
567 
574  void LearnRelatedScripts(const CPubKey &key, OutputType);
575 
580  void LearnAllRelatedScripts(const CPubKey &key);
581 
585  void MarkReserveKeysAsUsed(int64_t keypool_id)
586  EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore);
587  const std::map<CKeyID, int64_t> &GetAllReserveKeys() const {
588  return m_pool_key_to_index;
589  }
590 
591  std::set<CKeyID> GetKeys() const override;
592 };
593 
599 private:
601 
602 public:
604  : m_spk_man(spk_man) {}
605 
606  bool GetCScript(const CScriptID &scriptid, CScript &script) const override {
607  return m_spk_man.GetCScript(scriptid, script);
608  }
609  bool HaveCScript(const CScriptID &scriptid) const override {
610  return m_spk_man.HaveCScript(scriptid);
611  }
612  bool GetPubKey(const CKeyID &address, CPubKey &pubkey) const override {
613  return m_spk_man.GetPubKey(address, pubkey);
614  }
615  bool GetKey(const CKeyID &address, CKey &key) const override {
616  return false;
617  }
618  bool HaveKey(const CKeyID &address) const override { return false; }
619  bool GetKeyOrigin(const CKeyID &keyid, KeyOriginInfo &info) const override {
620  return m_spk_man.GetKeyOrigin(keyid, info);
621  }
622 };
623 
625 private:
626  WalletDescriptor m_wallet_descriptor GUARDED_BY(cs_desc_man);
627 
628  // Map of scripts to descriptor range index
629  using ScriptPubKeyMap = std::map<CScript, int32_t>;
630  // Map of pubkeys involved in scripts to descriptor range index
631  using PubKeyMap = std::map<CPubKey, int32_t>;
632  using CryptedKeyMap =
633  std::map<CKeyID, std::pair<CPubKey, std::vector<uint8_t>>>;
634  using KeyMap = std::map<CKeyID, CKey>;
635 
636  ScriptPubKeyMap m_map_script_pub_keys GUARDED_BY(cs_desc_man);
637  PubKeyMap m_map_pubkeys GUARDED_BY(cs_desc_man);
638  int32_t m_max_cached_index = -1;
639 
642 
643  KeyMap m_map_keys GUARDED_BY(cs_desc_man);
644  CryptedKeyMap m_map_crypted_keys GUARDED_BY(cs_desc_man);
645 
646  bool SetCrypted();
647 
649  bool m_decryption_thoroughly_checked = false;
650 
651  bool AddDescriptorKeyWithDB(WalletBatch &batch, const CKey &key,
652  const CPubKey &pubkey);
653 
654  KeyMap GetKeys() const EXCLUSIVE_LOCKS_REQUIRED(cs_desc_man);
655 
656  // Fetch the SigningProvider for the given script and optionally include
657  // private keys
658  std::unique_ptr<FlatSigningProvider>
659  GetSigningProvider(const CScript &script,
660  bool include_private = false) const;
661  // Fetch the SigningProvider for the given pubkey and always include private
662  // keys. This should only be called by signing code.
663  std::unique_ptr<FlatSigningProvider>
664  GetSigningProvider(const CPubKey &pubkey) const;
665  // Fetch the SigningProvider for a given index and optionally include
666  // private keys. Called by the above functions.
667  std::unique_ptr<FlatSigningProvider>
668  GetSigningProvider(int32_t index, bool include_private = false) const
669  EXCLUSIVE_LOCKS_REQUIRED(cs_desc_man);
670 
671 public:
673  WalletDescriptor &descriptor)
674  : ScriptPubKeyMan(storage), m_wallet_descriptor(descriptor) {}
676  bool internal)
677  : ScriptPubKeyMan(storage), m_address_type(address_type),
678  m_internal(internal) {}
679 
681 
682  bool GetNewDestination(const OutputType type, CTxDestination &dest,
683  std::string &error) override;
684  isminetype IsMine(const CScript &script) const override;
685 
686  bool CheckDecryptionKey(const CKeyingMaterial &master_key,
687  bool accept_no_keys = false) override;
688  bool Encrypt(const CKeyingMaterial &master_key,
689  WalletBatch *batch) override;
690 
691  bool GetReservedDestination(const OutputType type, bool internal,
692  CTxDestination &address, int64_t &index,
693  CKeyPool &keypool) override;
694  void ReturnDestination(int64_t index, bool internal,
695  const CTxDestination &addr) override;
696 
697  // Tops up the descriptor cache and m_map_script_pub_keys. The cache is
698  // stored in the wallet file and is used to expand the descriptor in
699  // GetNewDestination. DescriptorScriptPubKeyMan relies more on ephemeral
700  // data than LegacyScriptPubKeyMan. For wallets using unhardened derivation
701  // (with or without private keys), the "keypool" is a single xpub.
702  bool TopUp(unsigned int size = 0) override;
703 
704  void MarkUnusedAddresses(const CScript &script) override;
705 
706  bool IsHDEnabled() const override;
707 
709  bool SetupDescriptorGeneration(const CExtKey &master_key);
710 
711  bool HavePrivateKeys() const override;
712 
713  int64_t GetOldestKeyPoolTime() const override;
714  size_t KeypoolCountExternalKeys() const override;
715  unsigned int GetKeyPoolSize() const override;
716 
717  int64_t GetTimeFirstKey() const override;
718 
719  std::unique_ptr<CKeyMetadata>
720  GetMetadata(const CTxDestination &dest) const override;
721 
722  bool CanGetAddresses(bool internal = false) const override;
723 
724  std::unique_ptr<SigningProvider>
725  GetSolvingProvider(const CScript &script) const override;
726 
727  bool CanProvide(const CScript &script, SignatureData &sigdata) override;
728 
729  bool
731  const std::map<COutPoint, Coin> &coins, SigHashType sighash,
732  std::map<int, std::string> &input_errors) const override;
733  SigningResult SignMessage(const std::string &message, const PKHash &pkhash,
734  std::string &str_sig) const override;
736  FillPSBT(PartiallySignedTransaction &psbt,
737  SigHashType sighash_type = SigHashType().withForkId(),
738  bool sign = true, bool bip32derivs = false) const override;
739 
740  uint256 GetID() const override;
741 
742  void SetType(OutputType type, bool internal) override;
743 
744  void SetCache(const DescriptorCache &cache);
745 
746  bool AddKey(const CKeyID &key_id, const CKey &key);
747  bool AddCryptedKey(const CKeyID &key_id, const CPubKey &pubkey,
748  const std::vector<uint8_t> &crypted_key);
749 
750  bool HasWalletDescriptor(const WalletDescriptor &desc) const;
751  void AddDescriptorKey(const CKey &key, const CPubKey &pubkey);
752  void WriteDescriptor();
753 
754  const WalletDescriptor GetWalletDescriptor() const
755  EXCLUSIVE_LOCKS_REQUIRED(cs_desc_man);
756  const std::vector<CScript> GetScriptPubKeys() const;
757 };
758 
759 #endif // BITCOIN_WALLET_SCRIPTPUBKEYMAN_H
virtual bool Upgrade(int prev_version, bilingual_str &error)
Upgrades the wallet to the specified version.
std::map< CKeyID, std::pair< CPubKey, std::vector< uint8_t > >> CryptedKeyMap
void SignTransaction(CMutableTransaction &mtx, const SigningProvider *keystore, const std::map< COutPoint, Coin > &coins, const UniValue &hashType, UniValue &result)
Sign a transaction with the given keystore and previous transactions.
const LegacyScriptPubKeyMan & m_spk_man
virtual const CKeyingMaterial & GetEncryptionKey() const =0
bool GetCScript(const CScriptID &scriptid, CScript &script) const override
bool GetKeyOrigin(const CKeyID &keyid, KeyOriginInfo &info) const override
virtual void UnsetBlankWalletFlag(WalletBatch &)=0
virtual bool GetCScript(const CScriptID &hash, CScript &redeemScriptOut) const override
bool GetKeyOrigin(const CKeyID &keyid, KeyOriginInfo &info) const override
virtual const std::string GetDisplayName() const =0
A UTXO entry.
Definition: coins.h:27
Bilingual messages:
Definition: translation.h:17
virtual const CChainParams & GetChainParams() const =0
virtual ~ScriptPubKeyMan()
std::vector< uint8_t, secure_allocator< uint8_t > > CKeyingMaterial
Definition: crypter.h:63
std::map< CKeyID, std::pair< CPubKey, std::vector< uint8_t > >> CryptedKeyMap
SigningResult
Definition: message.h:47
Definition: key.h:158
bool GetPubKey(const CKeyID &address, CPubKey &pubkey) const override
virtual size_t KeypoolCountExternalKeys() const
bool HaveKey(const SigningProvider &wallet, const CKey &key)
Checks if a CKey is in the given CWallet compressed or otherwise.
Definition: rpcwallet.cpp:83
std::set< CScript > WatchOnlySet
An instance of this class represents one database.
Definition: bdb.h:97
virtual void RewriteDB()
The action to do when the DB needs rewrite.
static void LogPrintf(const char *fmt, const Args &... args)
Definition: logging.h:171
bool GetKey(const CKeyID &address, CKey &key) const override
bool HaveKey(const CKeyID &address) const override
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system...
Definition: chainparams.h:47
virtual WalletDatabase & GetDatabase()=0
A version of CTransaction with the PSBT format.
Definition: psbt.h:335
virtual bool IsWalletFlagSet(uint64_t) const =0
virtual int64_t GetTimeFirstKey() const
OutputType
Definition: outputtype.h:17
WalletFeature
(client) version numbers for particular wallet features
Definition: walletutil.h:14
const std::map< CKeyID, int64_t > & GetAllReserveKeys() const
virtual unsigned int GetKeyPoolSize() const
Access to the wallet database.
Definition: walletdb.h:183
void WalletLogPrintf(std::string fmt, Params... parameters) const
Prepends the wallet name in logging output to ease debugging in multi-wallet use cases.
virtual void KeepDestination(int64_t index, const OutputType &type)
virtual bool CanProvide(const CScript &script, SignatureData &sigdata)
Whether this ScriptPubKeyMan can provide a SigningProvider (via GetSolvingProvider) that...
int64_t nTime
The time at which the key was generated. Set in AddKeypoolPubKeyWithDB.
static void AddKey(CWallet &wallet, const CKey &key)
A class implementing ScriptPubKeyMan manages some (or all) scriptPubKeys used in a wallet...
virtual uint256 GetID() const
ScriptPubKeyMan(WalletStorage &storage)
virtual ~WalletStorage()=default
static const unsigned int DEFAULT_KEYPOOL_SIZE
Default for -keypool.
virtual bool IsHDEnabled() const
An encapsulated public key.
Definition: pubkey.h:31
std::map< CKeyID, CPubKey > WatchKeyMap
Fillable signing provider that keeps keys in an address->secret map.
virtual void MarkUnusedAddresses(const CScript &script)
Mark unused addresses as being used.
Wraps a LegacyScriptPubKeyMan so that it can be returned in a new unique_ptr.
LegacySigningProvider(const LegacyScriptPubKeyMan &spk_man)
std::map< CScript, int32_t > ScriptPubKeyMap
virtual TransactionError FillPSBT(PartiallySignedTransaction &psbt, SigHashType sighash_type=SigHashType().withForkId(), bool sign=true, bool bip32derivs=false) const
Adds script and derivation path information to a PSBT, and optionally signs it.
virtual bool CheckDecryptionKey(const CKeyingMaterial &master_key, bool accept_no_keys=false)
Check that the given decryption key is valid for this ScriptPubKeyMan, i.e.
bool m_pre_split
Whether this key was generated for a keypool before the wallet was upgraded to HD-split.
isminetype
IsMine() return codes.
Definition: ismine.h:18
boost::signals2::signal< void()> NotifyCanGetAddressesChanged
Keypool has new keys.
Descriptor with some wallet metadata.
Definition: walletutil.h:99
virtual bool HavePrivateKeys() const
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:22
virtual bool IsLocked() const =0
virtual void ReturnDestination(int64_t index, bool internal, const CTxDestination &addr)
256-bit opaque blob.
Definition: uint256.h:120
CPubKey vchPubKey
The public key.
virtual bool CanSupportFeature(enum WalletFeature) const =0
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:56
boost::signals2::signal< void(bool fHaveWatchOnly)> NotifyWatchonlyChanged
Watch-only address added.
virtual std::unique_ptr< CKeyMetadata > GetMetadata(const CTxDestination &dest) const
An interface to be implemented by keystores that support signing.
virtual bool TopUp(unsigned int size=0)
Fills internal address pool.
const CChainParams & Params()
Return the currently selected parameters.
Cache for single descriptor&#39;s derived extended pubkeys.
Definition: descriptor.h:18
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:429
std::map< CPubKey, int32_t > PubKeyMap
static bool GetPubKey(const SigningProvider &provider, const SignatureData &sigdata, const CKeyID &address, CPubKey &pubkey)
Definition: sign.cpp:54
bool HaveCScript(const CScriptID &scriptid) const override
virtual SigningResult SignMessage(const std::string &message, const PKHash &pkhash, std::string &str_sig) const
Sign a message with the given script.
virtual bool SignTransaction(CMutableTransaction &tx, const std::map< COutPoint, Coin > &coins, SigHashType sighash, std::map< int, std::string > &input_errors) const
Creates new signatures and adds them to the transaction.
A mutable version of CTransaction.
Definition: transaction.h:297
A reference to a CKey: the Hash160 of its serialized public key.
Definition: pubkey.h:22
virtual bool Encrypt(const CKeyingMaterial &master_key, WalletBatch *batch)
TransactionError
Definition: error.h:22
virtual bool HaveCScript(const CScriptID &hash) const override
virtual isminetype IsMine(const CScript &script) const
#define GUARDED_BY(x)
Definition: threadsafety.h:45
A reference to a CScript: the Hash160 of its serialization (see script.h)
Definition: standard.h:22
DescriptorScriptPubKeyMan(WalletStorage &storage, OutputType address_type, bool internal)
void SerializationOp(Stream &s, Operation ser_action)
virtual bool HasEncryptionKeys() const =0
virtual int64_t GetOldestKeyPoolTime() const
std::map< CKeyID, CKey > KeyMap
An encapsulated secp256k1 private key.
Definition: key.h:25
virtual bool GetReservedDestination(const OutputType type, bool internal, CTxDestination &address, int64_t &index, CKeyPool &keypool)
WalletStorage & m_storage
virtual bool GetNewDestination(const OutputType type, CTxDestination &dest, std::string &error)
#define READWRITE(...)
Definition: serialize.h:191
virtual void SetType(OutputType type, bool internal)
int64_t GetTime()
Return system time (or mocked time, if set)
Definition: time.cpp:27
virtual bool SetupGeneration(bool force=false)
Sets up the key generation stuff, i.e.
virtual void SetMinVersion(enum WalletFeature, WalletBatch *=nullptr, bool=false)=0
bool GetPubKey(const CKeyID &address, CPubKey &vchPubKeyOut) const override
virtual std::unique_ptr< SigningProvider > GetSolvingProvider(const CScript &script) const
bool error(const char *fmt, const Args &... args)
Definition: system.h:47
bool fInternal
Whether this keypool entry is in the internal keypool (for change outputs)
boost::variant< CNoDestination, PKHash, ScriptHash > CTxDestination
A txout script template with a specific destination.
Definition: standard.h:87
virtual bool CanGetAddresses(bool internal=false) const
Returns true if the wallet can give out new addresses.
std::vector< CKeyID > GetAffectedKeys(const CScript &spk, const SigningProvider &provider)
Signature hash type wrapper class.
Definition: sighashtype.h:37
A key from a CWallet&#39;s keypool.