mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 14:38:29 +01:00
Merge #19046: Replace CWallet::Set* functions that use memonly with Add/Load variants
3a9aba21a4Split SetWalletFlags into Add/LoadWalletFlags (Andrew Chow)d9cd095b59Split SetActiveScriptPubKeyMan into Add/LoadActiveScriptPubKeyMan (Andrew Chow)0122fbab4cSplit SetHDChain into AddHDChain and LoadHDChain (Andrew Chow) Pull request description: `SetHDChaiin`, `SetActiveScriptPubKeyMan`, and `SetWalletFlags` have a `memonly` argument which is kind of confusing, as noted in https://github.com/bitcoin/bitcoin/pull/17681#discussion_r427633081. This PR replaces those functions with `Add*` and `Load*` variants so that they follow the pattern used elsewhere in the wallet. `AddHDChain`, `AddActiveScriptPubKeyMan`, and `AddWalletFlags` both set their respective variables in `CWallet` and writes them to disk. These functions are used by the actions which modify the wallet such as `sethdseed`, `importdescriptors`, and creating a new wallet. `LoadHDChain`, `LoadActiveScriptPubKeyMan`, and `LoadWalletFlags` just set the `CWallet` variables. These functions are used by `LoadWallet` when loading the wallet from disk. ACKs for top commit: jnewbery: Code review ACK3a9aba21a4ryanofsky: Code review ACK3a9aba21a4. Only changes since last review tweaks making m_wallet_flags updates more safe meshcollider: utACK3a9aba21a4Tree-SHA512: 365aeaafc5ba42879c0eb797ec3beb29ab70e27f917dc880763f743420b3be6ddf797240996beed8a9ad70fb212c2590253c6b44c9dc244529c3939d9538983f
This commit is contained in:
@@ -905,20 +905,22 @@ bool LegacyScriptPubKeyMan::AddWatchOnly(const CScript& dest, int64_t nCreateTim
|
||||
return AddWatchOnly(dest);
|
||||
}
|
||||
|
||||
void LegacyScriptPubKeyMan::SetHDChain(const CHDChain& chain, bool memonly)
|
||||
void LegacyScriptPubKeyMan::LoadHDChain(const CHDChain& chain)
|
||||
{
|
||||
LOCK(cs_KeyStore);
|
||||
// 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::AddHDChain(const CHDChain& chain)
|
||||
{
|
||||
LOCK(cs_KeyStore);
|
||||
// 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;
|
||||
@@ -1172,7 +1174,7 @@ void LegacyScriptPubKeyMan::SetHDSeed(const CPubKey& seed)
|
||||
CHDChain newHdChain;
|
||||
newHdChain.nVersion = m_storage.CanSupportFeature(FEATURE_HD_SPLIT) ? CHDChain::VERSION_HD_CHAIN_SPLIT : CHDChain::VERSION_HD_BASE;
|
||||
newHdChain.seed_id = seed.GetID();
|
||||
SetHDChain(newHdChain, false);
|
||||
AddHDChain(newHdChain);
|
||||
NotifyCanGetAddressesChanged();
|
||||
WalletBatch batch(m_storage.GetDatabase());
|
||||
m_storage.UnsetBlankWalletFlag(batch);
|
||||
|
||||
Reference in New Issue
Block a user