Skip to content

Commit

Permalink
[wallet] Add HasUnusedKeys() helper
Browse files Browse the repository at this point in the history
  • Loading branch information
jnewbery committed Aug 4, 2017
1 parent f2123e3 commit c25d90f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/wallet/wallet.cpp
Expand Up @@ -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<CReserveScript> &script)
{
std::shared_ptr<CReserveKey> rKey = std::make_shared<CReserveKey>(this);
Expand Down
4 changes: 3 additions & 1 deletion src/wallet/wallet.h
Expand Up @@ -813,7 +813,7 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
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.
Expand Down Expand Up @@ -978,6 +978,8 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
bool GetKeyFromPool(CPubKey &key, bool internal = false);
int64_t GetOldestKeyPoolTime();
const std::map<CKeyID, int64_t>& 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<CTxDestination> > GetAddressGroupings();
std::map<CTxDestination, CAmount> GetAddressBalances();
Expand Down

0 comments on commit c25d90f

Please sign in to comment.