aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Chow <[email protected]>2020-05-21 22:43:58 -0400
committerAndrew Chow <[email protected]>2020-05-21 22:43:58 -0400
commit0122fbab4c340b23ae56173de6c5ab866ba25ab8 (patch)
tree8fbde6abd2086591ecebf24ad6918dd2bedb4f32 /src
parentMerge #18787: wallet: descriptor wallet release notes and cleanups (diff)
downloaddiscoin-0122fbab4c340b23ae56173de6c5ab866ba25ab8.tar.xz
discoin-0122fbab4c340b23ae56173de6c5ab866ba25ab8.zip
Split SetHDChain into AddHDChain and LoadHDChain
Remove the memonly bool and follow our typical Add and Load pattern.
Diffstat (limited to 'src')
-rw-r--r--src/wallet/scriptpubkeyman.cpp28
-rw-r--r--src/wallet/scriptpubkeyman.h6
-rw-r--r--src/wallet/walletdb.cpp2
3 files changed, 20 insertions, 16 deletions
diff --git a/src/wallet/scriptpubkeyman.cpp b/src/wallet/scriptpubkeyman.cpp
index 8a2a79864..9199a843f 100644
--- a/src/wallet/scriptpubkeyman.cpp
+++ b/src/wallet/scriptpubkeyman.cpp
@@ -900,20 +900,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;
@@ -1167,7 +1169,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);
diff --git a/src/wallet/scriptpubkeyman.h b/src/wallet/scriptpubkeyman.h
index 2f6245bbe..5b0ccc0ac 100644
--- a/src/wallet/scriptpubkeyman.h
+++ b/src/wallet/scriptpubkeyman.h
@@ -421,8 +421,10 @@ public:
//! Generate a new key
CPubKey GenerateNewKey(WalletBatch& batch, CHDChain& hd_chain, bool internal = false) EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore);
- /* Set the HD chain model (chain child index counters) */
- void SetHDChain(const CHDChain& chain, bool memonly);
+ /* Set the HD chain model (chain child index counters) and writes it to the database */
+ 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; }
void AddInactiveHDChain(const CHDChain& chain);
diff --git a/src/wallet/walletdb.cpp b/src/wallet/walletdb.cpp
index 331408ef4..7690019b6 100644
--- a/src/wallet/walletdb.cpp
+++ b/src/wallet/walletdb.cpp
@@ -540,7 +540,7 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue,
} else if (strType == DBKeys::HDCHAIN) {
CHDChain chain;
ssValue >> chain;
- pwallet->GetOrCreateLegacyScriptPubKeyMan()->SetHDChain(chain, true);
+ pwallet->GetOrCreateLegacyScriptPubKeyMan()->LoadHDChain(chain);
} else if (strType == DBKeys::FLAGS) {
uint64_t flags;
ssValue >> flags;