mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 15:09:59 +01:00
Determine inactive HD seeds from key metadata and track them in LegacyScriptPubKeyMan
This commit is contained in:
@@ -839,12 +839,29 @@ bool LegacyScriptPubKeyMan::AddWatchOnly(const CScript& dest, int64_t nCreateTim
|
||||
void LegacyScriptPubKeyMan::SetHDChain(const CHDChain& chain, bool memonly)
|
||||
{
|
||||
LOCK(cs_KeyStore);
|
||||
if (!memonly && !WalletBatch(m_storage.GetDatabase()).WriteHDChain(chain))
|
||||
throw std::runtime_error(std::string(__func__) + ": writing chain failed");
|
||||
// memonly == true means we are loading the wallet file
|
||||
// memonly == false means that the chain is actually being changed
|
||||
if (!memonly) {
|
||||
// Store the new chain
|
||||
if (!WalletBatch(m_storage.GetDatabase()).WriteHDChain(chain)) {
|
||||
throw std::runtime_error(std::string(__func__) + ": writing chain failed");
|
||||
}
|
||||
// When there's an old chain, add it as an inactive chain as we are now rotating hd chains
|
||||
if (!m_hd_chain.seed_id.IsNull()) {
|
||||
AddInactiveHDChain(m_hd_chain);
|
||||
}
|
||||
}
|
||||
|
||||
m_hd_chain = chain;
|
||||
}
|
||||
|
||||
void LegacyScriptPubKeyMan::AddInactiveHDChain(const CHDChain& chain)
|
||||
{
|
||||
LOCK(cs_KeyStore);
|
||||
assert(!chain.seed_id.IsNull());
|
||||
m_inactive_hd_chains[chain.seed_id] = chain;
|
||||
}
|
||||
|
||||
bool LegacyScriptPubKeyMan::HaveKey(const CKeyID &address) const
|
||||
{
|
||||
LOCK(cs_KeyStore);
|
||||
@@ -1011,8 +1028,8 @@ void LegacyScriptPubKeyMan::DeriveNewChildKey(WalletBatch &batch, CKeyMetadata&
|
||||
std::copy(master_id.begin(), master_id.begin() + 4, metadata.key_origin.fingerprint);
|
||||
metadata.has_key_origin = true;
|
||||
// update the chain model in the database
|
||||
if (!batch.WriteHDChain(hd_chain))
|
||||
throw std::runtime_error(std::string(__func__) + ": Writing HD chain model failed");
|
||||
if (hd_chain.seed_id == m_hd_chain.seed_id && !batch.WriteHDChain(hd_chain))
|
||||
throw std::runtime_error(std::string(__func__) + ": writing HD chain model failed");
|
||||
}
|
||||
|
||||
void LegacyScriptPubKeyMan::LoadKeyPool(int64_t nIndex, const CKeyPool &keypool)
|
||||
|
||||
Reference in New Issue
Block a user