Skip to content

Commit c25d90f

Browse files
committed
[wallet] Add HasUnusedKeys() helper
1 parent f2123e3 commit c25d90f

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/wallet/wallet.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3611,6 +3611,11 @@ void CReserveKey::ReturnKey()
36113611
vchPubKey = CPubKey();
36123612
}
36133613

3614+
bool CWallet::HasUnusedKeys(int min_keys) const
3615+
{
3616+
return setExternalKeyPool.size() >= min_keys && (setInternalKeyPool.size() >= min_keys || !CanSupportFeature(FEATURE_HD_SPLIT));
3617+
}
3618+
36143619
void CWallet::GetScriptForMining(std::shared_ptr<CReserveScript> &script)
36153620
{
36163621
std::shared_ptr<CReserveKey> rKey = std::make_shared<CReserveKey>(this);

src/wallet/wallet.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,7 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
813813
const CWalletTx* GetWalletTx(const uint256& hash) const;
814814

815815
//! check whether we are allowed to upgrade (or already support) to the named feature
816-
bool CanSupportFeature(enum WalletFeature wf) { AssertLockHeld(cs_wallet); return nWalletMaxVersion >= wf; }
816+
bool CanSupportFeature(enum WalletFeature wf) const { AssertLockHeld(cs_wallet); return nWalletMaxVersion >= wf; }
817817

818818
/**
819819
* populate vCoins with vector of available COutputs.
@@ -978,6 +978,8 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
978978
bool GetKeyFromPool(CPubKey &key, bool internal = false);
979979
int64_t GetOldestKeyPoolTime();
980980
const std::map<CKeyID, int64_t>& GetAllReserveKeys() const { return m_pool_key_to_index; }
981+
/** Does the wallet have at least min_keys in the keypool? */
982+
bool HasUnusedKeys(int min_keys) const;
981983

982984
std::set< std::set<CTxDestination> > GetAddressGroupings();
983985
std::map<CTxDestination, CAmount> GetAddressBalances();

0 commit comments

Comments
 (0)