0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-10 10:52:31 -05:00

Split SetHDChain into AddHDChain and LoadHDChain

Remove the memonly bool and follow our typical Add and Load pattern.
This commit is contained in:
Andrew Chow 2020-05-21 22:43:58 -04:00
parent df303ceb65
commit 0122fbab4c
3 changed files with 20 additions and 16 deletions

View file

@ -900,20 +900,22 @@ bool LegacyScriptPubKeyMan::AddWatchOnly(const CScript& dest, int64_t nCreateTim
return AddWatchOnly(dest); return AddWatchOnly(dest);
} }
void LegacyScriptPubKeyMan::SetHDChain(const CHDChain& chain, bool memonly) void LegacyScriptPubKeyMan::LoadHDChain(const CHDChain& chain)
{ {
LOCK(cs_KeyStore); LOCK(cs_KeyStore);
// memonly == true means we are loading the wallet file m_hd_chain = chain;
// memonly == false means that the chain is actually being changed }
if (!memonly) {
// Store the new chain void LegacyScriptPubKeyMan::AddHDChain(const CHDChain& chain)
if (!WalletBatch(m_storage.GetDatabase()).WriteHDChain(chain)) { {
throw std::runtime_error(std::string(__func__) + ": writing chain failed"); LOCK(cs_KeyStore);
} // Store the new chain
// When there's an old chain, add it as an inactive chain as we are now rotating hd chains if (!WalletBatch(m_storage.GetDatabase()).WriteHDChain(chain)) {
if (!m_hd_chain.seed_id.IsNull()) { throw std::runtime_error(std::string(__func__) + ": writing chain failed");
AddInactiveHDChain(m_hd_chain); }
} // 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; m_hd_chain = chain;
@ -1167,7 +1169,7 @@ void LegacyScriptPubKeyMan::SetHDSeed(const CPubKey& seed)
CHDChain newHdChain; CHDChain newHdChain;
newHdChain.nVersion = m_storage.CanSupportFeature(FEATURE_HD_SPLIT) ? CHDChain::VERSION_HD_CHAIN_SPLIT : CHDChain::VERSION_HD_BASE; newHdChain.nVersion = m_storage.CanSupportFeature(FEATURE_HD_SPLIT) ? CHDChain::VERSION_HD_CHAIN_SPLIT : CHDChain::VERSION_HD_BASE;
newHdChain.seed_id = seed.GetID(); newHdChain.seed_id = seed.GetID();
SetHDChain(newHdChain, false); AddHDChain(newHdChain);
NotifyCanGetAddressesChanged(); NotifyCanGetAddressesChanged();
WalletBatch batch(m_storage.GetDatabase()); WalletBatch batch(m_storage.GetDatabase());
m_storage.UnsetBlankWalletFlag(batch); m_storage.UnsetBlankWalletFlag(batch);

View file

@ -421,8 +421,10 @@ public:
//! Generate a new key //! Generate a new key
CPubKey GenerateNewKey(WalletBatch& batch, CHDChain& hd_chain, bool internal = false) EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore); CPubKey GenerateNewKey(WalletBatch& batch, CHDChain& hd_chain, bool internal = false) EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore);
/* Set the HD chain model (chain child index counters) */ /* Set the HD chain model (chain child index counters) and writes it to the database */
void SetHDChain(const CHDChain& chain, bool memonly); void AddHDChain(const CHDChain& chain);
//! Load a HD chain model (used by LoadWallet)
void LoadHDChain(const CHDChain& chain);
const CHDChain& GetHDChain() const { return m_hd_chain; } const CHDChain& GetHDChain() const { return m_hd_chain; }
void AddInactiveHDChain(const CHDChain& chain); void AddInactiveHDChain(const CHDChain& chain);

View file

@ -540,7 +540,7 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue,
} else if (strType == DBKeys::HDCHAIN) { } else if (strType == DBKeys::HDCHAIN) {
CHDChain chain; CHDChain chain;
ssValue >> chain; ssValue >> chain;
pwallet->GetOrCreateLegacyScriptPubKeyMan()->SetHDChain(chain, true); pwallet->GetOrCreateLegacyScriptPubKeyMan()->LoadHDChain(chain);
} else if (strType == DBKeys::FLAGS) { } else if (strType == DBKeys::FLAGS) {
uint64_t flags; uint64_t flags;
ssValue >> flags; ssValue >> flags;