Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/scriptpubkeyman.h
Show All 12 Lines | |||||
#include <util/message.h> | #include <util/message.h> | ||||
#include <wallet/crypter.h> | #include <wallet/crypter.h> | ||||
#include <wallet/ismine.h> | #include <wallet/ismine.h> | ||||
#include <wallet/walletdb.h> | #include <wallet/walletdb.h> | ||||
#include <wallet/walletutil.h> | #include <wallet/walletutil.h> | ||||
#include <boost/signals2/signal.hpp> | #include <boost/signals2/signal.hpp> | ||||
#include <unordered_map> | |||||
enum class OutputType; | enum class OutputType; | ||||
class CChainParams; | class CChainParams; | ||||
struct bilingual_str; | struct bilingual_str; | ||||
// Wallet storage things that ScriptPubKeyMans need in order to be able to store | // Wallet storage things that ScriptPubKeyMans need in order to be able to store | ||||
// things to the wallet database. It provides access to things that are part of | // things to the wallet database. It provides access to things that are part of | ||||
// the entire wallet and not specific to a ScriptPubKeyMan such as wallet flags, | // the entire wallet and not specific to a ScriptPubKeyMan such as wallet flags, | ||||
// wallet version, encryption keys, encryption status, and the database itself. | // wallet version, encryption keys, encryption status, and the database itself. | ||||
▲ Show 20 Lines • Show All 122 Lines • ▼ Show 20 Lines | inline void SerializationOp(Stream &s, Operation ser_action) { | ||||
} | } | ||||
} else { | } else { | ||||
READWRITE(fInternal); | READWRITE(fInternal); | ||||
READWRITE(m_pre_split); | READWRITE(m_pre_split); | ||||
} | } | ||||
} | } | ||||
}; | }; | ||||
class KeyIDHasher { | |||||
public: | |||||
KeyIDHasher() {} | |||||
size_t operator()(const CKeyID &id) const { return id.GetUint64(0); } | |||||
}; | |||||
/** | /** | ||||
* A class implementing ScriptPubKeyMan manages some (or all) scriptPubKeys used | * A class implementing ScriptPubKeyMan manages some (or all) scriptPubKeys used | ||||
* in a wallet. It contains the scripts and keys related to the scriptPubKeys it | * in a wallet. It contains the scripts and keys related to the scriptPubKeys it | ||||
* manages. A ScriptPubKeyMan will be able to give out scriptPubKeys to be used, | * manages. A ScriptPubKeyMan will be able to give out scriptPubKeys to be used, | ||||
* as well as marking when a scriptPubKey has been used. It also handles when | * as well as marking when a scriptPubKey has been used. It also handles when | ||||
* and how to store a scriptPubKey and its related scripts and keys, including | * and how to store a scriptPubKey and its related scripts and keys, including | ||||
* encryption. | * encryption. | ||||
*/ | */ | ||||
▲ Show 20 Lines • Show All 197 Lines • ▼ Show 20 Lines | private: | ||||
//! Adds a script to the store and saves it to disk | //! Adds a script to the store and saves it to disk | ||||
bool AddCScriptWithDB(WalletBatch &batch, const CScript &script); | bool AddCScriptWithDB(WalletBatch &batch, const CScript &script); | ||||
/** Add a KeyOriginInfo to the wallet */ | /** Add a KeyOriginInfo to the wallet */ | ||||
bool AddKeyOriginWithDB(WalletBatch &batch, const CPubKey &pubkey, | bool AddKeyOriginWithDB(WalletBatch &batch, const CPubKey &pubkey, | ||||
const KeyOriginInfo &info); | const KeyOriginInfo &info); | ||||
/* the HD chain data model (external chain counters) */ | /* the HD chain data model (external chain counters) */ | ||||
CHDChain hdChain; | CHDChain m_hd_chain; | ||||
std::unordered_map<CKeyID, CHDChain, KeyIDHasher> m_inactive_hd_chains; | |||||
/* HD derive new child key (on internal or external chain) */ | /* HD derive new child key (on internal or external chain) */ | ||||
void DeriveNewChildKey(WalletBatch &batch, CKeyMetadata &metadata, | void DeriveNewChildKey(WalletBatch &batch, CKeyMetadata &metadata, | ||||
CKey &secret, bool internal = false) | CKey &secret, CHDChain &hd_chain, | ||||
bool internal = false) | |||||
EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore); | EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore); | ||||
std::set<int64_t> setInternalKeyPool GUARDED_BY(cs_KeyStore); | std::set<int64_t> setInternalKeyPool GUARDED_BY(cs_KeyStore); | ||||
std::set<int64_t> setExternalKeyPool GUARDED_BY(cs_KeyStore); | std::set<int64_t> setExternalKeyPool GUARDED_BY(cs_KeyStore); | ||||
std::set<int64_t> set_pre_split_keypool GUARDED_BY(cs_KeyStore); | std::set<int64_t> set_pre_split_keypool GUARDED_BY(cs_KeyStore); | ||||
int64_t m_max_keypool_index GUARDED_BY(cs_KeyStore) = 0; | int64_t m_max_keypool_index GUARDED_BY(cs_KeyStore) = 0; | ||||
std::map<CKeyID, int64_t> m_pool_key_to_index; | std::map<CKeyID, int64_t> m_pool_key_to_index; | ||||
// Tracks keypool indexes to CKeyIDs of keys that have been taken out of the | // Tracks keypool indexes to CKeyIDs of keys that have been taken out of the | ||||
Show All 16 Lines | private: | ||||
* @return true if succeeded, false if failed due to empty keypool | * @return true if succeeded, false if failed due to empty keypool | ||||
* @throws std::runtime_error if keypool read failed, key was invalid, | * @throws std::runtime_error if keypool read failed, key was invalid, | ||||
* was not found in the wallet, or was misclassified in the internal | * was not found in the wallet, or was misclassified in the internal | ||||
* or external keypool | * or external keypool | ||||
*/ | */ | ||||
bool ReserveKeyFromKeyPool(int64_t &nIndex, CKeyPool &keypool, | bool ReserveKeyFromKeyPool(int64_t &nIndex, CKeyPool &keypool, | ||||
bool fRequestedInternal); | bool fRequestedInternal); | ||||
/** | |||||
* Like TopUp() but adds keys for inactive HD chains. | |||||
* Ensures that there are at least -keypool number of keys derived after the | |||||
* given index. | |||||
* | |||||
* @param seed_id the CKeyID for the HD seed. | |||||
* @param index the index to start generating keys from | |||||
* @param internal whether the internal chain should be used. true for | |||||
* internal chain, false for external chain. | |||||
* | |||||
* @return true if seed was found and keys were derived. false if unable to | |||||
* derive seeds | |||||
*/ | |||||
bool TopUpInactiveHDChain(const CKeyID seed_id, int64_t index, | |||||
bool internal); | |||||
public: | public: | ||||
using ScriptPubKeyMan::ScriptPubKeyMan; | using ScriptPubKeyMan::ScriptPubKeyMan; | ||||
bool GetNewDestination(const OutputType type, CTxDestination &dest, | bool GetNewDestination(const OutputType type, CTxDestination &dest, | ||||
std::string &error) override; | std::string &error) override; | ||||
isminetype IsMine(const CScript &script) const override; | isminetype IsMine(const CScript &script) const override; | ||||
bool CheckDecryptionKey(const CKeyingMaterial &master_key, | bool CheckDecryptionKey(const CKeyingMaterial &master_key, | ||||
▲ Show 20 Lines • Show All 79 Lines • ▼ Show 20 Lines | void UpdateTimeFirstKey(int64_t nCreateTime) | ||||
EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore); | EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore); | ||||
//! Adds a CScript to the store | //! Adds a CScript to the store | ||||
bool LoadCScript(const CScript &redeemScript); | bool LoadCScript(const CScript &redeemScript); | ||||
//! Load metadata (used by LoadWallet) | //! Load metadata (used by LoadWallet) | ||||
void LoadKeyMetadata(const CKeyID &keyID, const CKeyMetadata &metadata); | void LoadKeyMetadata(const CKeyID &keyID, const CKeyMetadata &metadata); | ||||
void LoadScriptMetadata(const CScriptID &script_id, | void LoadScriptMetadata(const CScriptID &script_id, | ||||
const CKeyMetadata &metadata); | const CKeyMetadata &metadata); | ||||
//! Generate a new key | //! Generate a new key | ||||
CPubKey GenerateNewKey(WalletBatch &batch, bool internal = false) | CPubKey GenerateNewKey(WalletBatch &batch, CHDChain &hd_chain, | ||||
bool internal = false) | |||||
EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore); | EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore); | ||||
/* Set the HD chain model (chain child index counters) */ | /* Set the HD chain model (chain child index counters) */ | ||||
void SetHDChain(const CHDChain &chain, bool memonly); | void SetHDChain(const CHDChain &chain, bool memonly); | ||||
const CHDChain &GetHDChain() const { return hdChain; } | const CHDChain &GetHDChain() const { return m_hd_chain; } | ||||
void AddInactiveHDChain(const CHDChain &chain); | |||||
//! Adds a watch-only address to the store, without saving it to disk (used | //! Adds a watch-only address to the store, without saving it to disk (used | ||||
//! by LoadWallet) | //! by LoadWallet) | ||||
bool LoadWatchOnly(const CScript &dest); | bool LoadWatchOnly(const CScript &dest); | ||||
//! Returns whether the watch-only script is in the wallet | //! Returns whether the watch-only script is in the wallet | ||||
bool HaveWatchOnly(const CScript &dest) const; | bool HaveWatchOnly(const CScript &dest) const; | ||||
//! Returns whether there are any watch-only things in the wallet | //! Returns whether there are any watch-only things in the wallet | ||||
bool HaveWatchOnly() const; | bool HaveWatchOnly() const; | ||||
▲ Show 20 Lines • Show All 243 Lines • Show Last 20 Lines |