From c25d90f125d69e33688288eff439eb7be75012e9 Mon Sep 17 00:00:00 2001 From: John Newbery Date: Thu, 3 Aug 2017 11:03:40 -0400 Subject: [PATCH] [wallet] Add HasUnusedKeys() helper --- src/wallet/wallet.cpp | 5 +++++ src/wallet/wallet.h | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index afe911ae9a..ce345804e1 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -3611,6 +3611,11 @@ void CReserveKey::ReturnKey() vchPubKey = CPubKey(); } +bool CWallet::HasUnusedKeys(int min_keys) const +{ + return setExternalKeyPool.size() >= min_keys && (setInternalKeyPool.size() >= min_keys || !CanSupportFeature(FEATURE_HD_SPLIT)); +} + void CWallet::GetScriptForMining(std::shared_ptr &script) { std::shared_ptr rKey = std::make_shared(this); diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 0d2262cfe1..310300126d 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -813,7 +813,7 @@ public: const CWalletTx* GetWalletTx(const uint256& hash) const; //! check whether we are allowed to upgrade (or already support) to the named feature - bool CanSupportFeature(enum WalletFeature wf) { AssertLockHeld(cs_wallet); return nWalletMaxVersion >= wf; } + bool CanSupportFeature(enum WalletFeature wf) const { AssertLockHeld(cs_wallet); return nWalletMaxVersion >= wf; } /** * populate vCoins with vector of available COutputs. @@ -978,6 +978,8 @@ public: bool GetKeyFromPool(CPubKey &key, bool internal = false); int64_t GetOldestKeyPoolTime(); const std::map& GetAllReserveKeys() const { return m_pool_key_to_index; } + /** Does the wallet have at least min_keys in the keypool? */ + bool HasUnusedKeys(int min_keys) const; std::set< std::set > GetAddressGroupings(); std::map GetAddressBalances();