From 386a994b853bc5b3a2ed0d812673465b8ffa4849 Mon Sep 17 00:00:00 2001 From: Andrew Chow Date: Mon, 7 Oct 2019 14:11:34 -0400 Subject: Key pool: Change ReturnDestination interface to take address instead of key In order for ScriptPubKeyMan to be generic and work with future ScriptPubKeyMans, ScriptPubKeyMan::ReturnDestination is changed to take a CTxDestination instead of a CPubKey. Since LegacyScriptPubKeyMan still deals with keys internally, a new map m_reserved_key_to_index is added in order to track the keypool indexes that have been reserved. The CPubKey argument of KeepDestination is also removed so that it is more generic. Instead of taking a CPubKey or a CTxDestination, we just use the nIndex given to find the pubkey. --- src/wallet/scriptpubkeyman.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/wallet/scriptpubkeyman.h') diff --git a/src/wallet/scriptpubkeyman.h b/src/wallet/scriptpubkeyman.h index bcc62ece1e..6ed9a4787a 100644 --- a/src/wallet/scriptpubkeyman.h +++ b/src/wallet/scriptpubkeyman.h @@ -151,8 +151,8 @@ public: virtual isminetype IsMine(const CScript& script) const { return ISMINE_NO; } virtual bool GetReservedDestination(const OutputType type, bool internal, CTxDestination& address, int64_t& index, CKeyPool& keypool) { return false; } - virtual void KeepDestination(int64_t index, const OutputType& type, const CPubKey& pubkey) {} - virtual void ReturnDestination(int64_t index, bool internal, const CPubKey& pubkey) {} + virtual void KeepDestination(int64_t index, const OutputType& type) {} + virtual void ReturnDestination(int64_t index, bool internal, const CTxDestination& addr) {} virtual bool TopUp(unsigned int size = 0) { return false; } @@ -246,6 +246,8 @@ private: std::set set_pre_split_keypool GUARDED_BY(cs_wallet); int64_t m_max_keypool_index GUARDED_BY(cs_wallet) = 0; std::map m_pool_key_to_index; + // Tracks keypool indexes to CKeyIDs of keys that have been taken out of the keypool but may be returned to it + std::map m_index_to_reserved_key; //! Fetches a key from the keypool bool GetKeyFromPool(CPubKey &key, const OutputType type, bool internal = false); @@ -274,8 +276,8 @@ public: bool EncryptKeys(CKeyingMaterial& vMasterKeyIn); bool GetReservedDestination(const OutputType type, bool internal, CTxDestination& address, int64_t& index, CKeyPool& keypool) override; - void KeepDestination(int64_t index, const OutputType& type, const CPubKey& pubkey) override; - void ReturnDestination(int64_t index, bool internal, const CPubKey& pubkey) override; + void KeepDestination(int64_t index, const OutputType& type) override; + void ReturnDestination(int64_t index, bool internal, const CTxDestination&) override; bool TopUp(unsigned int size = 0) override; -- cgit v1.2.3