Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/scriptpubkeyman.cpp
Show First 20 Lines • Show All 304 Lines • ▼ Show 20 Lines | bool LegacyScriptPubKeyMan::SetupGeneration(bool force) { | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
bool LegacyScriptPubKeyMan::IsHDEnabled() const { | bool LegacyScriptPubKeyMan::IsHDEnabled() const { | ||||
return !hdChain.seed_id.IsNull(); | return !hdChain.seed_id.IsNull(); | ||||
} | } | ||||
bool LegacyScriptPubKeyMan::CanGetAddresses(bool internal) { | bool LegacyScriptPubKeyMan::CanGetAddresses(bool internal) const { | ||||
LOCK(cs_KeyStore); | LOCK(cs_KeyStore); | ||||
// Check if the keypool has keys | // Check if the keypool has keys | ||||
bool keypool_has_keys; | bool keypool_has_keys; | ||||
if (internal && m_storage.CanSupportFeature(FEATURE_HD_SPLIT)) { | if (internal && m_storage.CanSupportFeature(FEATURE_HD_SPLIT)) { | ||||
keypool_has_keys = setInternalKeyPool.size() > 0; | keypool_has_keys = setInternalKeyPool.size() > 0; | ||||
} else { | } else { | ||||
keypool_has_keys = KeypoolCountExternalKeys() > 0; | keypool_has_keys = KeypoolCountExternalKeys() > 0; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | if (!batch.ReadPool(nIndex, keypool)) { | ||||
throw std::runtime_error(std::string(__func__) + | throw std::runtime_error(std::string(__func__) + | ||||
": read oldest key in keypool failed"); | ": read oldest key in keypool failed"); | ||||
} | } | ||||
assert(keypool.vchPubKey.IsValid()); | assert(keypool.vchPubKey.IsValid()); | ||||
return keypool.nTime; | return keypool.nTime; | ||||
} | } | ||||
int64_t LegacyScriptPubKeyMan::GetOldestKeyPoolTime() { | int64_t LegacyScriptPubKeyMan::GetOldestKeyPoolTime() const { | ||||
LOCK(cs_KeyStore); | LOCK(cs_KeyStore); | ||||
WalletBatch batch(m_storage.GetDatabase()); | WalletBatch batch(m_storage.GetDatabase()); | ||||
// load oldest key from keypool, get time and return | // load oldest key from keypool, get time and return | ||||
int64_t oldestKey = GetOldestKeyTimeInPool(setExternalKeyPool, batch); | int64_t oldestKey = GetOldestKeyTimeInPool(setExternalKeyPool, batch); | ||||
if (IsHDEnabled() && m_storage.CanSupportFeature(FEATURE_HD_SPLIT)) { | if (IsHDEnabled() && m_storage.CanSupportFeature(FEATURE_HD_SPLIT)) { | ||||
oldestKey = std::max(GetOldestKeyTimeInPool(setInternalKeyPool, batch), | oldestKey = std::max(GetOldestKeyTimeInPool(setInternalKeyPool, batch), | ||||
oldestKey); | oldestKey); | ||||
if (!set_pre_split_keypool.empty()) { | if (!set_pre_split_keypool.empty()) { | ||||
oldestKey = | oldestKey = | ||||
std::max(GetOldestKeyTimeInPool(set_pre_split_keypool, batch), | std::max(GetOldestKeyTimeInPool(set_pre_split_keypool, batch), | ||||
oldestKey); | oldestKey); | ||||
} | } | ||||
} | } | ||||
return oldestKey; | return oldestKey; | ||||
} | } | ||||
size_t LegacyScriptPubKeyMan::KeypoolCountExternalKeys() { | size_t LegacyScriptPubKeyMan::KeypoolCountExternalKeys() const { | ||||
LOCK(cs_KeyStore); | LOCK(cs_KeyStore); | ||||
return setExternalKeyPool.size() + set_pre_split_keypool.size(); | return setExternalKeyPool.size() + set_pre_split_keypool.size(); | ||||
} | } | ||||
unsigned int LegacyScriptPubKeyMan::GetKeyPoolSize() const { | unsigned int LegacyScriptPubKeyMan::GetKeyPoolSize() const { | ||||
LOCK(cs_KeyStore); | LOCK(cs_KeyStore); | ||||
return setInternalKeyPool.size() + setExternalKeyPool.size() + | return setInternalKeyPool.size() + setExternalKeyPool.size() + | ||||
set_pre_split_keypool.size(); | set_pre_split_keypool.size(); | ||||
▲ Show 20 Lines • Show All 588 Lines • ▼ Show 20 Lines | void LegacyScriptPubKeyMan::LoadKeyPool(int64_t nIndex, | ||||
// creation time. Note that this may be overwritten by actually | // creation time. Note that this may be overwritten by actually | ||||
// stored metadata for that key later, which is fine. | // stored metadata for that key later, which is fine. | ||||
CKeyID keyid = keypool.vchPubKey.GetID(); | CKeyID keyid = keypool.vchPubKey.GetID(); | ||||
if (mapKeyMetadata.count(keyid) == 0) { | if (mapKeyMetadata.count(keyid) == 0) { | ||||
mapKeyMetadata[keyid] = CKeyMetadata(keypool.nTime); | mapKeyMetadata[keyid] = CKeyMetadata(keypool.nTime); | ||||
} | } | ||||
} | } | ||||
bool LegacyScriptPubKeyMan::CanGenerateKeys() { | bool LegacyScriptPubKeyMan::CanGenerateKeys() const { | ||||
// A wallet can generate keys if it has an HD seed (IsHDEnabled) or it is a | // A wallet can generate keys if it has an HD seed (IsHDEnabled) or it is a | ||||
// non-HD wallet (pre FEATURE_HD) | // non-HD wallet (pre FEATURE_HD) | ||||
LOCK(cs_KeyStore); | LOCK(cs_KeyStore); | ||||
return IsHDEnabled() || !m_storage.CanSupportFeature(FEATURE_HD); | return IsHDEnabled() || !m_storage.CanSupportFeature(FEATURE_HD); | ||||
} | } | ||||
CPubKey LegacyScriptPubKeyMan::GenerateNewSeed() { | CPubKey LegacyScriptPubKeyMan::GenerateNewSeed() { | ||||
assert(!m_storage.IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)); | assert(!m_storage.IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)); | ||||
▲ Show 20 Lines • Show All 489 Lines • Show Last 20 Lines |