Skip to content

Commit 0122fba

Browse files
committed
Split SetHDChain into AddHDChain and LoadHDChain
Remove the memonly bool and follow our typical Add and Load pattern.
1 parent df303ce commit 0122fba

File tree

3 files changed

+20
-16
lines changed

3 files changed

+20
-16
lines changed

src/wallet/scriptpubkeyman.cpp

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -900,20 +900,22 @@ bool LegacyScriptPubKeyMan::AddWatchOnly(const CScript& dest, int64_t nCreateTim
900900
return AddWatchOnly(dest);
901901
}
902902

903-
void LegacyScriptPubKeyMan::SetHDChain(const CHDChain& chain, bool memonly)
903+
void LegacyScriptPubKeyMan::LoadHDChain(const CHDChain& chain)
904904
{
905905
LOCK(cs_KeyStore);
906-
// memonly == true means we are loading the wallet file
907-
// memonly == false means that the chain is actually being changed
908-
if (!memonly) {
909-
// Store the new chain
910-
if (!WalletBatch(m_storage.GetDatabase()).WriteHDChain(chain)) {
911-
throw std::runtime_error(std::string(__func__) + ": writing chain failed");
912-
}
913-
// When there's an old chain, add it as an inactive chain as we are now rotating hd chains
914-
if (!m_hd_chain.seed_id.IsNull()) {
915-
AddInactiveHDChain(m_hd_chain);
916-
}
906+
m_hd_chain = chain;
907+
}
908+
909+
void LegacyScriptPubKeyMan::AddHDChain(const CHDChain& chain)
910+
{
911+
LOCK(cs_KeyStore);
912+
// Store the new chain
913+
if (!WalletBatch(m_storage.GetDatabase()).WriteHDChain(chain)) {
914+
throw std::runtime_error(std::string(__func__) + ": writing chain failed");
915+
}
916+
// When there's an old chain, add it as an inactive chain as we are now rotating hd chains
917+
if (!m_hd_chain.seed_id.IsNull()) {
918+
AddInactiveHDChain(m_hd_chain);
917919
}
918920

919921
m_hd_chain = chain;
@@ -1167,7 +1169,7 @@ void LegacyScriptPubKeyMan::SetHDSeed(const CPubKey& seed)
11671169
CHDChain newHdChain;
11681170
newHdChain.nVersion = m_storage.CanSupportFeature(FEATURE_HD_SPLIT) ? CHDChain::VERSION_HD_CHAIN_SPLIT : CHDChain::VERSION_HD_BASE;
11691171
newHdChain.seed_id = seed.GetID();
1170-
SetHDChain(newHdChain, false);
1172+
AddHDChain(newHdChain);
11711173
NotifyCanGetAddressesChanged();
11721174
WalletBatch batch(m_storage.GetDatabase());
11731175
m_storage.UnsetBlankWalletFlag(batch);

src/wallet/scriptpubkeyman.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,8 +421,10 @@ class LegacyScriptPubKeyMan : public ScriptPubKeyMan, public FillableSigningProv
421421
//! Generate a new key
422422
CPubKey GenerateNewKey(WalletBatch& batch, CHDChain& hd_chain, bool internal = false) EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore);
423423

424-
/* Set the HD chain model (chain child index counters) */
425-
void SetHDChain(const CHDChain& chain, bool memonly);
424+
/* Set the HD chain model (chain child index counters) and writes it to the database */
425+
void AddHDChain(const CHDChain& chain);
426+
//! Load a HD chain model (used by LoadWallet)
427+
void LoadHDChain(const CHDChain& chain);
426428
const CHDChain& GetHDChain() const { return m_hd_chain; }
427429
void AddInactiveHDChain(const CHDChain& chain);
428430

src/wallet/walletdb.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue,
540540
} else if (strType == DBKeys::HDCHAIN) {
541541
CHDChain chain;
542542
ssValue >> chain;
543-
pwallet->GetOrCreateLegacyScriptPubKeyMan()->SetHDChain(chain, true);
543+
pwallet->GetOrCreateLegacyScriptPubKeyMan()->LoadHDChain(chain);
544544
} else if (strType == DBKeys::FLAGS) {
545545
uint64_t flags;
546546
ssValue >> flags;

0 commit comments

Comments
 (0)