Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/scriptpubkeyman.cpp
Show All 10 Lines | |||||
#include <util/translation.h> | #include <util/translation.h> | ||||
#include <wallet/scriptpubkeyman.h> | #include <wallet/scriptpubkeyman.h> | ||||
#include <wallet/wallet.h> | #include <wallet/wallet.h> | ||||
bool LegacyScriptPubKeyMan::GetNewDestination(const OutputType type, | bool LegacyScriptPubKeyMan::GetNewDestination(const OutputType type, | ||||
CTxDestination &dest, | CTxDestination &dest, | ||||
std::string &error) { | std::string &error) { | ||||
error.clear(); | error.clear(); | ||||
TopUpKeyPool(); | TopUp(); | ||||
// Generate a new key that is added to wallet | // Generate a new key that is added to wallet | ||||
CPubKey new_key; | CPubKey new_key; | ||||
if (!GetKeyFromPool(new_key)) { | if (!GetKeyFromPool(new_key)) { | ||||
error = "Error: Keypool ran out, please call keypoolrefill first"; | error = "Error: Keypool ran out, please call keypoolrefill first"; | ||||
return false; | return false; | ||||
} | } | ||||
LearnRelatedScripts(new_key, type); | LearnRelatedScripts(new_key, type); | ||||
▲ Show 20 Lines • Show All 201 Lines • ▼ Show 20 Lines | void LegacyScriptPubKeyMan::KeepDestination(int64_t index) { | ||||
KeepKey(index); | KeepKey(index); | ||||
} | } | ||||
void LegacyScriptPubKeyMan::ReturnDestination(int64_t index, bool internal, | void LegacyScriptPubKeyMan::ReturnDestination(int64_t index, bool internal, | ||||
const CPubKey &pubkey) { | const CPubKey &pubkey) { | ||||
ReturnKey(index, internal, pubkey); | ReturnKey(index, internal, pubkey); | ||||
} | } | ||||
bool LegacyScriptPubKeyMan::TopUp(unsigned int size) { | |||||
return TopUpKeyPool(size); | |||||
} | |||||
void LegacyScriptPubKeyMan::MarkUnusedAddresses(const CScript &script) { | void LegacyScriptPubKeyMan::MarkUnusedAddresses(const CScript &script) { | ||||
AssertLockHeld(cs_wallet); | AssertLockHeld(cs_wallet); | ||||
// extract addresses and check if they match with an unused keypool key | // extract addresses and check if they match with an unused keypool key | ||||
for (const auto &keyid : GetAffectedKeys(script, *this)) { | for (const auto &keyid : GetAffectedKeys(script, *this)) { | ||||
std::map<CKeyID, int64_t>::const_iterator mi = | std::map<CKeyID, int64_t>::const_iterator mi = | ||||
m_pool_key_to_index.find(keyid); | m_pool_key_to_index.find(keyid); | ||||
if (mi != m_pool_key_to_index.end()) { | if (mi != m_pool_key_to_index.end()) { | ||||
WalletLogPrintf("%s: Detected a used keypool key, mark all keypool " | WalletLogPrintf("%s: Detected a used keypool key, mark all keypool " | ||||
"key up to this key as used\n", | "key up to this key as used\n", | ||||
__func__); | __func__); | ||||
MarkReserveKeysAsUsed(mi->second); | MarkReserveKeysAsUsed(mi->second); | ||||
if (!TopUpKeyPool()) { | if (!TopUp()) { | ||||
WalletLogPrintf( | WalletLogPrintf( | ||||
"%s: Topping up keypool failed (locked wallet)\n", | "%s: Topping up keypool failed (locked wallet)\n", | ||||
__func__); | __func__); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 89 Lines • ▼ Show 20 Lines | if (m_storage.CanSupportFeature(FEATURE_HD_SPLIT)) { | ||||
split_upgrade = FEATURE_HD_SPLIT > prev_version; | split_upgrade = FEATURE_HD_SPLIT > prev_version; | ||||
} | } | ||||
// Mark all keys currently in the keypool as pre-split | // Mark all keys currently in the keypool as pre-split | ||||
if (split_upgrade) { | if (split_upgrade) { | ||||
MarkPreSplitKeys(); | MarkPreSplitKeys(); | ||||
} | } | ||||
// Regenerate the keypool if upgraded to HD | // Regenerate the keypool if upgraded to HD | ||||
if (hd_upgrade) { | if (hd_upgrade) { | ||||
if (!TopUpKeyPool()) { | if (!TopUp()) { | ||||
error = _("Unable to generate keys").translated; | error = _("Unable to generate keys").translated; | ||||
return false; | return false; | ||||
} | } | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
bool LegacyScriptPubKeyMan::HavePrivateKeys() const { | bool LegacyScriptPubKeyMan::HavePrivateKeys() const { | ||||
▲ Show 20 Lines • Show All 633 Lines • ▼ Show 20 Lines | bool LegacyScriptPubKeyMan::NewKeyPool() { | ||||
for (int64_t nIndex : set_pre_split_keypool) { | for (int64_t nIndex : set_pre_split_keypool) { | ||||
batch.ErasePool(nIndex); | batch.ErasePool(nIndex); | ||||
} | } | ||||
set_pre_split_keypool.clear(); | set_pre_split_keypool.clear(); | ||||
m_pool_key_to_index.clear(); | m_pool_key_to_index.clear(); | ||||
if (!TopUpKeyPool()) { | if (!TopUp()) { | ||||
return false; | return false; | ||||
} | } | ||||
WalletLogPrintf("LegacyScriptPubKeyMan::NewKeyPool rewrote keypool\n"); | WalletLogPrintf("LegacyScriptPubKeyMan::NewKeyPool rewrote keypool\n"); | ||||
return true; | return true; | ||||
} | } | ||||
bool LegacyScriptPubKeyMan::TopUpKeyPool(unsigned int kpSize) { | bool LegacyScriptPubKeyMan::TopUp(unsigned int kpSize) { | ||||
if (!CanGenerateKeys()) { | if (!CanGenerateKeys()) { | ||||
return false; | return false; | ||||
} | } | ||||
{ | { | ||||
LOCK(cs_wallet); | LOCK(cs_wallet); | ||||
if (m_storage.IsLocked()) { | if (m_storage.IsLocked()) { | ||||
return false; | return false; | ||||
▲ Show 20 Lines • Show All 115 Lines • ▼ Show 20 Lines | |||||
bool LegacyScriptPubKeyMan::ReserveKeyFromKeyPool(int64_t &nIndex, | bool LegacyScriptPubKeyMan::ReserveKeyFromKeyPool(int64_t &nIndex, | ||||
CKeyPool &keypool, | CKeyPool &keypool, | ||||
bool fRequestedInternal) { | bool fRequestedInternal) { | ||||
nIndex = -1; | nIndex = -1; | ||||
keypool.vchPubKey = CPubKey(); | keypool.vchPubKey = CPubKey(); | ||||
{ | { | ||||
LOCK(cs_wallet); | LOCK(cs_wallet); | ||||
TopUpKeyPool(); | TopUp(); | ||||
bool fReturningInternal = fRequestedInternal; | bool fReturningInternal = fRequestedInternal; | ||||
fReturningInternal &= | fReturningInternal &= | ||||
(IsHDEnabled() && m_storage.CanSupportFeature(FEATURE_HD_SPLIT)) || | (IsHDEnabled() && m_storage.CanSupportFeature(FEATURE_HD_SPLIT)) || | ||||
m_storage.IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS); | m_storage.IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS); | ||||
bool use_split_keypool = set_pre_split_keypool.empty(); | bool use_split_keypool = set_pre_split_keypool.empty(); | ||||
std::set<int64_t> &setKeyPool = | std::set<int64_t> &setKeyPool = | ||||
use_split_keypool | use_split_keypool | ||||
▲ Show 20 Lines • Show All 279 Lines • Show Last 20 Lines |