mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-06-19 05:12:03 +02:00
Refactor: Move MarkUnusedAddresses code out of CWallet::AddToWalletIfInvolvingMe
This commit does not change behavior.
This commit is contained in:
parent
a18edd7b38
commit
46865ec958
@ -287,6 +287,23 @@ bool LegacyScriptPubKeyMan::TopUp(unsigned int size)
|
|||||||
return TopUpKeyPool(size);
|
return TopUpKeyPool(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LegacyScriptPubKeyMan::MarkUnusedAddresses(const CScript& script)
|
||||||
|
{
|
||||||
|
AssertLockHeld(cs_wallet);
|
||||||
|
// extract addresses and check if they match with an unused keypool key
|
||||||
|
for (const auto& keyid : GetAffectedKeys(script, *this)) {
|
||||||
|
std::map<CKeyID, int64_t>::const_iterator mi = m_pool_key_to_index.find(keyid);
|
||||||
|
if (mi != m_pool_key_to_index.end()) {
|
||||||
|
WalletLogPrintf("%s: Detected a used keypool key, mark all keypool key up to this key as used\n", __func__);
|
||||||
|
MarkReserveKeysAsUsed(mi->second);
|
||||||
|
|
||||||
|
if (!TopUpKeyPool()) {
|
||||||
|
WalletLogPrintf("%s: Topping up keypool failed (locked wallet)\n", __func__);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void LegacyScriptPubKeyMan::UpgradeKeyMetadata()
|
void LegacyScriptPubKeyMan::UpgradeKeyMetadata()
|
||||||
{
|
{
|
||||||
AssertLockHeld(cs_wallet);
|
AssertLockHeld(cs_wallet);
|
||||||
|
@ -37,6 +37,8 @@ public:
|
|||||||
//! Default for -keypool
|
//! Default for -keypool
|
||||||
static const unsigned int DEFAULT_KEYPOOL_SIZE = 1000;
|
static const unsigned int DEFAULT_KEYPOOL_SIZE = 1000;
|
||||||
|
|
||||||
|
std::vector<CKeyID> GetAffectedKeys(const CScript& spk, const SigningProvider& provider);
|
||||||
|
|
||||||
/** A key from a CWallet's keypool
|
/** A key from a CWallet's keypool
|
||||||
*
|
*
|
||||||
* The wallet holds one (for pre HD-split wallets) or several keypools. These
|
* The wallet holds one (for pre HD-split wallets) or several keypools. These
|
||||||
@ -154,6 +156,9 @@ public:
|
|||||||
|
|
||||||
virtual bool TopUp(unsigned int size = 0) { return false; }
|
virtual bool TopUp(unsigned int size = 0) { return false; }
|
||||||
|
|
||||||
|
//! Mark unused addresses as being used
|
||||||
|
virtual void MarkUnusedAddresses(const CScript& script) {}
|
||||||
|
|
||||||
/* Returns true if HD is enabled */
|
/* Returns true if HD is enabled */
|
||||||
virtual bool IsHDEnabled() const { return false; }
|
virtual bool IsHDEnabled() const { return false; }
|
||||||
|
|
||||||
@ -259,6 +264,8 @@ public:
|
|||||||
|
|
||||||
bool TopUp(unsigned int size = 0) override;
|
bool TopUp(unsigned int size = 0) override;
|
||||||
|
|
||||||
|
void MarkUnusedAddresses(const CScript& script) override;
|
||||||
|
|
||||||
//! Upgrade stored CKeyMetadata objects to store key origin info as KeyOriginInfo
|
//! Upgrade stored CKeyMetadata objects to store key origin info as KeyOriginInfo
|
||||||
void UpgradeKeyMetadata() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
|
void UpgradeKeyMetadata() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
|
||||||
|
|
||||||
|
@ -236,8 +236,6 @@ std::string COutput::ToString() const
|
|||||||
return strprintf("COutput(%s, %d, %d) [%s]", tx->GetHash().ToString(), i, nDepth, FormatMoney(tx->tx->vout[i].nValue));
|
return strprintf("COutput(%s, %d, %d) [%s]", tx->GetHash().ToString(), i, nDepth, FormatMoney(tx->tx->vout[i].nValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<CKeyID> GetAffectedKeys(const CScript& spk, const SigningProvider& provider);
|
|
||||||
|
|
||||||
const CWalletTx* CWallet::GetWalletTx(const uint256& hash) const
|
const CWalletTx* CWallet::GetWalletTx(const uint256& hash) const
|
||||||
{
|
{
|
||||||
LOCK(cs_wallet);
|
LOCK(cs_wallet);
|
||||||
@ -876,17 +874,8 @@ bool CWallet::AddToWalletIfInvolvingMe(const CTransactionRef& ptx, CWalletTx::St
|
|||||||
|
|
||||||
// loop though all outputs
|
// loop though all outputs
|
||||||
for (const CTxOut& txout: tx.vout) {
|
for (const CTxOut& txout: tx.vout) {
|
||||||
// extract addresses and check if they match with an unused keypool key
|
if (auto spk_man = m_spk_man.get()) {
|
||||||
for (const auto& keyid : GetAffectedKeys(txout.scriptPubKey, *m_spk_man)) {
|
spk_man->MarkUnusedAddresses(txout.scriptPubKey);
|
||||||
std::map<CKeyID, int64_t>::const_iterator mi = m_spk_man->m_pool_key_to_index.find(keyid);
|
|
||||||
if (mi != m_spk_man->m_pool_key_to_index.end()) {
|
|
||||||
WalletLogPrintf("%s: Detected a used keypool key, mark all keypool key up to this key as used\n", __func__);
|
|
||||||
MarkReserveKeysAsUsed(mi->second);
|
|
||||||
|
|
||||||
if (!m_spk_man->TopUp()) {
|
|
||||||
WalletLogPrintf("%s: Topping up keypool failed (locked wallet)\n", __func__);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1135,7 +1135,6 @@ public:
|
|||||||
std::set<int64_t>& setExternalKeyPool GUARDED_BY(cs_wallet) = m_spk_man->setExternalKeyPool;
|
std::set<int64_t>& setExternalKeyPool GUARDED_BY(cs_wallet) = m_spk_man->setExternalKeyPool;
|
||||||
int64_t& nTimeFirstKey GUARDED_BY(cs_wallet) = m_spk_man->nTimeFirstKey;
|
int64_t& nTimeFirstKey GUARDED_BY(cs_wallet) = m_spk_man->nTimeFirstKey;
|
||||||
void MarkPreSplitKeys() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet) { AssertLockHeld(m_spk_man->cs_wallet); m_spk_man->MarkPreSplitKeys(); }
|
void MarkPreSplitKeys() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet) { AssertLockHeld(m_spk_man->cs_wallet); m_spk_man->MarkPreSplitKeys(); }
|
||||||
void MarkReserveKeysAsUsed(int64_t keypool_id) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet) { AssertLockHeld(m_spk_man->cs_wallet); m_spk_man->MarkReserveKeysAsUsed(keypool_id); }
|
|
||||||
using CryptedKeyMap = LegacyScriptPubKeyMan::CryptedKeyMap;
|
using CryptedKeyMap = LegacyScriptPubKeyMan::CryptedKeyMap;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user