diff options
author | Andrew Chow <achow101-github@achow101.com> | 2020-05-21 23:15:41 -0400 |
---|---|---|
committer | Andrew Chow <achow101-github@achow101.com> | 2020-06-22 14:59:09 -0400 |
commit | 3a9aba21a49a6d80bd187940d5e26893937b6832 (patch) | |
tree | 7e1609717e04984f8b639a841f6def38a3380320 /src | |
parent | d9cd095b5965fc20c09f401370e7ba99446663e3 (diff) | |
download | bitcoin-3a9aba21a49a6d80bd187940d5e26893937b6832.tar.xz |
Split SetWalletFlags into Add/LoadWalletFlags
Remove memonly bool and follow typical Add and Load pattern used
everywhere else.
Diffstat (limited to 'src')
-rw-r--r-- | src/wallet/wallet.cpp | 21 | ||||
-rw-r--r-- | src/wallet/wallet.h | 4 | ||||
-rw-r--r-- | src/wallet/walletdb.cpp | 2 |
3 files changed, 19 insertions, 8 deletions
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 6ee3149620..ab3b6d9d63 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1385,19 +1385,28 @@ bool CWallet::IsWalletFlagSet(uint64_t flag) const return (m_wallet_flags & flag); } -bool CWallet::SetWalletFlags(uint64_t overwriteFlags, bool memonly) +bool CWallet::LoadWalletFlags(uint64_t flags) { LOCK(cs_wallet); - m_wallet_flags = overwriteFlags; - if (((overwriteFlags & KNOWN_WALLET_FLAGS) >> 32) ^ (overwriteFlags >> 32)) { + if (((flags & KNOWN_WALLET_FLAGS) >> 32) ^ (flags >> 32)) { // contains unknown non-tolerable wallet flags return false; } - if (!memonly && !WalletBatch(*database).WriteWalletFlags(m_wallet_flags)) { + m_wallet_flags = flags; + + return true; +} + +bool CWallet::AddWalletFlags(uint64_t flags) +{ + LOCK(cs_wallet); + // We should never be writing unknown onon-tolerable wallet flags + assert(!(((flags & KNOWN_WALLET_FLAGS) >> 32) ^ (flags >> 32))); + if (!WalletBatch(*database).WriteWalletFlags(flags)) { throw std::runtime_error(std::string(__func__) + ": writing wallet flags failed"); } - return true; + return LoadWalletFlags(flags); } int64_t CWalletTx::GetTxTime() const @@ -3759,7 +3768,7 @@ std::shared_ptr<CWallet> CWallet::CreateWalletFromFile(interfaces::Chain& chain, // ensure this wallet.dat can only be opened by clients supporting HD with chain split and expects no default key walletInstance->SetMinVersion(FEATURE_LATEST); - walletInstance->SetWalletFlags(wallet_creation_flags, false); + walletInstance->AddWalletFlags(wallet_creation_flags); // Only create LegacyScriptPubKeyMan when not descriptor wallet if (!walletInstance->IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS)) { diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index e55257bd5d..046b79c307 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -1174,7 +1174,9 @@ public: /** overwrite all flags by the given uint64_t returns false if unknown, non-tolerable flags are present */ - bool SetWalletFlags(uint64_t overwriteFlags, bool memOnly); + bool AddWalletFlags(uint64_t flags); + /** Loads the flags into the wallet. (used by LoadWallet) */ + bool LoadWalletFlags(uint64_t flags); /** Determine if we are a legacy wallet */ bool IsLegacy() const; diff --git a/src/wallet/walletdb.cpp b/src/wallet/walletdb.cpp index 7e64ec16e1..8b103ba543 100644 --- a/src/wallet/walletdb.cpp +++ b/src/wallet/walletdb.cpp @@ -544,7 +544,7 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue, } else if (strType == DBKeys::FLAGS) { uint64_t flags; ssValue >> flags; - if (!pwallet->SetWalletFlags(flags, true)) { + if (!pwallet->LoadWalletFlags(flags)) { strErr = "Error reading wallet database: Unknown non-tolerable wallet flags found"; return false; } |