 |
Bitcoin Core
22.99.0
P2P Digital Currency
|
Go to the documentation of this file.
5 #ifndef BITCOIN_WALLET_SCRIPTPUBKEYMAN_H
6 #define BITCOIN_WALLET_SCRIPTPUBKEYMAN_H
20 #include <boost/signals2/signal.hpp>
23 #include <unordered_map>
118 template<
typename Stream>
121 int nVersion = s.GetVersion();
128 template<
typename Stream>
131 int nVersion = s.GetVersion();
138 }
catch (std::ios_base::failure&) {
145 }
catch (std::ios_base::failure&) {
156 std::optional<bool>
internal;
189 virtual bool TopUp(
unsigned int size = 0) {
return false; }
245 template<
typename...
Params>
275 using CryptedKeyMap = std::map<CKeyID, std::pair<CPubKey, std::vector<unsigned char>>>;
371 bool TopUp(
unsigned int size = 0) override;
421 bool LoadCryptedKey(const
CPubKey &vchPubKey, const
std::vector<
unsigned char> &vchCryptedSecret,
bool checksum_valid);
507 std::set<CKeyID>
GetKeys()
const override;
531 using CryptedKeyMap = std::map<CKeyID, std::pair<CPubKey, std::vector<unsigned char>>>;
561 m_wallet_descriptor(descriptor)
582 bool TopUp(
unsigned int size = 0)
override;
637 #endif // BITCOIN_WALLET_SCRIPTPUBKEYMAN_H
std::unique_ptr< FlatSigningProvider > GetSigningProvider(const CScript &script, bool include_private=false) const
void Unserialize(Stream &s)
bool HavePrivateKeys() const override
TransactionError FillPSBT(PartiallySignedTransaction &psbt, const PrecomputedTransactionData &txdata, int sighash_type=SIGHASH_DEFAULT, bool sign=true, bool bip32derivs=false, int *n_signed=nullptr, bool finalize=true) const override
Adds script and derivation path information to a PSBT, and optionally signs it.
An instance of this class represents one database.
bool GetKey(const CKeyID &address, CKey &key) const override
bool AddKey(const CKeyID &key_id, const CKey &key)
void AddInactiveHDChain(const CHDChain &chain)
WalletStorage & m_storage
bool GetKeyOrigin(const CKeyID &keyid, KeyOriginInfo &info) 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 CanSupportFeature(enum WalletFeature) const =0
uint256 GetID() const override
bool m_pre_split
Whether this key was generated for a keypool before the wallet was upgraded to HD-split.
std::vector< CKeyPool > MarkReserveKeysAsUsed(int64_t keypool_id) EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore)
Marks all keys in the keypool up to and including the provided key as used.
isminetype
IsMine() return codes, which depend on ScriptPubKeyMan implementation.
bool AddCryptedKeyInner(const CPubKey &vchPubKey, const std::vector< unsigned char > &vchCryptedSecret)
bool GetNewDestination(const OutputType type, CTxDestination &dest, bilingual_str &error) override
virtual void SetMinVersion(enum WalletFeature, WalletBatch *=nullptr)=0
bool AddWatchOnlyWithDB(WalletBatch &batch, const CScript &dest) EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore)
bool ReserveKeyFromKeyPool(int64_t &nIndex, CKeyPool &keypool, bool fRequestedInternal)
Reserves a key from the keypool and sets nIndex to its index.
bool CanGetAddresses(bool internal=false) const override
bool GetDescriptorString(std::string &out, const bool priv) const
std::vector< CKeyID > GetAffectedKeys(const CScript &spk, const SigningProvider &provider)
void ReturnDestination(int64_t index, bool internal, const CTxDestination &) override
void LoadKeyPool(int64_t nIndex, const CKeyPool &keypool)
Load a keypool entry.
RecursiveMutex cs_desc_man
A key from a CWallet's keypool.
virtual TransactionError FillPSBT(PartiallySignedTransaction &psbt, const PrecomputedTransactionData &txdata, int sighash_type=SIGHASH_DEFAULT, bool sign=true, bool bip32derivs=false, int *n_signed=nullptr, bool finalize=true) const
Adds script and derivation path information to a PSBT, and optionally signs it.
TransactionError FillPSBT(PartiallySignedTransaction &psbt, const PrecomputedTransactionData &txdata, int sighash_type=SIGHASH_DEFAULT, bool sign=true, bool bip32derivs=false, int *n_signed=nullptr, bool finalize=true) const override
Adds script and derivation path information to a PSBT, and optionally signs it.
bool CheckDecryptionKey(const CKeyingMaterial &master_key, bool accept_no_keys=false) override
Check that the given decryption key is valid for this ScriptPubKeyMan, i.e. it decrypts all of the ke...
bool m_decryption_thoroughly_checked
keeps track of whether Unlock has run a thorough check before
Fillable signing provider that keeps keys in an address->secret map.
static const std::unordered_set< OutputType > LEGACY_OUTPUT_TYPES
OutputTypes supported by the LegacyScriptPubKeyMan.
bool ImportPubKeys(const std::vector< CKeyID > &ordered_pubkeys, const std::map< CKeyID, CPubKey > &pubkey_map, const std::map< CKeyID, std::pair< CPubKey, KeyOriginInfo >> &key_origins, const bool add_keypool, const bool internal, const int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore)
boost::signals2::signal< void()> NotifyCanGetAddressesChanged
Keypool has new keys.
bool CanProvide(const CScript &script, SignatureData &sigdata) override
Whether this ScriptPubKeyMan can provide a SigningProvider (via GetSolvingProvider) that,...
void UpdateTimeFirstKey(int64_t nCreateTime) EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore)
Update wallet first key creation time.
virtual const std::string GetDisplayName() const =0
virtual bool Encrypt(const CKeyingMaterial &master_key, WalletBatch *batch)
bool LoadCryptedKey(const CPubKey &vchPubKey, const std::vector< unsigned char > &vchCryptedSecret, bool checksum_valid)
Adds an encrypted key to the store, without saving it to disk (used by LoadWallet)
bool AddDescriptorKeyWithDB(WalletBatch &batch, const CKey &key, const CPubKey &pubkey) EXCLUSIVE_LOCKS_REQUIRED(cs_desc_man)
CPubKey DeriveNewSeed(const CKey &key)
An interface to be implemented by keystores that support signing.
bool ImportScripts(const std::set< CScript > scripts, int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore)
bool ImportPrivKeys(const std::map< CKeyID, CKey > &privkey_map, const int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore)
int64_t GetTime()
DEPRECATED Use either GetTimeSeconds (not mockable) or GetTime<T> (mockable)
bool Encrypt(const CKeyingMaterial &master_key, WalletBatch *batch) override
CPubKey GenerateNewSeed()
bool GetReservedDestination(const OutputType type, bool internal, CTxDestination &address, int64_t &index, CKeyPool &keypool, bilingual_str &error) override
virtual ~ScriptPubKeyMan()
virtual bool CanProvide(const CScript &script, SignatureData &sigdata)
Whether this ScriptPubKeyMan can provide a SigningProvider (via GetSolvingProvider) that,...
void AddKeypoolPubkeyWithDB(const CPubKey &pubkey, const bool internal, WalletBatch &batch)
A reference to a CKey: the Hash160 of its serialized public key.
bool HaveCScript(const CScriptID &scriptid) const override
bool Upgrade(int prev_version, int new_version, bilingual_str &error) override
Upgrades the wallet to the specified version.
SigningResult SignMessage(const std::string &message, const PKHash &pkhash, std::string &str_sig) const override
Sign a message with the given script.
virtual WalletDatabase & GetDatabase() const =0
bool HasWalletDescriptor(const WalletDescriptor &desc) const
std::map< CScript, int32_t > ScriptPubKeyMap
bool LoadWatchOnly(const CScript &dest)
Adds a watch-only address to the store, without saving it to disk (used by LoadWallet)
std::vector< unsigned char, secure_allocator< unsigned char > > CKeyingMaterial
void DeriveNewChildKey(WalletBatch &batch, CKeyMetadata &metadata, CKey &secret, CHDChain &hd_chain, bool internal=false) EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore)
void WalletLogPrintf(std::string fmt, Params... parameters) const
Prepends the wallet name in logging output to ease debugging in multi-wallet use cases.
bool NewKeyPool()
Mark old keypool keys as used, and generate all new keys.
bool SetupGeneration(bool force=false) override
Sets up the key generation stuff, i.e.
unsigned int GetKeyPoolSize() const override
virtual bool SignTransaction(CMutableTransaction &tx, const std::map< COutPoint, Coin > &coins, int sighash, std::map< int, bilingual_str > &input_errors) const
Creates new signatures and adds them to the transaction.
std::map< CPubKey, int32_t > PubKeyMap
int64_t GetTimeFirstKey() const override
std::optional< int64_t > GetOldestKeyPoolTime() const override
bool AddKeyPubKeyInner(const CKey &key, const CPubKey &pubkey)
WalletFeature
(client) version numbers for particular wallet features
bool AddCScript(const CScript &redeemScript) override
bool SetupDescriptor(std::unique_ptr< Descriptor >desc)
Provide a descriptor at setup time Returns false if already setup or setup fails, true if setup is su...
virtual std::optional< int64_t > GetOldestKeyPoolTime() const
Wraps a LegacyScriptPubKeyMan so that it can be returned in a new unique_ptr.
bool AddKeyPubKeyWithDB(WalletBatch &batch, const CKey &key, const CPubKey &pubkey) EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore)
Adds a key to the store, and saves it to disk.
std::variant< CNoDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, WitnessUnknown > CTxDestination
A txout script template with a specific destination.
virtual isminetype IsMine(const CScript &script) const
bool AddKeyOriginWithDB(WalletBatch &batch, const CPubKey &pubkey, const KeyOriginInfo &info)
Add a KeyOriginInfo to the wallet.
virtual std::vector< WalletDestination > MarkUnusedAddresses(const CScript &script)
Mark unused addresses as being used Affects all keys up to and including the one determined by provid...
bool AddWatchOnlyInMem(const CScript &dest)
std::map< CKeyID, int64_t > m_pool_key_to_index
bool ImportScriptPubKeys(const std::set< CScript > &script_pub_keys, const bool have_solving_data, const int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore)
void MarkPreSplitKeys() EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore)
int64_t nTime
The time at which the key was generated. Set in AddKeypoolPubKeyWithDB.
std::optional< int64_t > GetOldestKeyPoolTime() const override
ScriptPubKeyMan(WalletStorage &storage)
bool Encrypt(const CKeyingMaterial &master_key, WalletBatch *batch) override
const std::vector< CScript > GetScriptPubKeys() const
virtual std::unique_ptr< SigningProvider > GetSolvingProvider(const CScript &script) const
bool fInternal
Whether this keypool entry is in the internal keypool (for change outputs)
static const unsigned int DEFAULT_KEYPOOL_SIZE
Default for -keypool.
void UpdateWalletDescriptor(WalletDescriptor &descriptor)
std::map< CKeyID, CPubKey > WatchKeyMap
Access to the wallet database.
bool HaveKey(const CKeyID &address) const override
virtual bool IsHDEnabled() const
bool RemoveWatchOnly(const CScript &dest)
Remove a watch only script from the keystore.
bool GetPubKey(const CKeyID &address, CPubKey &vchPubKeyOut) const override
virtual bool HaveCScript(const CScriptID &hash) const override
virtual ~WalletStorage()=default
bool AddCryptedKey(const CPubKey &vchPubKey, const std::vector< unsigned char > &vchCryptedSecret)
Adds an encrypted key to the store, and saves it to disk.
int64_t GetTimeFirstKey() const override
bool SetupDescriptorGeneration(const CExtKey &master_key, OutputType addr_type, bool internal)
Setup descriptors based on the given CExtkey.
virtual std::unique_ptr< CKeyMetadata > GetMetadata(const CTxDestination &dest) const
bool CanUpdateToWalletDescriptor(const WalletDescriptor &descriptor, std::string &error)
bool CanGenerateKeys() const
bool IsHDEnabled() const override
const WalletDescriptor GetWalletDescriptor() const EXCLUSIVE_LOCKS_REQUIRED(cs_desc_man)
isminetype IsMine(const CScript &script) const override
bool CanProvide(const CScript &script, SignatureData &sigdata) override
Whether this ScriptPubKeyMan can provide a SigningProvider (via GetSolvingProvider) that,...
KeyMap GetKeys() const EXCLUSIVE_LOCKS_REQUIRED(cs_desc_man)
Serialized script, used inside transaction inputs and outputs.
virtual bool GetReservedDestination(const OutputType type, bool internal, CTxDestination &address, int64_t &index, CKeyPool &keypool, bilingual_str &error)
void ReturnDestination(int64_t index, bool internal, const CTxDestination &addr) override
virtual void KeepDestination(int64_t index, const OutputType &type)
bool AddKeyPubKey(const CKey &key, const CPubKey &pubkey) override
Adds a key to the store, and saves it to disk.
bool GetReservedDestination(const OutputType type, bool internal, CTxDestination &address, int64_t &index, CKeyPool &keypool, bilingual_str &error) override
std::map< int64_t, CKeyID > m_index_to_reserved_key
const LegacyScriptPubKeyMan & m_spk_man
CPubKey vchPubKey
The public key.
Cache for single descriptor's derived extended pubkeys.
virtual void RewriteDB()
The action to do when the DB needs rewrite.
virtual bool CanGetAddresses(bool internal=false) const
void SetCache(const DescriptorCache &cache)
bool fDecryptionThoroughlyChecked
keeps track of whether Unlock has run a thorough check before
bool CheckDecryptionKey(const CKeyingMaterial &master_key, bool accept_no_keys=false) override
Check that the given decryption key is valid for this ScriptPubKeyMan, i.e. it decrypts all of the ke...
bool AddCryptedKey(const CKeyID &key_id, const CPubKey &pubkey, const std::vector< unsigned char > &crypted_key)
const CHDChain & GetHDChain() const
void AddHDChain(const CHDChain &chain)
std::unique_ptr< SigningProvider > GetSolvingProvider(const CScript &script) const override
std::unique_ptr< SigningProvider > GetSolvingProvider(const CScript &script) const override
bool CanGetAddresses(bool internal=false) const override
bool TopUpInactiveHDChain(const CKeyID seed_id, int64_t index, bool internal)
Like TopUp() but adds keys for inactive HD chains.
bool LoadKey(const CKey &key, const CPubKey &pubkey)
Adds a key to the store, without saving it to disk (used by LoadWallet)
SigningResult SignMessage(const std::string &message, const PKHash &pkhash, std::string &str_sig) const override
Sign a message with the given script.
virtual bool HavePrivateKeys() const
bool GetKeyOrigin(const CKeyID &keyid, KeyOriginInfo &info) const override
ScriptPubKeyMap m_map_script_pub_keys GUARDED_BY(cs_desc_man)
An encapsulated public key.
void KeepDestination(int64_t index, const OutputType &type) override
virtual bool IsLocked() const =0
virtual unsigned int GetKeyPoolSize() const
bool TopUp(unsigned int size=0) override
Fills internal address pool.
bool TopUp(unsigned int size=0) override
Fills internal address pool.
An encapsulated private key.
WalletBatch *encrypted_batch GUARDED_BY(cs_KeyStore)
bool SignTransaction(CMutableTransaction &tx, const std::map< COutPoint, Coin > &coins, int sighash, std::map< int, bilingual_str > &input_errors) const override
Creates new signatures and adds them to the transaction.
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. it decrypts all of the ke...
#define EXCLUSIVE_LOCKS_REQUIRED(...)
bool GetKeyFromPool(CPubKey &key, const OutputType type, bool internal=false)
Fetches a key from the keypool.
A version of CTransaction with the PSBT format.
std::map< CKeyID, std::pair< CPubKey, std::vector< unsigned char > >> CryptedKeyMap
std::map< CKeyID, std::pair< CPubKey, std::vector< unsigned char > >> CryptedKeyMap
bool IsHDEnabled() const override
bool LoadCScript(const CScript &redeemScript)
Adds a CScript to the store.
DescriptorScriptPubKeyMan(WalletStorage &storage)
void LoadScriptMetadata(const CScriptID &script_id, const CKeyMetadata &metadata)
void UpgradeDescriptorCache()
uint256 GetID() const override
const CChainParams & Params()
Return the currently selected parameters.
std::vector< WalletDestination > MarkUnusedAddresses(const CScript &script) override
Mark unused addresses as being used Affects all keys up to and including the one determined by provid...
bool AddWatchOnly(const CScript &dest) EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore)
Private version of AddWatchOnly method which does not accept a timestamp, and which will reset the wa...
const std::map< CKeyID, int64_t > & GetAllReserveKeys() const
void AddDescriptorKey(const CKey &key, const CPubKey &pubkey)
bool AddCScriptWithDB(WalletBatch &batch, const CScript &script)
Adds a script to the store and saves it to disk.
virtual bool GetNewDestination(const OutputType type, CTxDestination &dest, bilingual_str &error)
virtual const CKeyingMaterial & GetEncryptionKey() const =0
virtual int64_t GetTimeFirstKey() const
void SetHDSeed(const CPubKey &key)
virtual bool GetCScript(const CScriptID &hash, CScript &redeemScriptOut) const override
bool SignTransaction(CMutableTransaction &tx, const std::map< COutPoint, Coin > &coins, int sighash, std::map< int, bilingual_str > &input_errors) const override
Creates new signatures and adds them to the transaction.
std::set< CScript > WatchOnlySet
Descriptor with some wallet metadata.
virtual bool TopUp(unsigned int size=0)
Fills internal address pool.
bool GetKey(const CKeyID &address, CKey &keyOut) const override
An outpoint - a combination of a transaction hash and an index n into its vout.
bool HavePrivateKeys() const override
std::vector< WalletDestination > MarkUnusedAddresses(const CScript &script) override
Mark unused addresses as being used Affects all keys up to and including the one determined by provid...
virtual bool IsWalletFlagSet(uint64_t) const =0
RecursiveMutex cs_KeyStore
bool error(const char *fmt, const Args &... args)
virtual void UnsetBlankWalletFlag(WalletBatch &)=0
void Serialize(Stream &s) const
std::unique_ptr< CKeyMetadata > GetMetadata(const CTxDestination &dest) const override
virtual bool HasEncryptionKeys() const =0
bool GetPubKey(const CKeyID &address, CPubKey &pubkey) const override
std::unordered_map< CKeyID, CHDChain, SaltedSipHasher > m_inactive_hd_chains
A mutable version of CTransaction.
virtual bool Upgrade(int prev_version, int new_version, bilingual_str &error)
Upgrades the wallet to the specified version.
isminetype IsMine(const CScript &script) const override
virtual void ReturnDestination(int64_t index, bool internal, const CTxDestination &addr)
A reference to a CScript: the Hash160 of its serialization (see script.h)
void UpgradeKeyMetadata()
Upgrade stored CKeyMetadata objects to store key origin info as KeyOriginInfo.
virtual bool SetupGeneration(bool force=false)
Sets up the key generation stuff, i.e.
void LearnRelatedScripts(const CPubKey &key, OutputType)
Explicitly make the wallet learn the related scripts for outputs to the given key.
void LoadHDChain(const CHDChain &chain)
Load a HD chain model (used by LoadWallet)
bool HaveKey(const CKeyID &address) const override
void LoadKeyMetadata(const CKeyID &keyID, const CKeyMetadata &metadata)
Load metadata (used by LoadWallet)
int32_t m_max_cached_index
std::unique_ptr< CKeyMetadata > GetMetadata(const CTxDestination &dest) const override
std::map< CKeyID, CKey > KeyMap
LegacySigningProvider(const LegacyScriptPubKeyMan &spk_man)
unsigned int GetKeyPoolSize() const override
std::set< CKeyID > GetKeys() const override
void RewriteDB() override
The action to do when the DB needs rewrite.
bool GetWatchPubKey(const CKeyID &address, CPubKey &pubkey_out) const
Fetches a pubkey from mapWatchKeys if it exists there.
bool HaveWatchOnly() const
Returns whether there are any watch-only things in the wallet.
void LearnAllRelatedScripts(const CPubKey &key)
Same as LearnRelatedScripts, but when the OutputType is not known (and could be anything).
bool GetCScript(const CScriptID &scriptid, CScript &script) const override
virtual uint256 GetID() const
bool GetNewDestination(const OutputType type, CTxDestination &dest, bilingual_str &error) override
CPubKey GenerateNewKey(WalletBatch &batch, CHDChain &hd_chain, bool internal=false) EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore)
Generate a new key.
boost::signals2::signal< void(bool fHaveWatchOnly)> NotifyWatchonlyChanged
Watch-only address added.
size_t KeypoolCountExternalKeys() const
@ SIGHASH_DEFAULT
Taproot only; implied when sighash byte is missing, and equivalent to SIGHASH_ALL.